Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCL kernel execution does not start until clFinish or clWaitForEvents is called

Tags:

c++

opencl

I am trying to run a kernel on the GPU and do additional computation on the host (CPU). I see this effect:

only the kernel needs around 2000 ms:

clEnqueueNDRangeKernel ...

clFinish (or clWaitForEvents, I tried both)

I simulated additional computation on the CPU with sleep(10):

clEnqueueNDRangeKernel ...

sleep(10);

clFinish (or clWaitForEvents)

In theory the kernel should run on GPU and after the 10 sec sleep the kernel should be finished. But time measuring said it all needs 12000ms instead of 10000.

Does clFinish or clWaitForEvents invoke the kernel to start or did I miss something?

I'm using an AMD Fusion CPU/GPU und Linux.

Thanks a lot.

like image 369
Tomas Avatar asked Sep 20 '12 09:09

Tomas


2 Answers

Try calling clFlush right after clEnqueueNDRangeKernel:

clFlush

Issues all previously queued OpenCL commands in a command-queue to the device associated with the command-queue.

http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clFlush.html

like image 194
user1202136 Avatar answered Oct 19 '22 11:10

user1202136


clFinish() only guarantees that the kernel has been finished when the program proceeds ahead this function, but when the kernel will be started to execute is not sure. clFlush() can guarantee that the kernel has been started on device while the program proceeds ahead clFlush() sentence, but when will it be finished is not sure, so you need clFlush() to ensure the kernel has been launched on device, then the time (2000ms) can be overlapped by sleep time (10000ms) on host end. Hope it can be helpful.

like image 29
acekiller Avatar answered Oct 19 '22 12:10

acekiller