The shared qualifier is not permitted with members of unions and structures (CUDA programming guide section 4.2.2.4), and yet I have a need to create a union of shared arrays.
Ideally, I would like to be able to declare this in the .cu source file and successfully have two two-dimensional arrays with the same total number of elements but different dimensions:
#define BlockWidth …
#define BlockHeight …
union {
shared float As[BlockWidth][BlockHeight];
shared float Bs[BlockHeight][BlockWidth];
} Shared;
…
Shared.As[i][j] = …
Unfortunately, this is forbidden. I had hoped to use static multidimensional arrays rather than explicitly compute indices into a one dimensional array (i.e. As[i * BlockHeight + j] = …).
Can anyone explain:
- why the compiler was written to prohibit shared members of unions in all cases
- whether there is an alternative besides explicitly computing indices into a one-dimensional array
Thanks.