Combining g++ and NVCC, the pathway to hell is paved with padding! Alignment issues between host

Hi,

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:

struct example
{
double t1;
int t2;
double t3;
};

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:

  1. reorder data structure so that the int comes last.
  2. force g++ to align the structure to 8 bytes ( attribute(align(8)) )
  3. 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.

Kind regards,

Simon

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.

Ok There is a forth option -malign-double that also does work. I tried that option but bjam didn’t feel like passing it on.

Problem solved! Sorry for polluting the forum.

Ok There is a forth option -malign-double that also does work. I tried that option but bjam didn’t feel like passing it on.

Problem solved! Sorry for polluting the forum.

Yes. Today morning I was looking at the same exact issue. This is documented in the manual, I guess… I remember reading about that compiler option… today morning.

Yes. Today morning I was looking at the same exact issue. This is documented in the manual, I guess… I remember reading about that compiler option… today morning.