【发布时间】:2018-10-15 10:48:58
【问题描述】:
我有一个类似这样的内核代码
__kernel fn(***){
//X,Y would be image cordinates
int x = get_global_id(0);
int y = get_global_id(1);
//Initialize pixel value
int c = -5 + x * dx;
int d = -5 + y * dy;
int k=0;
for(; k< 500; k++){
//Perform Some Calculations using c and d
//Most of the calculations happen here
if(val > threshold)
break;
}
//Write data based on k
out[x*width+j] = k;
}
我有一种感觉,因为大多数计算都发生在 for 循环中,并且随着 for 循环创建分支,工作组中的一些工作项完成了它们的内核执行并等待整个工作组完成。
如果输出基于执行计数器 k,如何优化?
【问题讨论】: