简体   繁体   中英

How to deal with SIGSEGV, Segmentation fault. while using Avx2

How to deal with SIGSEGV, Segmentation fault. while using Avx2 (_mm256_load_pd)(_mm256_store_pd)

(solved)

_mm256_load_pd

I've received segmentation fault wile called

_mm256_load_pd

usage are as blew

double * Val = malloc(sizeof(double)*4);
__m256d vecv = _mm256_load_pd(&Val[0]);

gdb shows

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7fc5017 in _mm256_load_pd (__P=0x555555559370)
    at /usr/lib/gcc/x86_64-linux-gnu/9/include/avxintrin.h:862
862   return *(__m256d *)__P;
(gdb) frame 1
#1  gemv_d_lineProduct_4_avx2 (Val=0x555555559370, indx=0x5555555592f0, 
    Vector_X=0x5555555592c0, Vector_Y=0x555555559340)
    at someThing.c:114
114     __m256d vecv = _mm256_load_pd(&Val[0]);
(gdb) 

_mm256_store_pd

while I make Val bigger

double * Val = malloc(sizeof(double)*4);

I found _mm256_load_pd works rightly but result in

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7fc50e3 in _mm256_store_pd (__A=..., __P=0x555555559390)
    at /usr/lib/gcc/x86_64-linux-gnu/9/include/avxintrin.h:868
868   *(__m256d *)__P = __A;
(gdb) frame 1
#1  gemv_d_lineProduct_4_avx2 (Val=0x5555555593e0, indx=0x555555559310, 
    Vector_X=0x5555555592c0, Vector_Y=0x555555559390)
    at something.c:122
122     _mm256_store_pd(Vector_Y,vecY);

full project

https://github.com/DevilInChina/gemv

mkdir build;cd build
cmake ..
make
cd ../bin
./line
#then might get some seg fault

Method of solving

change memory allocate function to

void *aligned_alloc (size_t __alignment, size_t __size);

first parameter should be 1024 or something else.

Thanks to igor-r

According to the Intel reference , _mm256_load_pd() requires 32-byte aligned pointer.

Please, use aligned_alloc() to allocate a memory chunk having the proper alignment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM