Alignment of builtin vector types .cu and .cpp have different member alignments of the same struct


I’ve got a simple structure:

struct SimParams {

   float dt;

   float dt2;// dt * dt

   float3 gravity;

   uint4 gridDim;// xyz = dimensions, w = cell num

   float3 gridSize;

   float3 cellSize;


and I found that my data become corrupted since this structure is passed to

int  CudaSimulation(SSimulationInput input, SimParams &simParams);

function defined in .cu file.

The reason of corruption is that uint4 gridDim is aligned to 16-byte boundary in .cu, but not aligned in .cpp code (I compared offsets of each structure member).

uint4 is defined as follows:

struct __builtin_align__(16) uint4


  unsigned int x, y, z, w;


Then I go to definition of builtin_align and see very strange things:

#if defined(__CUDACC__) || defined(__CUDABE__) || \

    defined(__GNUC__) || defined(_WIN64)

#define __builtin_align__(a) \


#else /* __CUDACC__ || __CUDABE__ || __GNUC__ || _WIN64 */

#define __builtin_align__(a)

#endif /* __CUDACC__ || __CUDABE__ || __GNUC__  || _WIN64 */

uint4 is simply unaligned, in case it isn’t compiled with NVCC! I tried to enable alignment, but it resulted in a bunch of errors of MS compiler (“error C2719: ‘val’: formal parameter with __declspec(align(‘16’)) won’t be aligned”). The only way I could make everything work was to remove alignment of built-in vector types.

How is everything suppose to work?

P.S. There was some maybe similar problem discussed before, but about alignment of structures: