-
Notifications
You must be signed in to change notification settings - Fork 296
[Tensilelite] Add MXFP4 data generator for Tensile #4597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
archana-ramalingam
merged 11 commits into
gfx950_mx_rebase
from
users/aramalin/mxfp4_tensile
Feb 21, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ac72da7
Add mxdatagenerator
archana-ramalingam afd351a
Fix mxDataGenerator subdirectory conflict
archana-ramalingam d6e9e16
Numerically passing mxfp4
archana-ramalingam e53da42
Remove reliance on HIPBLASLT_USE_ROCROLLER
archana-ramalingam a6006d5
Fix path
archana-ramalingam a07f9ea
Add mxDataGenerator test
archana-ramalingam f328ff3
Merge branch 'gfx950_mx_rebase' into users/aramalin/mxfp4_tensile
archana-ramalingam 5e6ef4a
Address reviews
archana-ramalingam 2ca1d54
Merge branch 'users/aramalin/mxfp4_tensile' of https://github.com/ROC…
archana-ramalingam 94560b7
Update baseline and range of zero frequency in test comments
archana-ramalingam 379d0ee
Update comment
archana-ramalingam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
107 changes: 107 additions & 0 deletions
107
projects/hipblaslt/tensilelite/tests/MXDataGen_test.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Copyright Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <mxDataGen.hpp> | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| /** | ||
| * @brief Unpack two FP4 nibbles from a packed byte. | ||
| * | ||
| * FP4 E2M1 values are packed two-per-byte (low nibble first). | ||
| * Zero is represented by nibble value 0x0 (+0) or 0x8 (-0). | ||
| */ | ||
| static bool isZeroNibble(uint8_t nibble) | ||
| { | ||
| // FP4 E2M1: 0x0 = +0.0, 0x8 = -0.0 | ||
| return (nibble == 0x0) || (nibble == 0x8); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Count elements that decode to zero in a packed FP4 buffer. | ||
| */ | ||
| static size_t countZerosFP4(const uint8_t* packedData, size_t numPackedBytes) | ||
| { | ||
| size_t zeros = 0; | ||
| for(size_t i = 0; i < numPackedBytes; ++i) | ||
| { | ||
| uint8_t lo = packedData[i] & 0x0F; | ||
| uint8_t hi = (packedData[i] >> 4) & 0x0F; | ||
| if(isZeroNibble(lo)) | ||
| ++zeros; | ||
| if(isZeroNibble(hi)) | ||
| ++zeros; | ||
| } | ||
| return zeros; | ||
| } | ||
|
|
||
| class MXDataGenFP4Test : public ::testing::TestWithParam<std::tuple<uint64_t, uint64_t, int, bool>> | ||
| { | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Verify that generateMXInput produces FP4 data with an acceptable zero frequency. | ||
| * | ||
| * FP4 E2M1 has 16 nibble values, 2 of which are zero (0x0 = +0, 0x8 = -0), giving a | ||
| * naive baseline of 2/16 = 12.5%. MX block scaling slightly elevates this: the block | ||
| * maximum is guaranteed non-zero, pushing small elements toward zero. Empirically the | ||
| * zero frequency converges to ~12.89% for large matrices with bounded [-1, 1] input. | ||
| */ | ||
| TEST_P(MXDataGenFP4Test, ZeroFrequencyWithinBounds) | ||
| { | ||
| auto [rows, cols, mxBlock, isTranspose] = GetParam(); | ||
|
|
||
| const uint64_t numElements = rows * cols; | ||
| const uint64_t numPacked = (numElements + 1) / 2; | ||
| const size_t numScales = ((rows + mxBlock - 1) / mxBlock) * cols; | ||
|
|
||
| std::vector<uint8_t> dataBuffer(numPacked, 0); | ||
| std::vector<uint8_t> scaleBuffer(numScales, 0); | ||
|
|
||
| std::vector<size_t> emptySwizzle; | ||
| std::vector<size_t> emptyTile; | ||
|
|
||
| generateMXInput((hipDataType)HIP_R_4F_E2M1_EXT, | ||
| dataBuffer.data(), | ||
| scaleBuffer.data(), | ||
| rows, | ||
| cols, | ||
| rows, // stride = rows (column-major) | ||
| isTranspose, | ||
| emptySwizzle, | ||
| emptyTile, | ||
| mxBlock, | ||
| 1, | ||
| true, | ||
| "Bounded", | ||
| -1.0f, | ||
| 1.0f); | ||
|
|
||
| size_t zeros = countZerosFP4(dataBuffer.data(), numPacked); | ||
| double zeroPercent = 100.0 * static_cast<double>(zeros) / static_cast<double>(numElements); | ||
|
|
||
| // Empirically ~12.5–12.9% zeros; naive baseline is 2/16 = 12.5% (2 zero values | ||
| // out of 16 FP4 nibble values), slightly elevated by MX block scaling bias. | ||
| EXPECT_LT(zeroPercent, 13.0) | ||
| << "Zero frequency " << zeroPercent << "% exceeds 13% upper bound for " | ||
| << rows << "x" << cols << " FP4 matrix (transpose=" << isTranspose << ")"; | ||
|
|
||
| // Ensure non-trivial data was actually generated (not all zeros) | ||
| EXPECT_GT(numElements - zeros, 0u) | ||
| << "All elements are zero for " << rows << "x" << cols << " FP4 matrix"; | ||
| } | ||
|
|
||
| INSTANTIATE_TEST_SUITE_P( | ||
| FP4ZeroFrequency, | ||
| MXDataGenFP4Test, | ||
| ::testing::Values( | ||
| // rows, cols, mxBlock, isTranspose | ||
| std::make_tuple(128u, 128u, 32, true), | ||
| std::make_tuple(256u, 256u, 32, true), | ||
| std::make_tuple(2048u, 1026u, 32, true), | ||
| std::make_tuple(2048u, 514u, 32, false) | ||
| ) | ||
| ); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.