Software Archive
Read-only legacy content
17061 Discussions

How to use gather operations on MIC

shiva_rama_krishna_b
386 Views

Hi i want to gather a some elements from a array whose indices are specified in "index". Here is the code i have written.

#include<stdio.h>
#include<stdlib.h>
#include<immintrin.h>
int main()
{
float* arrA = (float*)_mm_malloc(sizeof(float)*500,64);
float* arrB = (float*)_mm_malloc(sizeof(float)*500,64);

for(int i=0; i <42; i++)
{
arrA =(float )i;
arrB = (float)1;

}
__m512i index = {0,1,2,3,4,5,6,7,8,9,10,11,12,16,19,21};
__m512 v1;
v1 = _mm512_i32gather_ps(index,(void*)arrA,sizeof(float));
_mm512_store_ps((void*)arrB,v1);

for(int i =0; i < 42; i++)
printf("%f ",arrB);
printf("\n");
}

 

In the above code i want to i want gather elements from "arrA" whose indices are given in "index". and all gathered elements will be stored in "arrB".

But it is giving Error: Illegal instruction (core dumped). If I remove _mm512_store_ps it is executing. Can some one tell what is wrong with code.

 

Thanks

sivaramakrishna

 

0 Kudos
2 Replies
Kevin_D_Intel
Employee
386 Views

You would compile with -mmic and run the executable on the coprocessor itself. It fails with the illegal instruction when compiled and executed on the host.

micnativeloadex is handy for a quick test like this one but if you prefer, transfer the executable to the coprocessor and then connect to the coprocessor to run it interactively.

$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.2.144 Build 20140120

$ icc -mmic u508619.cpp

$ /usr/bin/micnativeloadex a.out
0.000000 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.000000 10.000000 11.000000 12.000000 16.000000 19.000000 21.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000

 

0 Kudos
shiva_rama_krishna_b
386 Views

Thanks Davis :)

0 Kudos
Reply