在opencl kernel 代码在编译完成后,运行的过程中报如下错误:
Error in kernel:
<kernel>:67:22: error: call to 'mad24' is ambiguous
int tid = mad24(get_local_id(1), get_local_size(0), get_local_id(0));
^~~~~
cl_kernel.h:3368:22: note: candidate function
int __OVERLOADABLE__ mad24(int, int, int);
^
cl_kernel.h:3369:23: note: candidate function
uint __OVERLOADABLE__ mad24(uint, uint, uint);
^
cl_kernel.h:3372:23: note: candidate function
int2 __OVERLOADABLE__ mad24(int2, int2, int2);
^
cl_kernel.h:3374:23: note: candidate function
int3 __OVERLOADABLE__ mad24(int3, int3, int3);
^
cl_kernel.h:3376:23: note: candidate function
int4 __OVERLOADABLE__ mad24(int4, int4, int4);
^
cl_kernel.h:3377:23: note: candidate function
int8 __OVERLOADABLE__ mad24(int8, int8, int8);
^
cl_kernel.h:3378:24: note: candidate function
int16 __OVERLOADABLE__ mad24(int16, int16, int16);
^
cl_kernel.h:3380:24: note: candidate function
uint2 __OVERLOADABLE__ mad24(uint2, uint2, uint2);
^
cl_kernel.h:3382:24: note: candidate function
uint3 __OVERLOADABLE__ mad24(uint3, uint3, uint3);
^
cl_kernel.h:3384:24: note: candidate function
uint4 __OVERLOADABLE__ mad24(uint4, uint4, uint4);
^
cl_kernel.h:3385:24: note: candidate function
uint8 __OVERLOADABLE__ mad24(uint8, uint8, uint8);
^
cl_kernel.h:3386:25: note: candidate function
uint16 __OVERLOADABLE__ mad24(uint16, uint16, uint16);
^
找到kernel 代码中报错的对应行数查看代码如下:
int tid = mad24(get_local_id(1), get_local_size(0), get_local_id(0));
通过报错可以看到mad24的参数只接受int, unit, int2, int3, int4, int8, int16, int32, uint2, unit3, unit4, unit8,uint16。而函数get_local_id(1)、 get_local_size(0)、get_local_id(0)返回值均为size_t,在kernel 中size_t不能隐式转换为int.
cl_kernel.h:3368:22: note: candidate function
int __OVERLOADABLE__ mad24(int, int, int);
^
cl_kernel.h:3369:23: note: candidate function
uint __OVERLOADABLE__ mad24(uint, uint, uint);
^
cl_kernel.h:3372:23: note: candidate function
int2 __OVERLOADABLE__ mad24(int2, int2, int2);
^
cl_kernel.h:3374:23: note: candidate function
int3 __OVERLOADABLE__ mad24(int3, int3, int3);
^
cl_kernel.h:3376:23: note: candidate function
int4 __OVERLOADABLE__ mad24(int4, int4, int4);
^
cl_kernel.h:3377:23: note: candidate function
int8 __OVERLOADABLE__ mad24(int8, int8, int8);
^
cl_kernel.h:3378:24: note: candidate function
int16 __OVERLOADABLE__ mad24(int16, int16, int16);
^
cl_kernel.h:3380:24: note: candidate function
uint2 __OVERLOADABLE__ mad24(uint2, uint2, uint2);
^
cl_kernel.h:3382:24: note: candidate function
uint3 __OVERLOADABLE__ mad24(uint3, uint3, uint3);
^
cl_kernel.h:3384:24: note: candidate function
uint4 __OVERLOADABLE__ mad24(uint4, uint4, uint4);
^
cl_kernel.h:3385:24: note: candidate function
uint8 __OVERLOADABLE__ mad24(uint8, uint8, uint8);
^
cl_kernel.h:3386:25: note: candidate function
uint16 __OVERLOADABLE__ mad24(uint16, uint16, uint16);
所以将以上kernel 代码该为:
int tid = mad24((int)(get_local_id(1)), (int)(get_local_size(0)), (int)(get_local_id(0)));
再次编译运行后正常,大功告成。