opt(gemm): add hipBLASLt algorithm cache and thread-local workspace#321
opt(gemm): add hipBLASLt algorithm cache and thread-local workspace#321jasainio wants to merge 2 commits into
Conversation
|
Need to check if this feat is required once #277 is merged |
c7f6c13 to
b58a4cc
Compare
RuibinCheung
left a comment
There was a problem hiding this comment.
Generally LGTM. Could you share the performance improvement of hipblaslt gemm after applying this PR ?
There was a problem hiding this comment.
Could you create a new directory named hipblaslt in kernels/gemm and put this header file into this directory?
b58a4cc to
ea65b3e
Compare
ea65b3e to
9737552
Compare
|
Verified end-to-end as part of the integration branch |
Cache hipblasLtMatmulAlgo_t across repeat GEMM calls to skip expensive heuristic lookups on recurring shapes. Pre-allocate workspace via a thread-local tensor to avoid per-call CUDA malloc overhead. Changes: - Add hipblaslt_algo_cache.h with FNV-1a hashed lookup by GEMM config - Integrate cache into hipblaslt_gemm_impl (store on miss, reuse on hit) - Replace per-call at::empty workspace with thread-local pre-allocation - Add unit tests for bit-exactness, multi-shape, and layout correctness - Add benchmark script for cold-cache vs warm-cache latency comparison
- Move hipblaslt_algo_cache.h into csrc/kernels/gemm/hipblaslt/ subdir - Add kMaxEntries=256 cap with cache_.clear() on overflow to prevent unbounded growth under dynamic-shape workloads (e.g. MoE) - Add hipblaslt_algo_cache_clear() binding for test isolation - Add TestAlgoCacheOverflow test (300 unique shapes) - Add single-stream-per-thread safety comment on thread-local workspace
9737552 to
0bee432
Compare
|
Thanks @RuibinCheung. Addressed both comments: 1. Directory restructure: Done. Moved 2. Performance numbers (MI355X, FP8 GEMM, hipBLASLt backend): The cache eliminates
The benefit is most visible on shapes where the heuristic lookup is a meaningful fraction of total dispatch time (small/medium GEMMs: 100-470 us saved per call). For large compute-bound GEMMs, the kernel runtime dominates and warm/cold are nearly identical. Note: The very first hipBLASLt call for a new dimension-class incurs a one-shot ~1.5s penalty (internal solution library load from disk). This happens once per process regardless of caching. The cache eliminates the heuristic overhead on all subsequent calls for recurring shapes. The thread-local workspace eliminates a 64-128 MiB Additional improvements in this push:
Reproduce: |
Cache
hipblasLtMatmulAlgo_tacross repeat GEMM calls to skip expensive heuristic lookups on recurring shapes. Pre-allocate workspace via a thread-local tensor to avoid per-call CUDA malloc overhead.Changes:
hipblaslt_algo_cache.hwith FNV-1a hashed lookup by GEMM confighipblaslt_gemm_impl(store on miss, reuse on hit)at::emptyworkspace with thread-local pre-allocationDescription
Cache
hipblasLtMatmulAlgo_tresults across repeated GEMM calls so that expensive hipBLASLt heuristic lookups are only performed once per unique shape/config. On subsequent calls with the same GEMM configuration, the cached algorithm is reused directly. Additionally, the per-call workspace allocation (at::empty) is replaced with a thread-local pre-allocated tensor, eliminating repeated CUDA malloc/free overhead on every GEMM invocation.Type of change
Changes
Please list the changes introduced in this PR:
csrc/kernels/gemm/hipblaslt_algo_cache.himplementing a thread-safe algorithm cache with FNV-1a hashing keyed on GEMM config (M, N, K, dtypes, layouts, compute type)csrc/kernels/gemm/hipblaslt_gemm.cuandcsrc/pytorch/gemm/hipblaslt_gemm.cpp-- store algorithm on cache miss, reuse on hitat::emptyworkspace allocation with a thread-local pre-allocated tensor that grows as neededtests/pytorch/ops/test_algo_cache.pywith tests for bit-exact repeatability, multi-shape correctness (no key collisions), BF16 support, and NT/NN layout handlingbenchmark/ops/bench_algo_cache.pyfor measuring cold-cache vs warm-cache GEMM latency across model configurationsChecklist: