I wrote a kernel code which is compiled successfully. Now I start writing the host code. But in the host when try to create memory objects (create buffers for the inputs and output), I got confused about what are my input are and how to specify the size of the input and output arrays. I try the following host code.
cl_mem dev_X_train = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int) * [4344][20], NULL, NULL);// size
cl_mem dev_Y_train = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(int) * [4344], NULL, NULL);// size
Kernel code :
inline float distance(__global int* restrict array_point_A, __global int* restrict array_point_B) {
float sum = 0.0;
float w[20] = { 0.0847282, 0.0408621, 0.105036, 0.0619821, 0.0595455, 0.0416739, 0.0181147, 0.00592921,
0.040049, 0.0766054, 0.0441091, 0.0376111, 0.0124285, 0.0733558, 0.0587338, 0.0303001, 0.0579207, 0.0449221,
0.0530462, 0.0530462 };
for (int i = 0; i < 20; ++i) {
float a = array_point_A[i] - array_point_B[i];
float wieghted_distance = w[i] * (a * a);
sum += wieghted_distance;
}
return sqrt(sum);
}
__kernel void classifier(__global int * restrict X_train,__global int * restrict Y_train,__global int * restrict data_point, int k)
{
float array_dist[4344] = {};
int index_arr[4344] = {};
for (int i = 0; i < 4344; ++i)
{
array_dist[i] = distance(X_train,data_point);
index_arr[i] = i;
}
.......................
..............................
int class_label = min_index; }