As the title says, I'm trying to use an STL vector with an internal SIMD data type. I know this is not a good practice due to the potential overhead of loading / storing, but I came across a rather strange error. Here is the code:
#include "immintrin.h" #include <vector> #include <stdio.h> #define VL 8 int main () { std::vector<__m256> vec_1(10); std::vector<__m256> vec_2(10); float * tmp_1 = new float[VL]; printf("vec_1[0]:\n"); _mm256_storeu_ps(tmp_1, vec_1[0]); // seems to go as expected for (int i = 0; i < VL; ++i) printf("%f ", tmp_1[i]); printf("\n"); delete tmp_1; float * tmp_2 = new float[VL]; printf("vec_2[0]:\n"); _mm256_storeu_ps(tmp_2, vec_2[0]); // segmentation fault for (int i = 0; i < VL; ++i) printf("%f ", tmp_2[i]); printf("\n"); delete tmp_2; return 0; }
I compiled it with g++ -O3 -g -std=c++11 -mavx2 test.cpp -o test . vec_1[0] prints as expected (all zeros), but a segmentation error occurs when it comes to vec_2[0] . I thought this was a alignment problem, but instead of _mm256_store_ps I used _mm256_storeu_ps , which does not require alignment.
This is Intel Haswell architecture with the AVX2 extension. The GCC version is 4.8.5.
Any possible hint is appreciated.
source share