Opencl 错误:';原子';未在此范围内声明,其他未声明

Opencl 错误:';原子';未在此范围内声明,其他未声明,opencl,Opencl,请帮忙。。。 在opencl程序中,我得到了这些错误。 我没有“oclUtils.h”头文件。S0我还没有把它包括在我的计划中。这就是我遇到这个问题的原因。我也在发送我的内核。 如果这就是原因,我怎么能不用oclUtils.h使用原子函数呢 *"__kernel void BLAS_susdot_kernel(__global float *x,__global int *index,__global float *y,const int n,__global float* dot

请帮忙。。。 在opencl程序中,我得到了这些错误。 我没有“oclUtils.h”头文件。S0我还没有把它包括在我的计划中。这就是我遇到这个问题的原因。我也在发送我的内核。 如果这就是原因,我怎么能不用oclUtils.h使用原子函数呢

*"__kernel void BLAS_susdot_kernel(__global float *x,__global int *index,__global float        *y,const int n,__global float* dot_p)                    \n" \
"{                                                                                      \n" \
"    int block_x = get_group_id(0);                                                                     \n" \
"    int thread_x = get_local_id(0);                                                                    \n" \
"    int i = get_global_id(0);                                                                          \n" \
"    float dot_value, old = *dot_p;                                                                     \n" \
"    int warp_thread_id = i & (32-1);                                                                   \n" \
"    __local float tmp[512];                                                                                    \n" \
"    __local float share_dot_p;                                                                         \n" \
"    if(thread_x == 0)                          \n" \
"       share_dot_p = 0.0;                              \n" \
"    if (i < n)                                 \n" \
"   {                                        \n" \
"        tmp[i]= x[i]*y[index[i]];           \n" \
"        if(warp_thread_id <16 && (i+16)< n) \n" \
"            tmp[i]+=tmp[i+16];              \n" \
"        if(warp_thread_id <8 && (i+8)< n )  \n" \
"            tmp[i]+=tmp[i+8];               \n" \
"        if(warp_thread_id <4 && (i+4)< n )  \n" \
"            tmp[i]+=tmp[i+4];               \n" \
"        if(warp_thread_id <2 && (i+2)< n)   \n" \
"            tmp[i]+=tmp[i+2];               \n" \
"        if(warp_thread_id==0 && (i+1)< n)   \n" \
"        {                                   \n" \
"            tmp[i]+=tmp[i+1];               \n" \
"            do                              \n" \
"            {                               \n" \
"                dot_value = old;            \n" \
"                old = convert_int( atomic_cmpxchg((volatile __global unsigned int*)&share_dot_p, convert_int(dot_value), convert_int(tmp[i] + dot_value)));  \n" \
"            } while (dot_value != old);     \n" \
"            //share_dot_p +=tmp[i];         \n" \
"        }                                   \n" \
"        if(thread_x==0)                  \n" \
"        {                                   \n" \
"                                            \n" \
"            do                              \n" \
"            {                               \n" \
"                dot_value = old;            \n" \
"                old = convert_int(atomic_cmpxchg((volatile __global unsigned int *) dot_p, convert_int(dot_value), convert_int(share_dot_p+dot_value)));  \n" \
"            } while(dot_value != old);                                                 \n" \
"               // *dot_p += share_dot_p;                                               \n" \
"                                                                                       \n" \
"        }                                                                              \n" \
"   }                                                                                   \n" \
"}                                                                                      \n" \
"\n";*

由于您正在使用的是OpenCL中可选扩展的一部分
atomic_cmpxchg
,因此需要检查设备是否支持它,然后在内核代码中启用它:

  • 检查
    clGetDeviceInfo(…,cl\u设备扩展,…)返回的扩展中是否列出了
    cl\u khr\u global\u int32\u base\u atomics

  • 将以下内容添加到内核代码的顶部:

  • #pragma OPENCL扩展cl_khr_global_int32_base_atomics:启用

    请注意,如果使用带有_本地或64位操作数的原子函数,则可能需要启用其他扩展:

    #pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_global_int32_extended_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_local_int32_extended_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable
    
    此外,请确保您使用的是OpenCL1.1或更高版本,因为原子函数在OpenCL1.0中的命名不同。例如,如果使用NVidia的
    nvcc
    实用程序脱机编译内核,请确保指定了
    -arch
    命令行开关

    这些特定错误与oclUtils.h无关。这是一个NVidia头文件,只有在主机(而不是内核)代码中调用ocl*函数时才需要它

    #pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_global_int32_extended_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_local_int32_extended_atomics : enable
    #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable