Matrix into vector

How to convert MxN matrix into MN × 1 vector using Cuda???

Typically, an MxN matrix is already stored as an MN x 1 vector. There is no difference in underlying storage.

While that is how it should be done, numerous posts here over the years demonstrate that many programmers seem to think (erroneously) that a good way to store a matrix is as a vector of pointers to non-contiguously stored row (or column) vectors.

If the OP’s questions is how to transfer such a collection of row/column vectors on the host into contiguous storage on the device, the answer is to copy each row/column vector individually to the appropriate place. This may be fairly slow, certainly slower than the single bulk transfer required for copying a contiguously stored matrix.

I thought the OP was talking about something like this as well. I’m glad you brought it up because I had a post all typed out and then I decided against it.

It’s a real shame that multidensional arrays aren’t taught as 1d allocations with special indexing. It simplifies so much.