我正在尝试编写一个使用 OpenCL 管道的 OpenCL 内核。内核代码如下。
uint tid = get_global_id(0);
uint numWorkItems = get_global_size(0);
int i;
int rid;
int temp = 0, temp1 = 0;
int val;
int szgr = get_local_size(0);
int lid = get_local_id(0);
for(i = tid + start_index; i < rLen; i = i + numWorkItems){
temp = 0;
val = input[i];
temp = hashTable[val - 1];
if(temp){
temp1 = projection[val - 1];
}
reserve_id_t rid1 = work_group_reserve_write_pipe(c0, szgr);
while(is_valid_reserve_id(rid1) == false){
rid1 = work_group_reserve_write_pipe(c0, szgr);
}
if(is_valid_reserve_id(rid1))
{
write_pipe(c0,rid1,lid, &temp);
work_group_commit_write_pipe(c0, rid1);
}
reserve_id_t rid2 = work_group_reserve_write_pipe(c1, szgr);
while(is_valid_reserve_id(rid2) == false){
rid2 = work_group_reserve_write_pipe(c1, szgr);
}
if(is_valid_reserve_id(rid2))
{
write_pipe(c1,rid2,lid, &temp1);
work_group_commit_write_pipe(c1, rid2);
}
}
但是 work_group_reserve_write_pipe 函数总是失败,因此内核在 while 循环中挂起。如果我删除了这个 while 循环,那么代码不会挂起,但不会写入管道。有人能告诉我为什么会这样吗?
该管道被声明为 _write_only 管道。