Software Archive
Read-only legacy content
17061 Discussions

_mm512_i32gather_epi32 segmentation fault

Cheng_C_
Beginner
999 Views

Dear all,

I want to use _mm512_i32gather_epi32 to gather some integers from memory to a 512-bit vector. However, there is a segmentation fault. Would you please give some suggestions? The code is attached. Thanks.

The expected result should be 0, 1, 2, 3, .., 15

// _mm512_i32gather_epi32 test

// Allocate some 64-byte aligned memory
unsigned int * out_array = (unsigned int *) _mm_malloc(sizeof(unsigned int) * 16, 64);
unsigned int * in_array = (unsigned int *) _mm_malloc(sizeof(unsigned int) * 16, 64);

// Initialize the input array that the elements will be gathered from
for(int i=0; i<16; i++){
    in_array = i;
}   

// Initialize the int32 vector containing the indices
__m512i index = _mm512_set_epi32(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); 

// Gather elements from the array
__m512i result = _mm512_i32gather_epi32(index, in_array, 1); 

// Store the result vector back into an array 
_mm512_store_epi32(out_array, result);


for(int i=0; i<16; i++)
    printf("result[%u] = %u\n", i, out_array);

_mm_free(in_array);
_mm_free(out_array);

 

0 Kudos
1 Solution
Patrick_S_
New Contributor I
999 Views

line 16 has to be

__m512i result = _mm512_i32gather_epi32(index, in_array, sizeof(unsigned int));

Yes, I agree this parameter was also confusing for me...

 

View solution in original post

0 Kudos
2 Replies
Patrick_S_
New Contributor I
1,000 Views

line 16 has to be

__m512i result = _mm512_i32gather_epi32(index, in_array, sizeof(unsigned int));

Yes, I agree this parameter was also confusing for me...

 

0 Kudos
Cheng_C_
Beginner
999 Views

Patrick S. wrote:

line 16 has to be

__m512i result = _mm512_i32gather_epi32(index, in_array, sizeof(unsigned int));

Yes, I agree this parameter was also confusion for me...

 

Patrick, thanks very much. It solves the problem!

0 Kudos
Reply