未能初始化 opencl 向量文字

发布于 2025-01-04 14:08:57 字数 859 浏览 0 评论 0原文

所以我试图在我的 opencl 主机代码中初始化一个变量,如下所示:

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

其中,使用 Clang 2.9,失败:

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
                     ^          ~~~~~~~~~~~

并且,当使用 GCC 4.6.1 时,失败:

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

我正在使用 AMD 的 opencl sdk,并且可以构建例子就好了。 我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂人 2025-01-11 14:08:57

您正在尝试在主机代码中使用 OpenCL C 样式初始化程序,该代码可能是使用 C 编译器编译的。换句话说,这种初始化方式仅在您的内核中有效。在那里,您不会使用平台类型,而只会使用 float2

在您的主机代码中尝试一下:

cl_float2 var = { 0.0f, 0.0f };

这对您有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文