Alignment Trouble (mismatch)

I’m having trouble with an alignment mismatch in my code. This is with the CUDA 1.1 beta on an Intel Mac. All files are being compiled from scratch on the problem machine. This doesn’t occur on our RHEL 5 machine.

Our project consists of .c files (compiled with g++ since they use C++ comments, variable decl rulets, etc), .cu files containing host and GPU code and .cu files containing GPU device kernels.

This is the problem struct:

typedef struct

{

  char    aname[5];	/* atom name */

  double  xyz[3];  /* original xyz coordinates */

  double  XYZ[3];  /* transformed xyz coordinates */

  double  q;  /* atom charge */

  double  r;  /* atom radius */

  int     s;    /* ACE solvation type */

  double  access;  /* accessibility */

  double  accessgrad[3];      

  double  abc[3];

  int     one_two_bonds[ MAX_12_BONDS ];

} atom_t;

Unless I’m adding incorrectly, on the intel mac, the size of this struct should be 145 bytes.

The problem I’m seeing is that the g++ generated object code is padding this struct to 148 while the nvcc generated object code is padding this struct to 152. This obviously causes array mismatches and breaks everything.

Does anyone know what might cause this size mismatch? nvcc should just be calling g++ for the host portion, and I’m not using any crazy cross-compilation flags.

Is there a flag that will force/standardize the padding?

David

Massimiliano from NVIDIA pointed me towards the solution to this problem.

>From the release note.

When compiling GCC, special care must be taken for structs that

  contain 64-bit integers.  This is because GCC aligns long longs

  to a 4 byte boundary by default, while NVCC aligns long longs 

  to an 8 byte boundary by default.  Thus, when using GCC to 

  compile a file that has a struct/union, users must give the

  -malign-double

  option to GCC.  When using NVCC, this option is automatically

  passed to GCC.

This was the entire problem - adding -malign-double to my g++ options in my Makefile fixed everything. Here’s a lesson for reading release notes :)

I didn’t run into the problem on my non-mac hardware because I used the -m64 flag which I think implies -malign-double. This flag is removed for Intel Mac so the issue cropped up.

In any case, thanks Massimiliano/NVIDIA!

Amazing code, how about the flag for standardize the padding now?