在 openCL 代码中使用管道相关函数时生成错误

Build error when using pipe related functions in openCL code

我写信是为了使用 opencl 2.0 的管道功能。我有一个内核可以过滤输入并写入管道。但问题是,当我使用与管道相关的函数时,出现错误 "function declared implicitly"。当我在线查看时,我发现如果函数在使用前未声明,则此错误通常会出现在 C 代码中。但这是一个openCL库函数。

我的内核代码是:

__kernel void filter1_kernel(__global int *input, const unsigned int rLen, const unsigned int lower, const unsigned int upper, __global int *pipe1) {

unsigned int bitmap = 0;
int count = 0;
//reserve_id_t rid;

uint numWorkItems = get_global_size(0);
uint tid          = get_global_id(0);
uint num_packets = get_local_size(0);

while(tid < rLen){
    if(input[tid] >= lower && input[tid] <= upper){
        bitmap = bitmap | (1 << count);
        printf((__constant char *)"\nfilter1 %u %u %d %u", tid, bitmap, input[tid], count);
    }
    tid += numWorkItems;
    count++;
}

reserve_id_t rid = work_group_reserve_write_pipe(pipe1, num_packets);
while(is_valid_reserve_id(rid) == false) {
    rid = work_group_reserve_write_pipe(pipe1, num_packets);
}
//write to pipe

}

我得到的错误是:

构建日志缓冲区长度:1048 --- 构建日志 --- "C:\Users\pdca\AppData\Local\Temp\OCLFB5E.tmp.cl",第 40 行:错误:函数 "work_group_reserve_write_pipe" 隐式声明 reserve_id_t rid = work_group_reserve_write_pipe(pipe1, num_packets); ^

"C:\Users\pdca\AppData\Local\Temp\OCLFB5E.tmp.cl",第 40 行:警告:一个值 类型 "int" 不能用于初始化类型的实体 "reserve_id_t" reserve_id_t rid = work_group_reserve_write_pipe(pipe1, num_packets); ^

"C:\Users\pdca\AppData\Local\Temp\OCLFB5E.tmp.cl",第 41 行:错误:函数 "is_valid_reserve_id" 隐式声明 while(is_valid_reserve_id(rid) == false) { ^

"C:\Users\pdca\AppData\Local\Temp\OCLFB5E.tmp.cl",第 42 行:警告:一个值 "int" 类型的实体无法分配给 "reserve_id_t" 类型的实体 rid = work_group_reserve_write_pipe(pipe1, num_packets); ^

在编译 "C:\Users\pdca\AppData\Local\Temp\OCLFB5 时检测到 2 个错误 E.tmp.cl”。 前端阶段编译失败。

                            --- Build log ---

错误:clBuildProgram (CL_BUILD_PROGRAM_FAILURE)

来自 CL 规范 (https://www.khronos.org/registry/cl/specs/opencl-2.0.pdf),第 203 页:

If the cl-std build option is not specified, the highest OpenCL C 1.x language version supported by each device is used when compiling the program for each device. Applications are required to specify the –cl-std=CL2.0 option if they want to compile or build their programs with OpenCL C 2.0.

因此,如果您没有在 clBuildProgram() 调用中包含此选项,CL 编译器将无法识别任何 2.0 语言功能。因此,您的电话应该看起来像这样:

clBuildProgram (program, num_devices, device_list, "–cl-std=CL2.0", NULL, NULL);

另外,我认为你的内核参数不正确。您不能使用 __global int *pipe1 作为管道函数的参数。它可能应该声明为 __write_only pipe int pipe1.