有没有办法阻止OpenCL内核执行?

K0n*_*71n 5 c c++ opencl

有没有办法阻止OpenCL内核执行?例如,我启动内核,进行一些计算,然后在满足某些条件时停止它,否则,我等到它完成:

clEnqueueNDRange(queue, ...); // start kernel function

// do other stuff...
// ...

if (some condition met) {
    stopKernel();
} else { 
    clFinish(queue);
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

Jam*_*mes 7

没有.一旦你排队你的内核,它将运行完成.

实现的方法之一的东西像上面是这样做:

while ( data_left_to_process ) {

   clEnqueueNDRangeKernel( ..., NDRange for a portion of the data, ... )

   // other work

   if (condition) {
      break;
   }

   // adjust NDRange for next execution to processes the next part of your data

}

clFinish(queue);
Run Code Online (Sandbox Code Playgroud)

这样可以避免处理所有数据,显而易见的是,您现在提交的工作量较小,这可能会对性能产生影响.