Hailiang Zhang
Hailiang Zhang

Reputation: 18940

In cublas-4.1.28, is there a convention change in the function parameters?

I want to do the following matrix-matrix multiplication by using cublas:

  cA(M by K) * cB(K by N) => cAout(M by N)

I assigned cA with K as the leading index, and cB with N as the leading index. According to cublas-4.0 handbook, I should do:

HANDLE_ERROR(cublasSgemm(hdl, CUBLAS_OP_N, CUBLAS_OP_N, M, K, N, &alpha, cA, K, cB, N, &beta, cAout, N));    

but it didn't work. Instead, the following code produces the expected results by literately switching cA and cB:

HANDLE_ERROR(cublasSgemm(hdl, CUBLAS_OP_N, CUBLAS_OP_N, N, K, M, &alpha, cB, N, cA, K, &beta, cAout, N));    

The cublas version I was using is 4.1.28. Is there a convention change in the function parameters? Thanks!

Upvotes: 0

Views: 126

Answers (1)

njuffa
njuffa

Reputation: 26185

Recall that CUBLAS uses the column-major storage convention. Assuming these matrices are not part of some larger matrix, the leading dimension of cA is M, the leading dimension of cB is K, and the leading dimension of cAout is M. Your SGEMM call should therefore read

HANDLE_ERROR(cublasSgemm(hdl, CUBLAS_OP_N, CUBLAS_OP_N, M, K, N, &alpha, cA, M, cB, K, &beta, cAout, M));    

Upvotes: 3

Related Questions