Weird compile error with structures defined in *.cl

Hello.

I am facing a weird compile error, which I think it is caused by structure definition in my kernel.cl file.

I have 4 structures in my kernel file as shown below.


struct my_vec4f {
   float x, y, z, w ;
};
typedef struct my_vec4f MyVec4f ;

struct my_vec2f { 
	float x, y ;
}; 
typedef struct my_vec2f MyVec2f ;


struct my_vec2i { 
	int x, y ;
};
typedef struct my_vec2i MyVec2i ;

struct my_vec4i{
	int x,y,z,w;
};
typedef struct my_vec4i MyVec4i;

The first two are used in my kernel function, and the other two (vec2i, vec4i) are not used yet, but I will use them for kernel implementation.

The problem is that compile errors occur when I compile my_kernel.cl file with all four structures.
Moerover, the error message obtained by clGetProgramBuildInfo provide wrong information about the code, which has no errors.

However, when I remove one of them (just removing one of definitions of vec2i and vec4i, so I have only 3 structures),
the kernel is successfully built without errors.

This is very weird.
Anybody can help me how to solve this problem ?

By the way, I’m using GeForce 8800 GTX for OpenCL programming.

I don’t think I can help you with your compile error, but why don’t you use the built-in vector types (float2, float4, int2, int4)? They seem to provide exactly what you’re looking for.

Hello dominik.

Well, it is because the built-in vector types are only available in the device side, not in the host side.
Is there a way to use them in the host side ?
It will help me a lot.

By the way, I solve my problem.
It seems that the nvidia compiler causes errors when the defined structure is not used in the kernel code.
The errors are gone, when I wrote another kernel that uses all of my structures.

On the host side you can use cl_float2, cl_float4, etc. They are accessed like arrays, i.e. to access the first element you write “f[0]” rather than “f.x”.

Thanks dominik. I’ll try that.

I have another question related to built-in types.
Are the built-in math functions, such as dot(), cross() available on the host side ??

I don’t know that. Why don’t you just try to use them and see if it compiles. But I could imagine they’re not available on the host side…

I did some tests with cl_float4 and cl_float2.
Both types work filne in the host side.

It seems that the built-in functions are not supported in the host side.
Calling ‘dot()’ gives me compile errors.

The built-in functions are only supported from within code compiled by OpenCL and called from your kernel. Since your host-side code is neither, they won’t work. However, most of them would be trivial to implement given that math.h already has all the math functions. (Of course you won’t get high-performance vector versions of them as you do in CL.)

You can also execute an OpenCL kernel on the CPU if you want to execute there.

Just a quick remark on the host-side vector types:

In the Nvidia implementation they are accessed like arrays, but in the AMD implementation they are accessed like structs, i.e. with “.x”, “.y” etc. just like in the kernel code.

I hope that the vendors will agree on one notation at some point. I certainly think the AMD way makes more sense because vector types are accessed like structs in both host and kernel code.