cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

FangQ
Adept I

trigger kernel to wrap up when using a CPU backend

I am trying to use CPU and GPU simultaneously in a computing task. I want to do slightly better than launching two tasks based on a predicted work-load and wish they both finish at roughtly the same time. I am wondering if there is a mechanism to trigger a kernel to stop and return results when it is running on CPU backend.

The attached is a little pseudo-code to illustrate the scheme. I am curious

1. is this currently possible?

2. what call I should be using to replace "??? signal_CPU_kernel_to_stop ???"

 

any commons are welcome. thanks in advance.

lauch_gpu_kernel(gpu_queue,"mykernel", gpu_work_load); lauch_cpu_kernel(cpu_queue,"mykernel", enough_work_load); clEnqueueReadBuffer(gpu_queue, ..., CL_TRUE, ...); // read from GPU, blocking ??? signal_CPU_kernel_to_stop ??? clEnqueueReadBuffer(cpu_queue, ..., CL_TRUE, ...); // read from CPU, blocking

0 Likes
3 Replies
nou
Exemplar

no this is not possible.

0 Likes
Illusio
Journeyman III

If you don't mind assuming cache coherence between CPUs, can't you just pass the CPU workload an OpenCL buffer allocated with USE_HOST_PTR that could point to a "stop" flag, and simply do a quick test on that from inside your OpenCL code?

Then you wouldn't need a function call to stop it, just set the stop flag to TRUE in your main application, execute clFinish(), wait on an event you tied to the CPU workload, or something along those lines, the OpenCL code should then terminate fairly quickly.

You may have to declare the pointer inside your OpenCL code as "global volatile int* pStopFlag" to make sure the value isn't cached in a register though, and there may be other issues, such as it probably being a good idea to issue few work items so that you don't have to do billions of stop tests before the thing terminates.

 

0 Likes

Originally posted by: Illusio If you don't mind assuming cache coherence between CPUs, can't you just pass the CPU workload an OpenCL buffer allocated with USE_HOST_PTR that could point to a "stop" flag, and simply do a quick test on that from inside your OpenCL code?

 

Then you wouldn't need a function call to stop it, just set the stop flag to TRUE in your main application, execute clFinish(), wait on an event you tied to the CPU workload, or something along those lines, the OpenCL code should then terminate fairly quickly.

 

You may have to declare the pointer inside your OpenCL code as "global volatile int* pStopFlag" to make sure the value isn't cached in a register though, and there may be other issues, such as it probably being a good idea to issue few work items so that you don't have to do billions of stop tests before the thing terminates.

 

thank you for your comments. That's exactly what I was thinking. I just did a quick test with USE_HOST_PTR variables on CPU backend, it worked! I do aware that this will not be instant as opencl may cache the ptr values, but it doesn't matter for my purposes.

0 Likes