0

Suppose, I have a ROWS*COLS=4*4 matrix

A=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]

arranged in K1*K2=2*2 tiles.

I want to traverse the elements of A such that I get the sequence as

B = [1,2,5,6,3,4,7,8,9,10,13,14,11,12,15,16].

Why don't we store the matrix in such a sequence in a 1D array in the first place?

Will this help our CUDA program to do matrix multiplication faster?

user366312
  • 16,949
  • 65
  • 235
  • 452
  • 5
    isn't this how its designed in opengl and managed through glVertexAttribPointer function? I don't think anyone stores matrices in multi dimensional arrays where performance matters – X-_-FARZA_ D-_-X Aug 08 '23 at 22:22
  • I'm with Farza here. This is often specified as a 1D array of N repetitions of M-sized elements. – tadman Aug 08 '23 at 23:21
  • 1
    That's called a [Z-order curve](https://en.wikipedia.org/wiki/Z-order_curve). The opaque Array type in CUDA alsmost certainly works that way. The wikipedia article talks about it can help with matrix multiplication. – Homer512 Aug 09 '23 at 06:58

0 Answers0