Skip to content

fix(tensilelite): share one Debug instance across the tensilelite-host boundary - #12784

Merged
davidd-amd merged 6 commits into
developfrom
users/davidd-amd/tensilelite-shared-symbols
Oct 14, 2026
Merged

davidd-amd merged 6 commits into
developfrom
users/davidd-amd/tensilelite-shared-symbols

Conversation

@davidd-amd

@davidd-amd davidd-amd commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

JIRA ID : ROCM-31245 (also AIRADSW-923)

Motivation

Splitting hipBLASLt into libhipblaslt.so and shared libtensilelite-host.so created two process-local copies of TensileLite::Debug. rocblaslt_auxiliary.cpp wrote the {GridBasedMatching, PredictionMatching} exclusion set into the hipBLASLt copy, while ExactLogicLibrary::findAllSolutions() read the empty host-library copy and traversed the ranking libraries on every call.

This raised hipblasLtMatmulAlgoGetHeuristic host time on small GEMMs from roughly 0.03–0.07 ms to about 5 ms. The effect is most visible on gfx1200/gfx1201 shapes that reach the getAllSolutions() fallback.

This PR carries the symbol-related correction from #11946 and #12465. The unrelated StreamK work from #11946 remains separate.

Technical Details

One Debug instance across both shared libraries

Debug inherited Instance() from the header-only LazySingleton template. With hidden symbol and inline visibility, each shared object owned a separate function-local static.

  • Debug::Instance() is now declared on the exported Debug class and defined once in Debug.cpp.
  • Debug no longer derives from LazySingleton, so no inline accessor can create another private instance.
  • LazySingleton remains unchanged. This avoids exporting a template member that would impose dllimport requirements on consumer-only specializations such as LazySingleton<TestData>.

Complete the installed shared-library interface

The hipBLASLt development package installs roc::tensilelite-host as a shared imported CMake target and publishes the TensileLite headers as tensilelite_public_headers. A consumer compiling inline or template code from those headers must be able to resolve its out-of-line calls from libtensilelite-host.so.

This PR exports:

  • the complete ScalarValueTypeInfo::Get and KernelLanguageTypeInfo::Get overload families, matching the existing exported DataTypeInfo metadata interface;
  • MLFeatures::tilesPerCU and the stream operators for its public scale-factor types;
  • MLPClassification::DenseLayer::DenseLayer, MLPNet::predict, and MLPNet::valid.

Six of these functions are called directly by inline/template code in shipped headers. The remaining overloads and stream operators preserve the established complete-overload and exported-value-type patterns. These are package-interface exports, not test-only hooks.

In YAML builds, tensilelite-tests also links LLVMObjectYAML directly. tensilelite-host links that dependency privately with --exclude-libs,ALL, so the test executable cannot rely on the host library to re-export LLVM symbols.

Check the binary relationship without test-only production code

For shared non-Windows test builds, hipblaslt.symbol-contract.tensilelite-host runs llvm-ifs over both libraries. It verifies that:

  • libhipblaslt.so imports every symbol listed in library/symbol-contract/tensilelite-host-imports.txt, beginning with TensileLite::Debug::Instance();
  • libtensilelite-host.so exports those required imports;
  • every TensileLite symbol imported by libhipblaslt.so is exported by its provider.

The check adds no test-only function to the production library.

Test Plan

  1. Run the symbol-contract check against a pre-change TheRock artifact pair and confirm that it rejects the duplicated inline singleton.
  2. Build shared tensilelite-tests with YAML serialization to exercise the installed-header exports and direct LLVM YAML dependency.
  3. Build shared libhipblaslt.so with the normal msgpack serialization path and run the symbol-contract test.
  4. Let the refreshed automated GitHub checks cover the shared CI lanes after merging current develop.

Test Result

  • Pre-change control: hipblaslt_check_symbol_contract.cmake failed against TheRock run 37969613509. libhipblaslt.so.1.5 did not import Debug::Instance(), and libtensilelite-host.so.1.0 did not export it.
  • Merged head 64d7532a: shared YAML tensilelite-tests built successfully for gfx950 in a host-only configuration.
  • Merged head 64d7532a: shared msgpack libhipblaslt.so built successfully; hipblaslt.symbol-contract.tensilelite-host passed 1/1.
  • Artifact audit: the scanned rocBLAS and MIOpen libraries consume hipBLASLt APIs but do not directly import the added TensileLite type/ML/MLP symbols. Their justification is the installed roc::tensilelite-host header interface.
  • Automated GitHub checks restarted after the develop merge and are pending.

Exploratory result: combining HIPBLASLT_ENABLE_HOST=ON with HIPBLASLT_ENABLE_YAML=ON made the broad namespace check report three pre-existing msgpack imports that a YAML host library does not export (Serialization::objectToMap, fileToMsgObject, and LoadLibraryMapping). The supported msgpack contract above passes; this mixed serialization configuration is not counted as passing evidence for this PR.

Not covered locally:

Follow-ups

  • Restoring one process-wide Debug object also restores the previous shared mutable exclusion set. The two heuristic entry points use different mutexes, and the get-all path takes none. A later design should pass exclusions per call through findAllSolutions or SolutionLibrarySearchType.
  • EmbeddedData and EmbeddedLibrary retain the same latent header-only singleton shape, but no cross-library writer/reader pair has been identified.

Submission Checklist

Risk level

Low (2/5). The runtime change moves one singleton accessor to a single exported definition. The additional exports complete an already-installed C++ target and are additive; no kernel, device-library, or dispatch algorithm changes. Windows validation and refreshed automated checks remain pending.

…t boundary

JIRA ID : ROCM-31245

Debug inherited Instance() from LazySingleton, an inline member of a
header-only template. With CXX_VISIBILITY_PRESET hidden and
VISIBILITY_INLINES_HIDDEN, a shared libtensilelite-host and libhipblaslt
each got a private copy of the function-local static. libhipblaslt wrote
the {GridBasedMatching, PredictionMatching} exclusion set into its copy
before getAllSolutions(); ExactLogicLibrary::findAllSolutions() read the
other, empty copy and traversed the ranking libraries on every call. That
is the 100x-200x host-side slowdown in hipblasLtMatmulAlgoGetHeuristic for
small GEMMs.

Define Debug::Instance() out of line in Debug.cpp so the single exported
definition owns the only instance, and drop the LazySingleton base so no
inline accessor remains that could reintroduce a second copy. The
LazySingleton template is unchanged, which avoids exporting a template
member (a dllimport hazard for consumer-only specializations on Windows).

Also make tensilelite-tests link as a shared build: export the
ScalarValueTypeInfo / KernelLanguageTypeInfo Get() overloads and the
MLFeatures / MLPClassification entry points the tests call, and link
LLVMObjectYAML into the tests in YAML builds.

SingletonIdentity_test checks instance identity and state propagation
across the library boundary through a test-only probe that is not in the
installed headers, and skips when tensilelite-host is static.

Co-authored-by: Cursor <cursoragent@cursor.com>
@therock-pr-bot

therock-pr-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/hipblaslt/tensilelite/include/Tensile/Debug.hpp, projects/hipblaslt/tensilelite/include/Tensile/KernelLanguageTypes.hpp, projects/hipblaslt/tensilelite/include/Tensile/MLFeatures.hpp, projects/hipblaslt/tensilelite/include/Tensile/MLPClassification.hpp, projects/hipblaslt/tensilelite/include/Tensile/ScalarValueTypes.hpp (+1 more); no test file found
🔎 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

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

❌ Your project status has failed because the head coverage (49.68%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12784      +/-   ##
===========================================
- Coverage    72.37%   71.02%   -1.36%     
===========================================
  Files         2879     2953      +74     
  Lines       478194   488371   +10177     
  Branches     70867    70671     -196     
===========================================
+ Hits        346082   346828     +746     
- Misses      108166   117472    +9306     
- Partials     23946    24071     +125     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 49.68% <ø> (-0.02%) ⬇️
TensileLite-Unit 83.55% <ø> (+0.01%) ⬆️
hipBLAS 90.62% <ø> (ø) Carriedforward from 64d7532
hipBLASLt 43.30% <ø> (+0.57%) ⬆️
hipCUB 82.68% <ø> (ø) Carriedforward from 64d7532
hipDNN 86.69% <ø> (-0.11%) ⬇️ Carriedforward from 64d7532
hipFFT 54.32% <ø> (+12.20%) ⬆️ Carriedforward from 64d7532
hipRAND 76.12% <ø> (ø) Carriedforward from 64d7532
hipSOLVER 68.96% <ø> (ø) Carriedforward from 64d7532
hipSPARSE 86.99% <ø> (ø) Carriedforward from 64d7532
rocBLAS 48.25% <ø> (+0.04%) ⬆️ Carriedforward from 64d7532
rocFFT 47.11% <ø> (-0.14%) ⬇️ Carriedforward from 64d7532
rocRAND 57.42% <ø> (-0.17%) ⬇️ Carriedforward from 64d7532
rocSOLVER 76.83% <ø> (+<0.01%) ⬆️ Carriedforward from 64d7532
rocSPARSE 74.75% <ø> (-1.87%) ⬇️ Carriedforward from 64d7532
rocThrust 78.34% <ø> (-14.81%) ⬇️ Carriedforward from 64d7532

*This pull request uses carry forward flags. Click here to find out more.
see 360 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.

Co-authored-by: Cursor <cursoragent@cursor.com>
davidd-amd and others added 3 commits October 1, 2026 01:55
…tract check

Drop debugInstanceAddress() and SingletonIdentity_test.cpp so no
test-only code is built into libtensilelite-host.

Add hipblaslt.symbol-contract.tensilelite-host, a CTest test for shared,
non-Windows builds. It runs llvm-ifs on libhipblaslt and
libtensilelite-host and fails if libhipblaslt does not import, or
libtensilelite-host does not export, every symbol listed in
library/symbol-contract/tensilelite-host-imports.txt, or if any
TensileLite symbol libhipblaslt imports is not exported by
libtensilelite-host. The list starts with TensileLite::Debug::Instance();
with a duplicated Debug that import disappears and the check fails.

Co-authored-by: Cursor <cursoragent@cursor.com>
@davidd-amd
davidd-amd enabled auto-merge (squash) October 13, 2026 18:57
@talumbau

Copy link
Copy Markdown
Collaborator

precheckin(hipblaslt) is not reporting back to the Github UI that it is done and passed. Screenshots from math-ci:

image image

@talumbau talumbau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is good, but a final review shows that you are missing the file projects/hipblaslt/cmake/hipblaslt_check_symbol_contract.cmake which is added in the changes to projects/hipblaslt/CMakeLists.txt. Please add that file to the repo - thanks!

@talumbau talumbau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - approved!

@davidd-amd
davidd-amd merged commit 091eb4d into develop Oct 14, 2026
291 of 300 checks passed
@davidd-amd
davidd-amd deleted the users/davidd-amd/tensilelite-shared-symbols branch October 14, 2026 03:20
@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.

3 participants