failing to initialize opencl vector literal

ε祈祈猫儿з 提交于 2019-12-11 03:39:51

问题


So i'm trying to initialize a variable in my opencl host code like this:

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

Which, using Clang 2.9, fails with:

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's tangent vector
                     ^          ~~~~~~~~~~~

And, when using GCC 4.6.1, fails with:

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'm using AMD's opencl sdk, and can build the examples just fine. What is it i'm doing wrong?


回答1:


You are trying to use an OpenCL C-style initializer in your host code, which is presumably compiled with a C compiler. That style of initialization is only valid in your kernels, in other words. And there, you would not use a platform type, but would instead just use a float2.

Try this in your host code instead:

cl_float2 var = { 0.0f, 0.0f };

That will work for you.



来源:https://stackoverflow.com/questions/9230856/failing-to-initialize-opencl-vector-literal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!