c - How to do arithmetic with OpenCL host vector types? -
heres code:
#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; }
when compiling gcc 4.6, produces error
test.c:14:11: error: invalid operands binary + (have ‘cl_float3’ , ‘cl_float3’)
very strange me, because opencl specification demontrates in section 6.4 that, addition of 2 floatn
. need include other headers?
but more strange when compiling -std=c99
errors like
test.c:16:26: error: ‘cl_float3’ has no member named ‘x’
..for components (x, y , z)...
opencl programs consist of 2 parts.
- a program runs on host. written in c or c++, it's nothing special except uses api described in sections 4 & 5 of opencl specification.
- a kernel runs on opencl device (normally gpu). written in language specified in section 6. isn't c, it's close. adds things vector operations (like you're trying use). compiled host program passing string contains kernel code opencl via api.
you've confused two, , tried use features of kernel language in host code.
Comments
Post a Comment