Skip to content

runtime: use cublaslt for bf16 gemm with f32 output - #156

Merged
xiaguan merged 2 commits into
pegainfer-project:masterfrom
zjbpaul1317:fix/cublas-classic-handle-destruction
Nov 23, 2026
Merged

xiaguan merged 2 commits into
pegainfer-project:masterfrom
zjbpaul1317:fix/cublas-classic-handle-destruction

Conversation

@zjbpaul1317

Copy link
Copy Markdown
Contributor

Summary

When PyTorch has already loaded cuBLASLt 13.1 from its Python environment, kern can load the system's classic cuBLAS 13.0. With this mixed pair, destroying a classic handle bound to a non-default stream can free the same allocation twice and abort the host process.

Run extern:cublas_bf16_tn_f32 through the stream's existing cuBLASLt handle with FP32 output layouts and a 32 MiB workspace per stream. This removes classic cuBLAS handle creation and destruction from kern. In the tested environment, the process can still map both versions of cuBLASLt.

Validation

On an NVIDIA L20 with PyTorch 2.14.0+cu130, both builds loaded the same Qwen3-4B kern.Runtime inside a PyTorch process. With the system CUDA library directory on LD_LIBRARY_PATH, and again with LD_LIBRARY_PATH empty, the baseline aborted during teardown with exit code 134. The patched build exited normally in both cases. Both builds exited normally with the compatibility symlinks in use.

  • All six targeted GPU tests passed, covering BF16-to-FP32 output in eager and CUDA graph execution, padded output stride, classic cuBLAS mappings, pinned algorithms, and FP8 GEMM.
  • All 41 host-side kern-runtime tests passed on Linux.

K3 end-to-end numerical validation is pending.

The classic cuBLAS handle could abort during destruction when a host
process loaded cuBLAS and cuBLASLt from different builds. Use the stream's
cuBLASLt handle for f32 output and retain the 32 MiB workspace per stream.

On L20, the f32 GEMM, pinned algorithm and FP8 tests passed. In a torch
process without the compatibility symlinks, the baseline aborted while
dropping the Qwen3-4B runtime and the new build exited successfully.
Use fixed-size arrays for the little-endian float reads so the test
passes the chunks_exact_to_as_chunks lint on current stable Clippy.
@xiaguan

xiaguan commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Thanks for the clean change and thorough tests! Removing the classic libcublas handle and unifying extern:cublas_bf16_tn_f32 onto cublasLtMatmul is a nice simplification on its own — it drops an entire shared-library dependency and avoids eagerly creating a classic cuBLAS handle for manifests that never use the f32 GEMM.

For the underlying mixed-library / duplicate-mapping issue (where the process can still map two versions of libcublasLt), the root cause is cudarc's get_lib_name_candidates trying unversioned lib<name>.so before the versioned SONAME lib<name>.so.<major> on Linux (tracked upstream in chelsea0x3b/cudarc#603). We opened #166 to track fixing that separately across libcublasLt and libcupti.

Merging this now.

@xiaguan
xiaguan merged commit 9cfb7e9 into pegainfer-project:master Nov 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants