Tea*_*low 4 c gcc types opencl
继承我的代码:
#include <stdio.h>
#include <CL/cl.h>
#include <CL/cl_platform.h>
int main(){
cl_float3 f3 = (cl_float3){1, 1, 1};
cl_float3 f31 = (cl_float3) {2, 2, 2};
cl_float3 f32 = (cl_float3) {2, 2, 2};
f3 = f31 + f32;
printf("%g %g %g \n", f3.x, f3.y, f3.z);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用gcc 4.6进行编译时,会产生错误
test.c:14:11: error: invalid operands to binary + (have ‘cl_float3’ and ‘cl_float3’)
Run Code Online (Sandbox Code Playgroud)
对我来说很奇怪,因为OpenCL规范在6.4节中只是增加了两个floatn
.我是否需要包含任何其他标题?
但更奇怪的是,在编译时-std=c99
我得到的错误就像
test.c:16:26: error: ‘cl_float3’ has no member named ‘x’
Run Code Online (Sandbox Code Playgroud)
..对于所有组件(x,y和z)......
结构下标编译问题的原因可以在AMD SDK中的标准实现中看到.
如果查看<CL/cl_platform.h>
AMD工具包中的标题,您可以看到如何定义结构.
typedef cl_float4 cl_float3;
typedef union
{
cl_float CL_ALIGNED(16) s[4];
#if (defined( __GNUC__) || defined( __IBMC__ )) && ! defined( __STRICT_ANSI__ )
__extension__ struct{ cl_float x, y, z, w; };
....
#endif
}cl_float4;
Run Code Online (Sandbox Code Playgroud)
使用#if
gcc调用该子句时将忽略该子句--std=c99
.
要使代码与--std = c99一起f3.x
使用f3.s[0]
,您可以替换对with的引用,依此类推.
OpenCL程序由两部分组成.
您已经混淆了两者,并试图在主机代码中使用内核语言的功能.
归档时间: |
|
查看次数: |
2452 次 |
最近记录: |