I’m trying to pass a class compiled by the g++(4.3.2) compiler to a CUDA kernel compiled by NVCC.
As an example lets consider following class:
When i request a sizeof in g++ he will tell me that the size of that thing is 20 bytes. When I ask a sizeof in NVCC he will tell me that the size of the very same thing is 24 bytes. So obviously I cannot pass the struct created by g++ to NVCC since they are not binary compatible.
The reason why they are not the same is that NVCC aligns int’s to 64 bit boundaries while g++ (which is 32 bits) will align them to 32 bits boundaries.
I have already following solutions to my problem:
reorder data structure so that the int comes last.
force g++ to align the structure to 8 bytes ( attribute(align(8)) )
use a 64 bit system
I don’t like any of these solutions. 1) is very hard to to with complex data structures and is not always possible. 2) is just annoying to add everywhere and is not portable. 3) My religion forbids me to use 64 bit systems.
Is there anyone who has a better idea to solve this problem, because passing data structures around is useful from time to time…
Any help would be greatly appreciated.
I have a 32 OS ( Ubuntu with gcc 4.3.2) on a 64 bit machine with an GTX480. I use nvcc 3.1 V0.2.1221.