Titouan Parcollet Titouan Parcollet - 1 month ago 20
C++ Question

From non coalesced access to coalesced memory access CUDA

I was wondering if there is any simple way to transform a non coalesced memory access into a coalesced one. Let's take the example of this array :


Now, i know that if Thread 0 in block 0 access dW[0] and then Thread 1 in block 0 access dw[1], that's a coalesced access in the global memory. The problem is that i have two operations. The first one is coalesced as described above. But the second one isn't because Thread 1 in block 0 needs to do an operation on both dW[0], dW[1] and dW[2].

I know that the initial shape of the container allow or forbid the coalesced access. But dW is a very big array, and i can't transform it during the process ...

Do you know if it's possible to aleviate this problem ?

leo leo

You can try to use shared memory maybe, that might work (or not, hard to tell without an example).

For instance, say the first operation access coalesced data and the second one strides a lot; this may speedup things

__shared__ int shared[BLOCK_SIZE];
// Load data global -> shared with coalesced access ; you may need to load a bit more before/after depending on you application
shared[tid] = global[some id]
// Do the math with coalescing access
// Do the math with the non coalescing access
function1(shared[tid+-1 or wathever])

The idea is to load data in shared in a coalescent manner, and then use shared to do the math, since coalescent access do not matter with shared memory (but bank conflict do on the other hand ; that's usually fine though).

You'll have to give us more information if you want a more accurate help. That's just a hint.