3 Replies Latest reply on Apr 28, 2011 5:19 AM by himanshu.gautam

    event_wait_list into clEnqueueNDRangeKernel() doesn't work??

    Kariddi

      Hi, I'm triggering a strange bug (or situation) with clEnqueueNDRangeKernel() and event_wait_list.

      What I do is making a kernel wait for some buffers to be ready before starting execution. More or less the code that does the trick is this one :

       

       

      status = clEnqueueWriteBuffer(queue, oclb->m_edgeeq, CL_FALSE, 0, 

      sizeof(cl_float)*9, eqparams, 0, NULL, events+2);

      status = clEnqueueWriteBuffer(queue, oclb->m_interpar, CL_FALSE, 0, 

      sizeof(cl_float)*3, lerppar, 0, NULL, events+3);

      /* DOING SOME MORE WORK HERE ... */

      if (blx > 0 && bly > 0 && trx > 0 && trry > 0)

      {

      status = clEnqueueNDRangeKernel(queue, interpk, 2, global_offset, global_size, NULL, 2, events+2, events+5); 

      }



       

      where events is an array of cl_event defined as 

      cl_event events[10];

      I use this for various events.

       

      The problem is that the kernel doesn't seem to wait for the buffers to be ready before starting execution, triggering some nasty and subtle problems (that in the beginning brought me completely in the wrong direction).


      Doing this :

       

      if (blx > 0 && bly > 0 && trx > 0 && trry > 0)

      {

      clWaitForEvents(2, events+2);

      status = clEnqueueNDRangeKernel(queue, interpk, 2, global_offset, global_size, NULL, 0, NULL, events+5); 

      }



       

      putting a clWaitForEvents just before the kernel execution solves the problem and the execution is correct. Even setting the Buffer write as blocking (setting the blocking parameter with CL_TRUE) solves the problem without the need for any event wait.


      So, what's the problem? Why doesn't the function wait for the events I specified in the list? I did something wrong?

      Thank you 

       

        • event_wait_list into clEnqueueNDRangeKernel() doesn't work??
          himanshu.gautam

          Can you please provide a proper testcase. I am not able to reproduce it by doing some event passing stuff in samples.

          Also mention clInfo output.

          • event_wait_list into clEnqueueNDRangeKernel() doesn't work??
            hayabusaxps

            heres an example of my runkernal

             


            int runCLKernels(void)
            {
            cl_int      status;
            cl_event     events[3];
            size_t      global[3]    = {256,256,256};
                 globalThreads[0]   = x0 ;
                 localThreads[0]   = y0 ;
                 localThreads[1]   = z0 ;

             

            status = clGetDeviceInfo(
            devices[0],
            CL_DEVICE_MAX_WORK_GROUP_SIZE,
            sizeof(size_t),
            (void*)&maxWorkGroupSize,
            NULL);


            status = clGetDeviceInfo(
            devices[0],
            CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
            sizeof(cl_uint),
            (void*)&maxDims,
            NULL);


            status = clGetDeviceInfo(
            devices[0],
            CL_DEVICE_MAX_WORK_ITEM_SIZES,
            sizeof(size_t)*maxDims,
            (void*)maxWorkItemSizes,
            NULL);

             
            /*** Set appropriate arguments to the kernel ***/
            /* the input array to the kernel */


            status = clSetKernelArg(
            kernel,
            0,
            sizeof(cl_mem),
            (void*)&input0Buffer);


            status = clSetKernelArg(
            kernel,
            1,
            sizeof(cl_mem),
            (void*)&output0Buffer);

             

            status = clSetKernelArg(
            kernel,
            2,
            sizeof(cl_uint),
            (void*)&c0);

             

            /* Write data to buffer */
            status = clEnqueueWriteBuffer(
            commandQueue,
            input0Buffer,
            1,
            0,
            sizeof(double) * x0 * y0 * z0 *c0,
            input0,
            0,
            NULL,
            &events[0]);

            /* wait for the kernel call to finish execution */
            status = clWaitForEvents(1, &events[0]);
            status = clReleaseEvent(events[0]);

             

            // Enqueue a kernel run call.


            status = clEnqueueNDRangeKernel(
            commandQueue,
            kernel,
            3,
            NULL,
            global,
            NULL,
            0,
            NULL,
            &events[1]);

            /* wait for the kernel call to finish execution */
            status = clWaitForEvents(1, &events[1]);

            status = clReleaseEvent(events[1]);

             

            /* Enqueue readBuffer */
            status = clEnqueueReadBuffer(
            commandQueue,
            output0Buffer,
            CL_TRUE,
            0,
            x0 * y0 *z0 *c0 *sizeof(double),
            output0,
            0,
            NULL,
            &events[2]);

            /* Wait for the read buffer to finish execution */
            status = clWaitForEvents(1, &events[2]);
            status = clReleaseEvent(events[2]);

            return 0;
            }

              • event_wait_list into clEnqueueNDRangeKernel() doesn't work??
                himanshu.gautam

                hayabusaxps,

                Do you mean that if you remove clWaitForEvents from this kernel, you get wrong result?

                I suspect this is a snippet modified from one of the SDK samples. What i can figure out is that you are just using events to refer to various operation, but you never put a condition on any operation where it must wait for some other events. Try putting the writeBuffer event properly in second-last and third-last arguments of enqueueNDRangeKernel. Similarly do this for Read Buffer later.