Ok I managed to make it work with 3D arrays now but I have another question.
How do I define a non-existing index in the index array. Like if some value of A should not be summed anywhere? (in my above CUDA code I set the index to -1 and skipped it). I guess I could make a garbage column in the result array and dump all the ones I don’t want there. But maybe there is a more elegant solution?