Different pointer size on host and device causing problems

Hi there,

I have the following situation. I have defined a structure on both host and device, i.e. I have the same definition in a C-header and in the program defining the kernel that is using the structure (since as far as I am aware, there is no way to include files in a program). The structure is something along the line of:

typedef struct tag_hash_table
	int 				size;
	bucket *			buckets;
	data_items *		source;
} hash_table;

If I try accessing a bucket in the kernel (say table->buckets[0]->seed), I get

[CL_INVALID_COMMAND_QUEUE] : OpenCL Fatal Error : Finish caused an error that invalidated the queue (0x100112570). This may be due to a resource allocation failure at execution time.
Break on OpenCLFatalBreak to debug.

If I pass only the buckets as an argument to the kernel, everything is fine and I can access all my data. I’ve noticed that sizeof(hash_table) is 12 on the device, but 24 on the host (sizeof(pointer)=8 + sizeof(int)=4 + sizeof(padding added by compiler) = 4). So my guess is that the different sizes cause this problem. I’m providing the memory by invoking:

cl_mem mem_hash = clCreateBuffer(cl_ctx->ctx, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, hashtablesize, hashtable, NULL);

Any idea how I can get this to work (optionally in a way that is portable), or any idea if this is actually the problem? Since the implementation seems to be getting along just fine with the difference in pointer sizes, since else none of my other code would be working at all. Let me know if you need some additional info.


How do you fill the members in the struct and how to you pass it to the kernel?

There is a thread that discusses a similar problem at http://www.khronos.org/message_boards/viewtopic.php?f=37&t=2900

Ah, I guess that is exactly the problem I have! Thank you for pointing me in the right direction :slight_smile: