Note that there are some explanatory texts on larger screens.

plurals
  1. POerror CL_OUT_OF_RESOURCES while reading back data in host memory while using atomic function in opencl kernel
    primarykey
    data
    text
    <p>I am trying to implement atomic functions in my opencl kernel. Multiple threads I am creating are parallely trying to write a single memory location. I want them to perform serial execution on that particular line of code. I have never used an atomic function before. </p> <p>I found similar problems on many blogs and forums,and I am trying one solution.,i.e. use of two different functions 'acquire' and 'release' for locking and unlocking the semaphore. I have included necessary opencl extensions, which are all surely supported by my device (NVIDIA GeForce GTX 630M).</p> <p>My kernel execution configuration:</p> <pre><code>global_item_size = 8; ret = clEnqueueNDRangeKernel(command_queue2, kernel2, 1, NULL, &amp;global_item_size2, &amp;local_item_size2, 0, NULL, NULL); </code></pre> <p>Here is my code: reducer.cl</p> <pre><code>#pragma OPENCL EXTENSION cl_khr_fp64 : enable #pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable #pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable #pragma OPENCL EXTENSION cl_khr_global_int32_extended_atomics : enable #pragma OPENCL EXTENSION cl_khr_local_int32_extended_atomics : enable typedef struct data { double dattr[10]; int d_id; int bestCent; }Data; typedef struct cent { double cattr[5]; int c_id; }Cent; __global void acquire(__global int* mutex) { int occupied; do { occupied = atom_xchg(mutex, 1); } while (occupied&gt;0); } __global void release(__global int* mutex) { atom_xchg(mutex, 0); //the previous value, which is returned, is ignored } __kernel void reducer(__global int *keyMobj, __global int *valueMobj,__global Data *dataMobj,__global Cent *centMobj,__global int *countMobj,__global double *sumMobj, __global int *mutex) { __local double sum[2][2]; __local int cnt[2]; int i = get_global_id(0); int n,j; if(i&lt;2) cnt[i] = countMobj[i]; barrier(CLK_GLOBAL_MEM_FENCE); n = keyMobj[i]; for(j=0; j&lt;2; j++) { barrier(CLK_GLOBAL_MEM_FENCE); acquire(mutex); sum[n][j] += dataMobj[i].dattr[j]; release(mutex); } if(i&lt;2) { for(j=0; j&lt;2; j++) { sum[i][j] = sum[i][j]/countMobj[i]; centMobj[i].cattr[j] = sum[i][j]; } } } </code></pre> <p>Unfortunately the solution doesn't seem like working for me. When I am reading back the centMobj into the host memory, using </p> <pre><code>ret = clEnqueueReadBuffer(command_queue2, centMobj, CL_TRUE, 0, (sizeof(Cent) * 2), centNode, 0, NULL, NULL); ret = clEnqueueReadBuffer(command_queue2, sumMobj, CL_TRUE, 0, (sizeof(double) * 2 * 2), sum, 0, NULL, NULL); </code></pre> <p>it is giving me error with error code = -5 (CL_OUT_OF_RESOURCES) for both centMobj and sumMobj. </p> <p>I am not getting if there is any problem in my atomic function code or problem is in reading back data into the host memory. If I am using the atomic function incorrectly, please make me correct. Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload