简体   繁体   English

如何处理 SIGSEGV,Segmentation fault。 使用 Avx2 时

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

How to deal with SIGSEGV, Segmentation fault.如何处理 SIGSEGV,Segmentation fault。 while using Avx2 (_mm256_load_pd)(_mm256_store_pd)使用 Avx2 (_mm256_load_pd)(_mm256_store_pd)

(solved) (解决了)

_mm256_load_pd _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 gdb 显示

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 _mm256_store_pd

while I make Val bigger而我让 Val 更大

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

I found _mm256_load_pd works rightly but result in我发现_mm256_load_pd工作正常但导致

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 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将 memory 分配 function 更改为

void *aligned_alloc (size_t __alignment, size_t __size);

first parameter should be 1024 or something else.第一个参数应该是 1024 或其他。

Thanks to igor-r感谢igor-r

According to the Intel reference , _mm256_load_pd() requires 32-byte aligned pointer.根据Intel 参考资料_mm256_load_pd()需要 32 字节对齐的指针。

Please, use aligned_alloc() to allocate a memory chunk having the proper alignment.请使用aligned_alloc()分配具有正确alignment 的memory 块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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