-1

I'm beginner for cuda. I want to try to solve svd for row-major matrix using cusolver API. but I'm confusing about leading dimension for matrix A.

I have a row-major matrix 100x10.(e.g, I have 100 data which is in the 10 dimensional space.) As the CUDA documentation, cusolverDnDgesvd function needs lda parameter(leading dimenstion for matrix A). My matrix is row-major so I gave 10 to cusolver gesvd function. But function was not working. This function indicated that my lda parameter was wrong. Ok, I gave 100 to cusolver gesvd function. Function was working but the results of function (U, S, Vt) seems to be wrong. I mean, I can't get the matrix A from USVt.

As my knowledge, cuSolver API assume all matrix is column-major. If I changed my matrix into column-major, m is lower than n(10x100). But gesvd function only works for m >= n.

Yes, I'm in trouble. How can I solve this problem?

Hotaek Han
  • 21
  • 1

1 Answers1

2

Row-major, col-major and leading dimension are concepts related to the storage. A matrix can be stored in either scheme, while representing the same mathematical matrix.

To get correct result, you could use cublasDgeam() to change your row-major 100x10 matrix into a col-major 100x10 matrix, which is equivalent to matrix transpose while keeing the storage order, before calling cusolver.

There are many sources talking about storage ordering,

https://en.wikipedia.org/wiki/Row-major_order

https://fgiesen.wordpress.com/2012/02/12/row-major-vs-column-major-row-vectors-vs-column-vectors/

https://eigen.tuxfamily.org/dox-devel/group__TopicStorageOrders.html

Confusion between C++ and OpenGL matrix order (row-major vs column-major)

as well as leading dimension

http://www.ibm.com/support/knowledgecenter/SSFHY8_5.3.0/com.ibm.cluster.essl.v5r3.essl100.doc/am5gr_leaddi.htm

You should google them.

Community
  • 1
  • 1
kangshiyin
  • 9,681
  • 1
  • 17
  • 29
  • Thanks for comment. – Hotaek Han Jul 05 '16 at 11:44
  • actually I just solved this problem using transpose. I understand that cuBLAS API assume that all in/out matrix is column major. so I changed my row-major matrix(100x10) into column-major(10x100) using transpose. I just gave that colum-major matrix to gesvd function HOWEVER I gave other parameters such as m, n, lda, ldu, ldvt from row-major matrix. I mean, just input 100 into m, 10 into n, A is transposed row-major matrix, 100 into lda, 100 into ldu, 10 into ldvt. Function was working well. I can get a origin matrix A from U * S * Vt. Of course, U, Vt matrix from gesvd are also column-major. – Hotaek Han Jul 05 '16 at 11:51