OpenCL内核没有编译?

时间:2014-03-22 15:26:07

标签: opencl

以下是我的内核:

#ifdef FP64

#ifdef cl_khr_fp64 //Khronos extension available
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#define DOUBLE_SUPPORT_AVAILABLE

#elif defined(cl_amd_fp64) //AMD extension available
#pragma OPENCL EXTENSION cl_amd_fp64 : enable
#define DOUBLE_SUPPORT_AVAILABLE
#endif

#endif

#ifdef DOUBLE_SUPPORT_AVAILABLE

//double
typedef double myreal;

#else

//float
typedef float myreal;

#endif

__kernel void calcURatios(__global myreal *ratios, __global myreal *rhs, __local myreal *lRatios, __local myreal *lRhs, myreal c, myreal r)
{
    size_t gid = get_global_id(0);
    size_t lid = get_local_id(0);

    lRatios[lid] = ratios[gid];
    lRhs[lid] = rhs[gid];

    lRatios[lid] = lRatios[lid] / c;
    ratios[gid] = lRatios[lid];

    lRatios[lid] = lRatios[lid] * r;
    lRhs[lid] = lRhs[lid] - lRatios[lid];
    rhs[gid] = lRhs[lid];
}

我收到以下错误:

C:\Users\xxx\AppData\Local\Temp\OCL2AD4.tmp.cl(1): error: expected an
          identifier
  #ifdef(FP64)
        ^

C:\Users\xxx\AppData\Local\Temp\OCL2AD4.tmp.cl(30): error: expected an
          identifier
  #ifdef
        ^

2 errors detected in the compilation of "C:\Users\xxx\AppData\Local\Temp\OCL2AD4.tmp.cl".

Internal error: clc compiler invocation failed.

我甚至尝试使用#ifdef(FP64),但它仍然给了我同样的错误。 我无法理解这是什么问题?

2 个答案:

答案 0 :(得分:0)

检查双数据类型支持哦主机端&在构建程序时传递宏myreal

cl_uint native_double_width;    
clGetDeviceInfo(device_id, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, sizeof(cl_uint), &native_double_width, NULL);

if(native_double_width){
    clBuildProgramm(...,"-D myreal=double",...);
}
else{
    clBuildProgramm(...,"-D myreal=float",...);
}

然后在内核中使用宏(在本例中不是typedef)。

答案 1 :(得分:0)

从.cl文件中读取的文本正在用\n替换每个空格。因此,传递给OpenCL编译器的代码是这样的:

#ifdef
FP_64
#ifdef
cl_khr_fp64
....

添加空格而不是\n后问题得以解决。