I want to multiply two (float/double) vectors with AVX operators. In order to do that, I need aligned memory. My function for float values is:
#define SIZE 65536
float *g, *h, *j;
g = (float*)aligned_alloc(32, sizeof(float)*SIZE);
h = (float*)aligned_alloc(32, sizeof(float)*SIZE);
j = (float*)aligned_alloc(32, sizeof(float)*SIZE);
//Filling g and h with data
for(int i = 0; i < SIZE/8; i++)
{
__m256 a_a, b_a, c_a;
a_a = _mm256_load_ps(g+8*i);
b_a = _mm256_load_ps(h+8*i);
c_a = _mm256_mul_ps(a_a, b_a);
_mm256_store_ps (j+i*8, c_a);
}
free(g);
free(h);
free(j);
That works, but when I am trying to do that with double values, I get a memory access error (such as if the memory is not aligned correctly):
double *g_d, *h_d, *i_d;
g_d = (double*)aligned_alloc(32, sizeof(double)*SIZE);
h_d = (double*)aligned_alloc(32, sizeof(double)*SIZE);
i_d = (double*)aligned_alloc(32, sizeof(double)*SIZE);
for(int i = 0; i < SIZE/4; i++)
{
__m256d a_a, b_a, c_a;
a_a = _mm256_load_pd(g_d+4*i);
b_a = _mm256_load_pd(h_d+4*i);
c_a = _mm256_mul_pd(a_a, b_a);
_mm256_store_pd (i_d+i*4, c_a);
}
free(g_d);
free(h_d);
free(i_d);
Why is the alignment not working for the double
-values?
When running it in gdb, I get
Program received signal SIGSEGV, Segmentation fault.
0x0000000000401669 in _mm256_load_pd (__P=0x619f70) at /usr/lib/gcc/x86_64-linux-gnu/5/include/avxintrin.h:836
Edit: I found my mistake, it was a copy/paste error from a former function, which manifested in that function. Due to not being helpful for others (as I assume), I close the question.