I’m using CUBLAS DGEMM and have noticed that if I have values of M,N = 1, K = 0 I get a
CUBLAS_STATUS_INVALID_VALUE error when I make the DGEMM call. (Leaving aside the performance
issues) the docs say this error occurs when M,N,K < 0 ? But they clearly are not.

Is this a bug ?


Maybe a mistake in the documentation, should be <=. What exactly are you trying to do if one of the matrix dimensions is 0?


Can you show the exact call to cublasDgemm ?

M=1,N=1,K=0 should be ok. Maybe your lda,ldb,ldc are wrong.

The documentation for normal DGEMM ( says that the M,N and K must be at least 0 so

assuming that CUBLAS DGEMM is intended to be a replacement then the CUBLAS docs are correct.


Its all a bit tied up in other things, I’ll try and simplify it and post it here.

Well apart from the obvious line

Where inM,inN = 1, inK = 0

status = cublasDgemm(handle, TA, TB, inM, inN, inK, alpha, d_A, lda, d_B, ldb, beta, d_C, ldc);

Ahhh, now I look at it TA and TB are not set to anything when the size is 0, thanks for helping me find that.

Still think the error message is wrong, but IF TA and TB are not set to any of the appropriate values

it returns INVALID_VALUE, irrespective of the values of M,N,K


Ok, you’re right, if K = 0 then all you are doing is scaling the matrix C. I tend to think of the gemms as multiplying matrices, so this use seems weird to me.

The behavior of cublasDgemm() is designed to match the behavior of DGEMM in the reference BLAS implementation. Best I can tell, this is the case. As eelsen points out, k=0 results in the scaling of matrix C by beta. Like the reference implementation, cublasDgemm() also checks the arguments (including the transpose modes) for validity, and it returns CUBLAS_STATUS_INVALID_VALUE when an invalid argument is detected.

Other than the documentation not enumerating all possible reasons for the error code CUBLAS_STATUS_INVALID_VALUE to be returned, I do not see any issue at the moment.

Yeah, maybe just change the docs to include that M,N,K < 0 aren’t the only reasons for this return value.