KhronosGroup/SPIR

errors like "no known conversion from '__global half *' to 'const double *'"

wuke1993 opened this issue · 8 comments

When I run "clang -cc1 -emit-llvm-bc -triple spir64-unknown-unknown -cl-std=CL1.2 -cl-mad-enable -cl-spir-compile-options "-cl-std=CL1.2 -cl-mad-enable" -include opencl_spir.h -o result kernels.cl", errors like below appear, can anyone help, thanks.

...
opencl_spir.h:5001:37: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant char
char3 __attribute__((overloadable)) vload3(size_t offset, const __constant char *p);
                                    ^
opencl_spir.h:5002:38: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant uchar
uchar3 __attribute__((overloadable)) vload3(size_t offset, const __constant uchar *p);
                                     ^
opencl_spir.h:5003:38: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant short
short3 __attribute__((overloadable)) vload3(size_t offset, const __constant short *p);
                                     ^
opencl_spir.h:5004:39: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant ushor
ushort3 __attribute__((overloadable)) vload3(size_t offset, const __constant ushort *p);
                                      ^
opencl_spir.h:5005:36: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant int *
int3 __attribute__((overloadable)) vload3(size_t offset, const __constant int *p);
                                   ^
opencl_spir.h:5006:37: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant uint
uint3 __attribute__((overloadable)) vload3(size_t offset, const __constant uint *p);
                                    ^
opencl_spir.h:5007:37: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant long
long3 __attribute__((overloadable)) vload3(size_t offset, const __constant long *p);
                                    ^
opencl_spir.h:5008:38: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant ulong
ulong3 __attribute__((overloadable)) vload3(size_t offset, const __constant ulong *p);
                                     ^
opencl_spir.h:5009:38: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant float
float3 __attribute__((overloadable)) vload3(size_t offset, const __constant float *p);
                                     ^
opencl_spir.h:5038:39: note: candidate function not viable: no known conversion from '__global half *' to 'const __constant doubl
double3 __attribute__((overloadable)) vload3(size_t offset, const __constant double *p);

5 warnings and 2100 errors generated.
bader commented

It looks like you need to enable cl_khr_fp16 extension. Please, pass -Dcl_khr_fp16 option.

It looks like you need to enable cl_khr_fp16 extension. Please, pass -Dcl_khr_fp16 option.

Thanks for your reply. But I'm not total understand.

You mean add "cl_khr_fp16" option into the following command line?
"clang -cc1 -emit-llvm-bc -triple spir64-unknown-unknown -cl-std=CL1.2 -cl-mad-enable -cl-spir-compile-options "-cl-std=CL1.2 -cl-mad-enable"

And I have already add "pragma OPENCL EXTENSION cl_khr_fp16 : enable" in my kernels.cl.

In addition, this is my intention:
I used to use the fellow commend to create a OpenCL program object, and the "final_source" is my kernels. Now I want to use the the "final_source", which I stored into "kernels.cl", to create a SPIR binaries.
program_ = clCreateProgramWithSource(context_, 1, &final_source, NULL, &err);

Looking forward to your reply.

Thanks

In opencl_spir.h, all the methods for 'half' are commented, anyone know why? I think this may be the reason of the errors above.
https://github.com/KhronosGroup/SPIR-Tools/blob/master/headers/opencl_spir.h

/**
 * Arc cosine function.
 */
float const_func __attribute__((overloadable)) acos(float);
float2 const_func __attribute__((overloadable)) acos(float2);
float3 const_func __attribute__((overloadable)) acos(float3);
float4 const_func __attribute__((overloadable)) acos(float4);
float8 const_func __attribute__((overloadable)) acos(float8);
float16 const_func __attribute__((overloadable)) acos(float16);
double const_func __attribute__((overloadable)) acos(double);
double2 const_func __attribute__((overloadable)) acos(double2);
double3 const_func __attribute__((overloadable)) acos(double3);
double4 const_func __attribute__((overloadable)) acos(double4);
double8 const_func __attribute__((overloadable)) acos(double8);
double16 const_func __attribute__((overloadable)) acos(double16);
//half const_func __attribute__((overloadable)) acos(half);
//half2 const_func __attribute__((overloadable)) acos(half2);
//half3 const_func __attribute__((overloadable)) acos(half3);
//half4 const_func __attribute__((overloadable)) acos(half4);
//half8 const_func __attribute__((overloadable)) acos(half8);
//half16 const_func __attribute__((overloadable)) acos(half16);
**kernels2.cl:45:23: error: no matching function for call to 'vstore4'
 else if (num == 5) { vstore4((half4)(0.0f), 0, output + globalID0);
                      ^~~~~~~**
opencl_spir.h:5076:36: note: candidate function not viable: no known conversion from 'half4' to 'char4' for 1st argument
void __attribute__((overloadable)) vstore4(char4 data, size_t offset, __global char *p);
                                   ^
opencl_spir.h:5077:36: note: candidate function not viable: no known conversion from 'half4' to 'uchar4' for 1st argument
void __attribute__((overloadable)) vstore4(uchar4 data, size_t offset, __global uchar *p);
                                   ^
opencl_spir.h:5078:36: note: candidate function not viable: no known conversion from 'half4' to 'short4' for 1st argument
void __attribute__((overloadable)) vstore4(short4 data, size_t offset, __global short *p);
                                   ^
opencl_spir.h:5079:36: note: candidate function not viable: no known conversion from 'half4' to 'ushort4' for 1st argument
void __attribute__((overloadable)) vstore4(ushort4 data, size_t offset, __global ushort *p);
                                   ^
opencl_spir.h:5080:36: note: candidate function not viable: no known conversion from 'half4' to 'int4' for 1st argument
void __attribute__((overloadable)) vstore4(int4 data, size_t offset, __global int *p);
                                   ^
opencl_spir.h:5081:36: note: candidate function not viable: no known conversion from 'half4' to 'uint4' for 1st argument
void __attribute__((overloadable)) vstore4(uint4 data, size_t offset, __global uint *p);
                                   ^
opencl_spir.h:5082:36: note: candidate function not viable: no known conversion from 'half4' to 'long4' for 1st argument
void __attribute__((overloadable)) vstore4(long4 data, size_t offset, __global long *p);
                                   ^
bader commented

@wuke1993, sorry for the delay.
What are you trying to achieve?
I suggest switching to clang from llvm.org + https://github.com/KhronosGroup/SPIRV-LLVM-Translator if possible.

@wuke1993, sorry for the delay.
What are you trying to achieve?
I suggest switching to clang from llvm.org + https://github.com/KhronosGroup/SPIRV-LLVM-Translator if possible.

Thanks for your reply.
First, I want to use this tool to generate SPIR binaries with my OpenCL-C file.

clang -cc1 -emit-llvm-bc -triple spir64-unknown-unknown -cl-std=CL1.2 -cl-mad-enable -cl-spir-compile-options "-cl-std=CL1.2 -cl-mad-enable" -include opencl_spir.h -o result kernels.cl

But the first problem I met is

kernels3.cl:33:18: error: no matching function for call to 'vstore3'
                 vstore3((half3)(0.0f), 0, output + globalID0 + 4);
                 ^~~~~~~
opencl_spir.h:5067:36: note: candidate function not viable: no known conversion from 'half3' to 'char3' for 1st argument
void __attribute__((overloadable)) vstore3(char3 data, size_t offset, __global char *p);
                                   ^

For this, I find that in opencl_spir.h, all the methods for 'half' are commented

https://github.com/KhronosGroup/SPIR-Tools/blob/master/headers/opencl_spir.h

void __attribute__((overloadable)) vstore4(double4 data, size_t offset, __private double *p);
void __attribute__((overloadable)) vstore8(double8 data, size_t offset, __private double *p);
void __attribute__((overloadable)) vstore16(double16 data, size_t offset, __private double *p);
//void __attribute__((overloadable)) vstore(half data, size_t offset, __global half *p);
//void __attribute__((overloadable)) vstore2(half2 data, size_t offset, __global half *p);
//void __attribute__((overloadable)) vstore3(half3 data, size_t offset, __global half *p);
//void __attribute__((overloadable)) vstore4(half4 data, size_t offset, __global half *p);

So I uncomment some lines in opencl_spir.h, and the SPIR binary seems generated successfully. But, when I use the following code to create opencl program, it failed with error code "CL_INVALID_BINARY"
program_ = clCreateProgramWithBinary(context_, 1, selected_device_, &binary_size, (const unsigned char**)&program_binary, NULL, &err);

I am not sure the problem is caused by which process.

Looking forward to your reply.
Thanks!

bader commented

@wuke1993, please, make sure that selected_device_ supports both extensions: cl_khr_fp16 and cl_khp_spir via clGetDeviceInfo API.

@wuke1993, please, make sure that selected_device_ supports both extensions: cl_khr_fp16 and cl_khp_spir via clGetDeviceInfo API.

Thanks, I check my device, and find it didn't support "cl_khp_spir", but it support "cl_khr_il_program", in which SPIR-V is needed. So I change into another branch

https://github.com/KhronosGroup/SPIR/tree/spirv-1.1