Fix matmul() bug where conj() operands could return incorrect results - #1250
Open
tbensonatl wants to merge 1 commit into
Open
tbensonatl wants to merge 1 commit into
tbensonatl wants to merge 1 commit into
Conversation
matmul() with a conj() operand over a row-major tensor fails for complex types. For example, matmul(conj(A), transpose_matrix(A)). This is because cuBLASLt rejects CUBLAS_OP_C on an operand whose layout differs from that of C/D, returning CUBLAS_STATUS_NOT_SUPPORTED. On debug builds, this error throws an exception, but release builds elide that check. WithMatmulOperand lowers conj(A) as (A^T)^H, handing cuBLASLt transpose_matrix(A) with CUBLAS_OP_C. Transposing a row-major view yields a column-major operand, while matmul always describes C as row-major, so the combination is unsupported for row-major inputs. Existing coverage exercised conj(transpose_matrix(a)), where the extra transpose lands back on row-major. This change only uses the CUBLAS_OP_C path when the operand handed to cuBLASLt is row-major. Otherwise, it falls back to evaluation into a temporary for the input operator. We also make cuBLAS status checks unconditional on build type so that cuBLAS errors will throw in release builds as well. Finally, we free the cublasLt handle, which was previously never destroyed, in the operator destructor. Add new test coverage and enable a previously disabled conj() test. Signed-off-by: Thomas Benson <tbenson@nvidia.com>
Contributor
|
Collaborator
Author
|
/build |
cliffburdick
approved these changes
Sep 11, 2026
Collaborator
Author
|
/build |
2 similar comments
Collaborator
Author
|
/build |
Collaborator
|
/build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
matmul() with a conj() operand over a row-major tensor fails for complex types. For example, matmul(conj(A), transpose_matrix(A)). This is because cuBLASLt rejects CUBLAS_OP_C on an operand whose layout differs from that of C/D, returning CUBLAS_STATUS_NOT_SUPPORTED. On debug builds, this error throws an exception, but release builds elide that check.
WithMatmulOperand lowers conj(A) as (A^T)^H, handing cuBLASLt transpose_matrix(A) with CUBLAS_OP_C. Transposing a row-major view yields a column-major operand, while matmul always describes C as row-major, so the combination is unsupported for row-major inputs. Existing coverage exercised conj(transpose_matrix(a)), where the extra transpose lands back on row-major.
This change only uses the CUBLAS_OP_C path when the operand handed to cuBLASLt is row-major. Otherwise, it falls back to evaluation into a temporary for the input operator. We also make cuBLAS status checks unconditional on build type so that cuBLAS errors will throw in release builds as well.
Finally, we free the cublasLt handle, which was previously never destroyed, in the operator destructor.
Add new test coverage and enable a previously disabled conj() test.