giaf / blasfeo

Basic linear algebra subroutines for embedded optimization
Other
323 stars 88 forks source link

Segfault dpotrf_l for target HASWELL #57

Closed roversch closed 6 years ago

roversch commented 6 years ago

The following program segfaults for HASWELL (not for GENERIC). I'm trying to compute the cholesky decomposition of a submatrix and store it in a smaller matrix. For GENERIC, I get the correct result (checked in the last lines).

#include <stdlib.h>

#include "blasfeo_d_blas.h"
#include "blasfeo_d_aux.h"
#include "blasfeo_d_aux_ext_dep.h"

int main()
{

    double R[4] = {4, 2, 2, 2};
    double Q[4] = {1, 2, 2, 8};
    double S[4] = {-0.25, -0.5, -0.75, -1};

    struct blasfeo_dmat RSQ, L;

    int num_bytes = blasfeo_memsize_dmat(4, 4);
    void *raw_mem = malloc(num_bytes);
    blasfeo_create_dmat(4, 4, &RSQ, raw_mem);
    blasfeo_dgese(4, 4, 0.0, &RSQ, 0, 0);

    num_bytes = blasfeo_memsize_dmat(2, 2);
    raw_mem = malloc(num_bytes);
    blasfeo_create_dmat(2, 2, &L, raw_mem);
    blasfeo_dgese(2, 2, 0.0, &L, 0, 0);

    blasfeo_pack_dmat(2, 2, R, 2, &RSQ, 0, 0);
    blasfeo_pack_dmat(2, 2, Q, 2, &RSQ, 2, 2);
    blasfeo_pack_tran_dmat(2, 2, S, 2, &RSQ, 2, 0);

    /// Segfault occurs here
    blasfeo_dpotrf_l(2, &RSQ, 0, 0, &L, 0, 0);
    ///

    blasfeo_print_dmat(2, 2, &L, 0, 0);

    blasfeo_dgemm_nt(2, 2, 2, 1.0, &L, 0, 0, &L, 0, 0, 0.0, &L, 0, 0, &L, 0, 0);

    blasfeo_print_dmat(2, 2, &L, 0, 0);

}
giaf commented 6 years ago

When you use the HP version, the memory used to create matrices is assumed to be properly aligned, otherwise it may seg-fault depending on the architecture.

Instead of malloc, you should use the blasfeo routine v_zeros_align, or alternatively use blasfeo_allocate_dmat instead of blasfeo_create_dmat (as the former takes care of memory allocation itself).

roversch commented 6 years ago

solved, thanks !