0

I am calling cblas_sgemm using the following parameters:

  1. order: CblasRowMajor
  2. transA, transB: either CblasTrans or CblasNoTrans
  3. M: the number of rows (height) of the matrix op(A) and of the matrix C
  4. N: the number of columns (width) of the matrix op(B) and of the matrix C
  5. K: the number of columns (width) of the matrix op(A) and the number of rows (height) of the matrix op(B)
  6. alpha: scalar
  7. A: pointer to matrix A
  8. LDA: When transA = CblasNoTrans then LDA = M, otherwise LDA = K
  9. B: pointer to matrix B
  10. LDB: when transB = CblasNoTrans then LDB = K, otherwise LDB = N
  11. beta: scalar
  12. C: pointer to matrix C (bias on entry and the result on exit)
  13. LDC = M

where, op(M) = M if transM is CblasNoTrans, and Transpose(M) otherwise

The parameters are correct (according to the documentation) but I am getting am error: "** On entry to SGEMM, parameter number X had an illegal value" - How do I fix this error?

PolarBear2015
  • 745
  • 6
  • 14

1 Answers1

0

TL;DR When using: CblasRowMajor

  1. Keep M,N,K setting as listed above.
  2. Flip Transpose value when computing LDA,LDB, and set LDC = N

Details: I ran into this problem using multiplication with Transpose and could not find a detailed answer that answers my problem. I write this Q/A in hope it will be useful for others.

The root problem, as others have noted, is that cblas is a wrapper over BLAS, which is written in FORTRAN that does not have an order parameter and expect column major matrix representation. The available documentation (usually) is the BLAS documentation - which I used above in the question.

However, While M,N,and K are logical values (the width/height of matrix regardless of its representation) the leading dimensions (LDA, LDB, LDC) are not. Therefore the computation of M,N, and K should stay the same when using CblasRowMajor. However, the transpose of op(A), op(B) and C, should be use when computing LDA, LDB, and LDC.

If CblasColMajor is used then it is the same representation as Fortran and the parameter setting shown in the question is the correct one.

Also note that when you get and error in parameter X, X is shifted by 1 because the error originated in BLAS that does not have an order parameter.

PolarBear2015
  • 745
  • 6
  • 14