Add promote_storage_type pass to compute storage-only types in float - #5138
Open
pfultz2 wants to merge 11 commits into
Open
Add promote_storage_type pass to compute storage-only types in float#5138pfultz2 wants to merge 11 commits into
pfultz2 wants to merge 11 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves GPU performance for storage-only data types (notably bf16) by introducing a compiler pass that promotes eligible computations to run in float, reducing repeated implicit bf16↔float conversions and preserving narrow storage where appropriate during constant folding.
Changes:
- Added
promote_storage_typepass to insert storage→float→storage conversions around pointwise/reduction computations and then cancel adjacent convert pairs viaeliminate_convert. - Refactored truncation/quantization type-rewrite logic into a reusable
replace_data_type(...)helper template and rewiredtruncate_float_passto use it. - Updated constant propagation to avoid folding widening
convertops (to preserve narrow storage literals), and added/updated unit tests to match the new semantics.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/quantization.cpp | Updates literal_add expectations to reflect fp32 const-folding behavior before truncation/quantization. |
| test/propagate_constant_test.cpp | Adds regression coverage for skipping widening convert folding and still folding narrowing converts. |
| test/promote_storage_type_test.cpp | Adds unit tests for the new promote_storage_type pass (pointwise, reduce, adjacency, idempotency, where-condition handling). |
| src/truncate_float.cpp | Replaces the local quantization rewrite helper with the new shared replace_data_type(...) utility. |
| src/propagate_constant.cpp | Prevents constant folding of widening convert to keep narrow storage literals and avoid literal size/type expansion. |
| src/promote_storage_type.cpp | Implements the promote_storage_type module pass and runs eliminate_convert to remove redundant convert pairs. |
| src/include/migraphx/replace_data_type.hpp | Introduces the shared type-rewrite helper template used by both truncation and promotion. |
| src/include/migraphx/promote_storage_type.hpp | Declares the new promote_storage_type pass API. |
| src/CMakeLists.txt | Adds promote_storage_type.cpp to the core library build. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5138 +/- ##
========================================
Coverage 93.13% 93.13%
========================================
Files 625 628 +3
Lines 33252 33270 +18
========================================
+ Hits 30967 30985 +18
Misses 2285 2285
🚀 New features to boost your workflow:
|
pfultz2
requested review from
CharlieL7,
TedThemistokleous,
bdevorem and
kahmed10
August 17, 2026 18:49
TedThemistokleous
approved these changes
Aug 19, 2026
Collaborator
|
Add a changelog entry for this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
On the GPU, bf16 does not support any VALU computations. It only supports matrix ops. So the compiler does an implicit conversion to float and then back to bf16 every time making it much slower. This adds a pass to do this directly in the graph, so we dont generate all these intermediate conversions.
Constant propagation also needs to cooperate: folding a widening convert
would materialize the literal in the wider type, enlarging it and losing the
narrow storage type, so those converts must stay as runtime conversions.
Technical Details
promote_storage_typepass that takes a list of storage-only types.For every pointwise or reduction instruction of such a type (detected via
the
pointwise/reduceattributes, excludingconvert,bit_cast,layout, andidentity, which carry the pointwise attribute but perform nocomputation), it converts the storage-typed inputs to float and converts the
result back to the storage type. It then runs
eliminate_convert, whichcancels the storage/float convert pairs between adjacent promoted
instructions, leaving the intermediate values in float.
quantize_modulefromtruncate_float.cppinto a reusablereplace_data_type(module, src_types, target_type, predicate)template ininclude/migraphx/replace_data_type.hpp. Bothtruncate_float_passandpromote_storage_typeare now thin wrappers over it, so the tuple-outputand module-input handling is shared instead of duplicated.
propagate_constantto skip folding converts to a wider type(mirroring the existing
dequantizelinearhandling), keeping literals inthe narrow storage type with a runtime conversion. Narrowing converts still
fold.
pointwise+reduce with no intermediate converts,
wherekeeping its boolcondition, unlisted types unchanged, idempotency) and for the
propagate_constantchange (widening convert of a broadcast literal iskept, narrowing convert still folds). The
literal_addquantization test isupdated for the new semantics:
quantize_fp16with{"add"}const-foldsthe add in fp32 before truncation, so nothing remains to quantize and the
folded literal stays float, while the hand-built half program now keeps its
half literal with a runtime widening convert.
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.