Skip to content

fix(rocm): stop leaking alpha/beta pairs in the GEMM pointer wrappers - #2252

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-2243-gemm-alpha-beta-leak
Oct 9, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-2243-gemm-alpha-beta-leak

Conversation

@inureyes

@inureyes inureyes commented Oct 8, 2026

Copy link
Copy Markdown
Member

Three ROCm GEMM pointer wrappers heap-allocated a never-freed alpha/beta pair for any scale other than (1, 0) and (1, 1), leaking 8 bytes per call. The comments blamed the library retaining host pointers past enqueue, but no pointer mode is set, so the scalars are read during the call, and CommandEncoder::launch_kernel runs its functor synchronously. hipblaslt_gemm_ptrs, hipblaslt_gemm_rowmajor_on_stream and rocblas_gemm_ptrs now pass &alpha and &beta of the lambda's by-value captures (the parameters in the on-stream variant), as the epilogue and batched paths already do. The use_hip_graphs() comment records that deferred graph nodes would need a revisit. LOCAL_FIXES 43; stays in mlxcelverse.

No Rust-reachable path calls these wrappers with another scale (addmm goes through hipblaslt_gemm and gemm_rocblas; the current callers pass 1/0 or 1/1), so there is no behavior or leak test for it, and no before/after leak measurement was possible.

Verification

On gfx1151: git grep 'new float\[' over patches-rocm is empty; make verify-versions verify-kernel-dtype-keys verify-kernel-port-dispatch verify-llama-compat verify-fmt verify-rocm-overlay pass; rocm_hipblaslt_concurrency, rocm_rocblas_handle_concurrency and rocm_gather_qmm_expert_batched pass. Full make verify-rocm-held result is in the comment below.

Not verified: Metal and CUDA are not available on this host. Neither is touched (ROCm overlay only).

Closes #2243

@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:low Low priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific labels Oct 8, 2026
@inureyes

inureyes commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

make verify-rocm-held on gfx1151 at the rebased head passed (exit 0), including the fast script gates, overlay check, clippy with -D warnings, the test suites and the ROCm smoke run. Metal and CUDA were not run (not available on this host).

@inureyes inureyes added the status:done Completed label Oct 8, 2026
hipblaslt_gemm_ptrs, hipblaslt_gemm_rowmajor_on_stream and rocblas_gemm_ptrs heap-allocated a never-freed float pair for any scale other than (1, 0) and (1, 1), leaking 8 bytes per call. The justification (the library keeps host pointers past enqueue) does not hold: no pointer mode is set, so the scalars are read during the library call, and launch_kernel runs its functor synchronously. The wrappers now pass the addresses of the lambda's by-value captures (the function parameters in the on-stream variant), as the epilogue and batched paths already did. The use_hip_graphs() comment notes the assumption. Recorded as LOCAL_FIXES 43.

Verified on gfx1151: rocm_hipblaslt_concurrency, rocm_rocblas_handle_concurrency and rocm_gather_qmm_expert_batched pass; verify-rocm-overlay passes. No Rust-reachable path calls these wrappers with another scale, so there is no behavior test for it.

Closes #2243
@inureyes
inureyes force-pushed the fix/issue-2243-gemm-alpha-beta-leak branch from b54ae04 to 9eb02c9 Compare October 8, 2026 23:26
@inureyes
inureyes merged commit 25baebc into main Oct 9, 2026
26 of 27 checks passed
@inureyes
inureyes deleted the fix/issue-2243-gemm-alpha-beta-leak branch October 9, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers platform:linux Linux (CUDA / packaging) specific priority:low Low priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(rocm): stop leaking alpha/beta pairs in the GEMM pointer wrappers

1 participant