fix(sgemm): destroy cublas handle to avoid alloc failed#415
Merged
DefTruth merged 1 commit intoxlite-dev:mainfrom Apr 5, 2026
Merged
fix(sgemm): destroy cublas handle to avoid alloc failed#415DefTruth merged 1 commit intoxlite-dev:mainfrom
DefTruth merged 1 commit intoxlite-dev:mainfrom
Conversation
Contributor
Author
|
Hi @DefTruth, could you please help review this PR when you have time? |
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.
What
Fix cuBLAS handle leak in kernels/sgemm/sgemm_cublas.cu by destroying handle after GEMM, and add status checks for cuBLAS API calls.
Why
Repeated benchmark calls can accumulate unreleased cuBLAS handles, then torch.matmul may fail with CUBLAS_STATUS_ALLOC_FAILED when creating a new handle.
Changes
Added CHECK_CUBLAS macro for cuBLAS status checking
cublas_sgemm: create -> setMathMode -> gemm -> destroy
cublas_sgemm_tf32: create -> setMathMode -> gemm -> destroy
Repro error
RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling cublasCreate(handle)
Link issue
Fixes SGEMM benchmark may hit CUBLAS_STATUS_ALLOC_FAILED due to cublas handle leak in kernels/sgemm/sgemm_cublas.cu #414
Environment
GPU: NVIDIA H200 NVL (143771 MiB)
Driver: 580.126.09
CUDA Toolkit (nvcc): 12.8 (Build cuda_12.8.r12.8/compiler.35583870_0)
PyTorch: 2.5.0+cu124
PyTorch CUDA runtime: 12.4
CUDA available in torch: True
Compute capability: (9, 0)