Host memory is getting value just after kernel finishes

Discussion created by richeek.arya on May 26, 2011
Latest reply on May 28, 2011 by nou

Hi all, 

I have a strange problem. I am calling the openCL kernel and waiting on it to finish  execution. This is how I am doing it:

status = clEnqueueNDRangeKernel(commandQueue, kernel, 1, NULL, globalThreads, localThreads, 0, NULL, &events[0]);
    /* wait for the kernel call to finish execution */
    status = clWaitForEvents(1, &events[0]);
    if(status != CL_SUCCESS)
            "Error: Waiting for kernel run to finish. \
        return 1;

status = clReleaseEvent(events[0]);

  And after this I am reading back the memory buffers on the host side:

/* Enqueue cand_dist Buffer*/
    status = clEnqueueReadBuffer(commandQueue, cand_dist_d, CL_TRUE, 0, LIST_SIZE*no_mimo_sym * sizeof(float), cand_dist, 0, NULL, &events[1]);


But when I run Visual Studio debugger I see cand_dist  get the values as soon as clWaitForEvents() returns. I do not understand how this could happen? At the end of the execution I am freeing memory so it is not stray values from old run. Does anyone know why this may happen?

I allocated device side memory like this:

cand_dist_d = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, sizeof(float)*LIST_SIZE*no_mimo_sym , cand_dist, &status);

So is it device writing back the data on the host side too?

Thanks for the help!