Failed to initialize opencl vector literal

So, I am trying to initialize a variable in my opencl host code as follows:

cl_float2 es = (cl_float2)(0.0f,0.0f); 

That, using Clang 2.9, fails:

 source/solveEikonalEq.c:75:38: warning: expression result unused [-Wunused-value] cl_float2 es = (cl_float2)(0.0f,0.0f); ^~~~ source/solveEikonalEq.c:75:26: error: cast to union type from type 'float' not present in union cl_float2 es = (cl_float2)(0.0f,0.0f); //ray tangent vector ^ ~~~~~~~~~~~ 

And when using GCC 4.6.1 crash:

 source/solveEikonalEq.c:75:42: warning: left-hand operand of comma expression has no effect [-Wunused-value] source/solveEikonalEq.c:75:26: error: cast to union type from type not present in union 

I am using AMD opencl sdk and can just create examples. What am I doing wrong?

+2
source share
1 answer

You are trying to use the OpenCL C initializer in your host code, which is supposedly compiled using the C compiler. In other words, this initialization style is valid only in your kernels. And there you will not use the platform type, but instead just use float2 .

Try instead in the host code:

 cl_float2 var = { 0.0f, 0.0f }; 

This will work for you.

+5
source

Source: https://habr.com/ru/post/1442695/


All Articles