I'd like to run this simple C-code in GPU with an OpenCL-kernel. Is is possible?
/* new re-order */
#include <stdio.h>
int main()
{int a[15]={7,8,0,4,13,1,14,5,10,2,3,11,12,6,9};
int b[15];
printf(input datas: ");
for (i=0;i<15;i++) printf("%3d",a);
printf("\n");
for (i=0;i<15;i++) b[a]=i;
for (i=0;i<15;i++) printf("%3d",b);
printf("\n");
return 0;
}
// input datas : 7 8 0 4 13 1 14 5 10 2 3 11 12 6 9
// output datas: 2 5 9 10 3 7 13 0 1 14 8 11 12 4 6
Yes, it is possible. For example, here is an equivalent OpenCL kernel:
__kernel void reorder_kernel(__global const int *a, __global int *b)
{
int i = get_global_id(0);
b[a] = i;
}
Please note, this is just an example. Depending on the exact usage, some optimization techniques can be applied to reduce the overhead of the scattered writes to the global memory.
Thanks.
Thank you! It works really!