Tuesday 15 June 2010

c - opencl value assignment gets screwed -


I am trying to write a interpolation tool that works on a 3D cube, but in any way Prices are not getting correctly. Here's my simplified kernel, which values ​​should be reassigned from one array to another

  __Collectly interpolate (__Global float * input, __ global float * output) {output [0] = Input [0]; Output [1] = input [1]; Output [2] = Input [2]; Output [3] = input [3]; Output [4] = Input [4]; }   

If I now read the output array in my CPU code, then I should get the values ​​that I had inserted back into the correct array in the input array. I know that the above example does not smart anything, but I am interested in theory.

The output I should get:

  input0: 42.392487 Input 1: 20.455040 Input 2: 3.366035 Input 3: 20.000000 Input 4: 0.948683   

But I'm getting:

  output0: 42.392487 Output 1: 20.455040 Output 2: 20.000000 Output 3: 20.000000 Output 4:  

Update Do: (Again: With additional input / output declaration and updates: 20.000000

CL_MEM_READ_ONLY)

To create a memory here Code, copy data to device and set kernel algorithm

  Float * input = malloc (sizeof (float) * counter); Float * output = maulock (float) * counter); Input = clCreateBuffer (references, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, size (input), input, null); Output = clCreateBuffer (reference, CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR, size (output), output, tap); Err = clSetKernelArg (kernel, 0, size (cl_mem), and input); Err = clSetKernelArg (kernel, 1, size (cl_mem), and output);    

Your problem is that if you declare your variable a pointer aka :

  cl_float * input = molok (cl_float) * counter); Cl_float * Output = Molok (cl_float * counter);   

then

  size (input); // == 8   

will return the size of a float pointer (in your case, with 64bits system, this returns 8) instead of the size of your array.

You need to be the size of the array that needs to be passed to equal logic compared to malloc:

  sizeof (cl_float) * counter; // == size your array   

so that you should make your buffer with the current statement:

  input_buf = clCreateBuffer (reference, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof (Cl_float) * counter, input, tap); Output_buf = clCreateBuffer (reference, CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR, size (cl_float) * counter, output, tap);    

No comments:

Post a Comment