Skip to content

fix(tensilelite): key the solution cache on every field its predicates read - #12861

Merged
jaopaulolc merged 10 commits into
developfrom
users/jolabega/fix-tensilelite-caching-library-key
Oct 7, 2026
Merged

jaopaulolc merged 10 commits into
developfrom
users/jolabega/fix-tensilelite-caching-library-key

Conversation

@jaopaulolc

@jaopaulolc jaopaulolc commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

JIRA ID : AIHPBLAS-4984

Motivation

hipBLASLt asks TensileLite for the GPU kernels, called solutions, that suit each matrix multiplication (GEMM). TensileLite's CachingLibrary caches the answer at the root of the loaded library, keyed on the problem, but the key leaves out fields that per-solution checks read. On gfx950, a bf16-bias heuristic query of an f16 GEMM finds no solutions, but after an f16-bias query of the same shape it gets the cached f16-bias ones. hipblasLtMatmul with one returns success and writes D without the bias.

Technical Details

hipblasLtMatmulAlgoGetHeuristic reaches CachingLibrary::findTopSolutions through getBestSolutions and MasterSolutionLibrary::findTopSolutions. A cache hit skips each solution's BiasDataTypeWhiteList check, and hipblasLtMatmul runs a solution by index without it. Bias type does not split libraries; it is checked per solution, below the cache. The GemmInstance and grouped GEMM heuristics share the cache; getAllAlgos and matmulIsAlgoSupported do not.

Host code only. Comparison and std::hash for ContractionProblemGemm also cover these fields, each with the check that reads it and the number of the 314 shipped gfx950 library files that use it:

  • bias type: BiasDataTypeWhiteList, 311;
  • activation enum: ActivationEnumWhiteList, 266;
  • whether beta is 0: BufferLoadOffsetLimitCheck_Beta, 311;
  • amaxD type, which hipBLASLt sets to the compute type: WorkspaceCheck, 304;
  • GSU (global split-U): AmaxDCheck, 311, and WorkspaceCheck;
  • fallback status: WorkgroupMappingXCCCheck, 311.

Other fields that checks read stay out of the key. hipBLASLt never sets sparsity, the gate-residual type or factorDim. It derives bias length, biasEnum and device user arguments from D's sizes, the epilogue and grouped_gemm, which the key already covers. No shipped library checks the alpha and beta restrictions, C == D, the grouped GEMM count or persistent-kernel eligibility.

The new fields go in a second compare and hash call to keep hits fast. The grouped GEMM hash now reuses the per-problem hash.

Test Plan

Run hipblaslt-test --gtest_filter='CachingLibraryCollision.*'. smoke_Bf16BiasHeuristicIsNotServedF16BiasSolutions runs the f16-then-bf16 queries through the public API. Every bf16 result must pass matmulIsAlgoSupported and give D equal to the bias. Five smoke_*PartOfKey tests check that a problem a real predicate rejects is not served a solution cached for one it accepts. Two tests check that equal keys still hit: identical problems, and beta 0.5, 2.0 and 1.0.

Test Result

On an MI355X (gfx950) with a TheRock gfx950 device library, the bf16 query on develop returned 4 solutions. matmulIsAlgoSupported rejected all 4, and each left every element of D wrong. Here it returns none. The public-API test and the 5 smoke_*PartOfKey tests fail on develop; all 12 suite tests pass here. Median heuristic latency over 3 rounds, small library: warm 1.70–1.71 µs before, 1.71–1.72 µs after; cold about 94–99 µs both. Automated GitHub checks are pending.

Submission Checklist

Risk level

Low (2/5): only cache lookups change. Problems differing in a predicate-read field get separate entries, so results match an uncached search.

…s read

CachingLibrary answers repeated solution queries from a cache keyed on
ContractionProblemGemm, but the key left out fields that solution
predicates and the workspace check read. A problem that differed only in
one of them was served the solutions cached for another. After an f16-bias
heuristic query, a bf16-bias query of the same shape returned the f16
kernels, and hipblasLtMatmul with one of them wrote 0 instead of the bias.

Compare and hash the bias data type, bias enum, factorDim, gate-residual
type, activation enum, compute type, amaxD type, C == D, beta, alpha and
beta restrictions, sparsity, device user arguments, GSU, fallback status,
persistent-kernel eligibility and grouped GEMM count, and also compare the
bias sizes. The new fields go in a second compare and hash call, which
keeps cache hits fast. The grouped GEMM hash now reuses the per-problem
hash instead of its own shorter field list.

The new CachingLibraryCollision cases cache a solution for a problem that
a real predicate accepts and check that a problem it rejects is not
served from the cache.
@therock-pr-bot

therock-pr-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@jaopaulolc
jaopaulolc marked this pull request as ready for review October 1, 2026 17:58
@jaopaulolc
jaopaulolc requested a review from a team as a code owner October 1, 2026 17:58
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12861      +/-   ##
===========================================
- Coverage    71.93%   70.92%   -1.01%     
===========================================
  Files         2863     2946      +83     
  Lines       472701   485740   +13039     
  Branches     69827    70150     +323     
===========================================
+ Hits        340000   344476    +4476     
- Misses      109118   117306    +8188     
- Partials     23583    23958     +375     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 49.33% <ø> (ø)
TensileLite-Unit 83.28% <ø> (ø)
hipBLAS 90.62% <ø> (ø) Carriedforward from 71665f6
hipBLASLt 38.92% <ø> (+<0.01%) ⬆️
hipCUB 82.68% <ø> (ø) Carriedforward from 71665f6
hipDNN 86.64% <ø> (+0.01%) ⬆️ Carriedforward from 71665f6
hipFFT 54.32% <ø> (+10.89%) ⬆️ Carriedforward from 71665f6
hipRAND 76.12% <ø> (ø) Carriedforward from 71665f6
hipSOLVER 68.96% <ø> (ø) Carriedforward from 71665f6
hipSPARSE 86.99% <ø> (ø) Carriedforward from 71665f6
rocBLAS 48.24% <ø> (-0.01%) ⬇️ Carriedforward from 71665f6
rocFFT 47.11% <ø> (-0.51%) ⬇️ Carriedforward from 71665f6
rocRAND 57.42% <ø> (-0.03%) ⬇️ Carriedforward from 71665f6
rocSOLVER 76.83% <ø> (+<0.01%) ⬆️ Carriedforward from 71665f6
rocSPARSE 74.75% <ø> (+0.12%) ⬆️ Carriedforward from 71665f6
rocThrust 78.45% <ø> (-14.70%) ⬇️ Carriedforward from 71665f6

*This pull request uses carry forward flags. Click here to find out more.
see 173 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jaopaulolc jaopaulolc added the rocm:gemm algos Label to identify PRs of the GEMM Algorithms team. label Oct 2, 2026
…public API

Every f16 GEMM is looked up through the one CachingLibrary at the root of
the master library, and BiasDataTypeWhiteList is a solution predicate below
that cache. On develop, after an f16-bias heuristic query, a bf16-bias query
of the same shape returns the cached f16-bias solutions. No shipped f16 GEMM
kernel reads a bf16 bias, so matmulIsAlgoSupported rejects them and
hipblasLtMatmul with one writes D without the bias.

The new case runs the two queries through hipblasLtMatmulAlgoGetHeuristic
and checks every bf16-bias result with matmulIsAlgoSupported and with a
GEMM whose D must equal the bias.
The solution predicates read beta only as beta == 0 (BetaZero, and
BufferLoadOffsetLimitCheck_Beta in 311 of 314 shipped gfx950 library
files) and beta == 1 (BetaOne). Keying the raw value gave every other
beta its own cache entry, so the key now holds that category instead.
betaRestriction does not cover beta == 1: for complex types hipBLASLt
stores |beta| in beta() but derives the restriction from the complex
value.

Compute type is read only by isGemmTypeSame in the GEMM_TYPE_ONLY search
of findAllSolutions, which bypasses the cache, so it leaves the key.

The beta test now holds the restriction fixed and separates 0, 1 and
other values. A new test checks that beta 0.5 and 2.0 share one entry.
A field stays in the cache key only if a predicate in the shipped gfx950
libraries reads it and hipBLASLt can set it apart from the rest of the key.

- Beta is keyed as beta == 0, which BufferLoadOffsetLimitCheck_Beta reads
  in 311 of 314 library files. BetaZero and BetaOne ship in none.
- The alpha and beta restrictions, C == D, the grouped GEMM count and
  persistent-kernel eligibility are dropped: AlphaValue, BetaValue,
  CEqualsD, SynchronizerSizeCheck and PersistentKernelCheck ship in none.
- Sparsity, the gate-residual type and factorDim are dropped because
  hipBLASLt never sets them. Bias length, biasEnum and device user
  arguments are dropped because hipBLASLt derives them from D's sizes,
  the epilogue and grouped_gemm.
- The amaxD type stays. hipBLASLt sets it to the compute type, so it also
  keys computeTypeElementSize(), which WorkspaceCheck reads.

The synthetic tests for dropped fields are removed. The beta tests now
check that zero and non-zero beta are kept apart and that 0.5, 2.0 and
1.0 share one entry.
@jaopaulolc
jaopaulolc enabled auto-merge (squash) October 5, 2026 21:52
@jaopaulolc
jaopaulolc merged commit e5f9b5c into develop Oct 7, 2026
238 of 249 checks passed
@jaopaulolc
jaopaulolc deleted the users/jolabega/fix-tensilelite-caching-library-key branch October 7, 2026 21:44
@assistant-librarian

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants