Bitfield compiler bug

I am running into a couple of bugs with bit fields in structures with the native CUDA compiler. Take the following struct as an example:

struct {

    signed x:2;

    signed y:2;

    signed z:2;

    signed d:26;

} MyStruct;

The x, y and z bit fields end up being treated as unsigned by the compiler. I get different results in my code in the debug CUDA code compared to the native CUDA code. I have worked around this problem by adding 1 to each value before storing it in the struct and then subtracting 1 again when I access the value.

The other problem is that without the d value for padding out to 32 bits, I get a duplicate symbol error:

Test_kernel.cu:26: error: duplicate member `__dummy’.

I am using CUDA 1.0.

-Mark Granger

NewTek

Well… to be honest, I’m surprised bit field could even be compiled.
I’d recommend you to use int and bit operations. Even if they do fix this bug, you won’t get it till November.
Also, even struct doesn’t seem completely working. Once I tried to declare a struct with a 2D array member and it gets put into local memory on some strange occasions. The safest way is to only use primitive types and arrays in device code.

Structs work fine, the problem is arrays. As the hardware cannot index into registers, these get put into local memory. I also found this out the hard way.

The thing is I only indexed it using constant subscript. It seemed like complier having trouble to deduce whether some deep struct/array combination is indexed by constant or not.

Indeed, it was the same in my case. I ended up using a structure with x0,x1,x2,x3… instead. Seems you can never assume the nvcc compiler is smart in any way.