I have created a vector with some values. Then Created a cl_buffer for that vector and pass it to the OpenCL kernel using kernel Arguments. Like this:
In host Code:
std::vector<cl_double> inp;
inp.resize(1024);
for( int i = 0; i<1024;i++)
{
inp[i] = i;
}
filter_kernel = cl::Buffer(context,CL_MEM_READ_ONLY|CL_MEM_USE_HOST_PTR,sizeof(cl_double)*inp.size(),(void*)&inp[0],&err); // also tried (void*)inp.data()
kernel.setArg(0, filter_kernel);
In Kernel Code:
__kernel void test(__global double* inp)
{
for(int m = 0;m<10;m++)
{
printf("inp values are : %d \n",inp[m]);
}
}
This is just and example of showing, how I am passing values in the vector to OpenCL kernel in my program. Is there something wrong with it? As when I print the values, I am getting some random garbage values every time.
I am using MacOS system and Xcode. Device is Intel HD graphics 4000
kernel.setArg(0, filter_kernel)rather than usinginpthe pointer to the memory in the host code. - Neapolitan