有什么办法可以阻止OpenCL内核执行?
例如,我启动内核,进行一些计算,然后在满足某些条件的情况下将其停止,否则,我等待它完成:
clEnqueueNDRange(queue, ...); // start kernel function
// do other stuff...
// ...
if (some condition met) {
stopKernel();
} else {
clFinish(queue);
}
谢谢你的帮助
最佳答案
不会。一旦将您的内核排入队列,它就会运行完成。
完成上述操作的一种方法是执行以下操作:
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);
这样您就可以避免处理所有数据,而且显然要权衡取舍,因为您现在正在以较小的块提交工作,这可能会对性能产生影响。
关于c++ - 有什么办法可以阻止OpenCL内核执行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9039155/