cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

foofel
Journeyman III

Passing arguments to Kernel

Hi, I am trying to pass a struct from my host program to the Kernel. It looks like this:

OpenCL:

typedef struct sampleOptions_t
{
float density;
float transferScale;
float transferOffset;
float brightness;
}SampleOptions;

Host:

typedef struct sampleOptions_t
{
float density;
float transferScale;
float transferOffset;
float brightness;
} SampleOptions;

My Kernel signature looks that way:

 __kernel void Render
(
__global uchar4 *out_image ,
__private float16 invViewMatrix,
__global uint *volumeImage,
__private SampleOptions opts,
__private float4 opts2
)

My problem is, that "opts" does not always get the right values. "opts2" (only added for debugging purposes) and "opts" get exactly the same values passed, but it depends on the parameter order order if i get the right values. The upper example does not work, but as soon as i change the signature to

 __kernel void Render
(
__global uchar4 *out_image ,
__private float16 invViewMatrix,
__global uint *volumeImage ,
__private float4 opts2,
__private SampleOptions opts
)

it works. I think its an aliasing problem but i cant get it right. Any ideas?

 

Thanks for reading

Tags (2)
0 Likes
3 Replies
Marco13
Journeyman III

Passing arguments to Kernel

Hi there,

 

My first guess is that this could be an alignment issue. To quote from one thread here in the forum:

Structs are difficult, both alignment of individual components and alignment and size of the overall struct must match on the device and host code. It probably will take trial and error to get it correct.

You might want to have a look at the OpenCL spec and search for "alignment", or see the short note about padding structs in the ATI Stream SDK release notes (Section 7)

 

bye

 

 

 

0 Likes
foofel
Journeyman III

Passing arguments to Kernel

Thanks for your answer. But as far as I can see, alignment (and padding) is only necessary if you have types of different size. Even the size of the whole struct should be a perfect match to the native float4 type.

0 Likes
omkaranathan
Journeyman III

Passing arguments to Kernel

Alignments of both the struct and individual elements of the struct on the host side is user's responsibility.

Refer to the following post for better understanding of struct alignment

http://forums.amd.com/forum/messageview.cfm?catid=390&threadid=121236&highlight_key=y

0 Likes