c++avx512knights-landing

Memory access error with _mm512_i64gather_pd()


I am trying to use a very simple example of the AVX-512 gather instructions:

double __attribute__((aligned(64))) array3[17] = {1.0,  2.0,  3.0,  4.0,  5.0,  6.0,  7.0,  8.0,
                     9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
                    17.0};
int __attribute__((aligned(64))) i_index_ar[16] = {1,  2,  3,  4,  5,  6,  7,  8, 9, 10, 11, 12, 13, 14, 15, 16};
__m512i i_index = _mm512_load_epi64(i_index_ar);
__m512d a7AVX = _mm512_i64gather_pd(i_index, &array3[0], 1);

Unfortunetly, my last call to _mm512_i64gather_pd results in an memory access error (memory dumped).

Error message in German: Speicherzugriffsfehler (Speicherabzug geschrieben)

I am using Intel Xeon Phi (KNL) 7210.

edit: The error here was, that I was using 32 bit integers with 64bit load instructions and scale in _mm512_i64gather_pd has to be 8 or sizeof(double).


Solution

  • I think you need to set scale to sizeof(double), not 1.

    Change:

    __m512d a7AVX = _mm512_i64gather_pd(i_index, &array3[0], 1);
    

    to:

    __m512d a7AVX = _mm512_i64gather_pd(i_index, &array3[0], sizeof(double));
    

    See also: this question and its answers for a fuller explanation of Intel SIMD gathered loads and their usage.

    ā€”

    Another problem: your indices need to be 64 bit ints, so change:

    int __attribute__((aligned(64))) i_index_ar[16] = {1,  2,  3,  4,  5,  6,  7,  8, 9, ...
    

    to:

    int64_t __attribute__((aligned(64))) i_index_ar[16] = {1,  2,  3,  4,  5,  6,  7,  8, 9, ...