I faced with following problem: I need to copy two elements (each of that has size 128 bits) from the global memory to cache. I have to do that for each Thread from Block. If I realize above described like following:
for (int i = 0; i<32; i+=16) (PixelType)&shared[tid+i] = (PixelType)&d_in[num+i];
I think you may have an issue due to alignment on 16-byte boundaries (your union definition). Say “shared” array starts at address 0. Then:
thread with tid=0 will write to byte addresses 0 through 31, inclusively.
thread with tid=1 will write to byte addresses 1 through 32, inclusively.
So, now thread 1 is violating the alignment requirement. It is also overwriting the data that thread 0 wrote (unless you intend this, you’ll have correctness issues). And you also have bank conflicts as multiple threads are writing to the same bank of shared memory, which will reduce your performance.
Let me know if I missed something reading the code.