From 3630156b1a300c29442e561a82a60868c1daed11 Mon Sep 17 00:00:00 2001 From: Tony Davis Date: Thu, 17 Sep 2026 22:47:55 +0000 Subject: [PATCH 1/2] fix(tensilelite): stop offering solutions whose output stores are dropped A kernel that writes its output matrix D with buffer stores addresses it through a buffer resource descriptor. That descriptor's num_records field is 32 bits wide and bounds every store: the hardware discards a store at or past it and raises no fault. allocPostLoopSrd in KernelWriterAssembly.py sets that field to the BufferOOB sentinel, 0xfffff000. BufferStoreOffsetLimitCheck is the host-side check that keeps solution selection away from shapes a kernel cannot write in full, but it compared the required extent against 2^32 instead. Any shape whose extent landed between 0xfffff000 and 2^32 was reported as supported and then only partly written, with hipblasLtMatmul returning success. Measured on an MI350X against the ROCm 7.13 library at M = 8,388,607, N = 256, K = 48 in bfloat16: 22 of the 64 algorithms the heuristic offered returned success while leaving part of D unwritten. Every one of them had MacroTile1 = 256, which for this shape makes a workgroup's store extent span the whole tensor. The unwritten elements were the trailing partial tile of each solution's own MacroTile0, matching the pattern reported in ROCm/hipBLASLt#2299. Compare against the sentinel the generator emits, and name the constant so the two can be seen to agree. With the same build and only this threshold changed, the reproducing shape goes from 22 broken of 64 to 0, while a control one step below the sentinel keeps all 1629 of its candidates. The hand-written kernels under Tensile/CustomKernels still set BufferOOB to 0x80000000, so this single global threshold remains too permissive for them. That is recorded in the comment and tracked as ROCM-31258. debugEval printed strides()[1] * value, skipping the min() against N that operator() applies, so it could report a larger extent than the one that decided the result. It now prints the value actually compared. ROCM-31016 Co-authored-by: Cursor --- .../Tensile/ContractionProblemPredicates.hpp | 38 ++++- .../tensilelite/tests/Predicates_test.cpp | 132 ++++++++++++++++++ 2 files changed, 164 insertions(+), 6 deletions(-) diff --git a/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp b/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp index bf638f5c6c00..00baf2c03219 100755 --- a/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp +++ b/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp @@ -1555,12 +1555,35 @@ namespace TensileLite return "BufferStoreOffsetLimitCheck"; } - // The min operator is used to handle cases where size_N is smaller than the value(usually is MacroTile1) + // Each BufferStore=True kernel writes D through a buffer resource + // descriptor whose 32-bit num_records field bounds every store: an + // offset at or past it is discarded by the hardware without raising a + // fault. allocPostLoopSrd in KernelWriterAssembly.py programs that + // field with the BufferOOB sentinel, so this threshold has to be the + // same number the generator emits. When it is larger, this predicate + // reports a shape as supported that the kernel will only partly write. + // + // That agreement only holds for generated kernels. A hand-written + // kernel under Tensile/CustomKernels sets its own BufferOOB and + // nothing checks it against this value, so adding or changing one + // means confirming by hand that its sentinel is at least this large. + // A kernel with a smaller sentinel drops stores this predicate admits. + static constexpr uint64_t BufferOOBBytes = 0xfffff000ull; + + // Each workgroup re-bases the descriptor along N before storing (see + // computeStoreSrdStart), so the extent that has to fit is one + // MacroTile1 of columns rather than all of D. min() covers the case + // where N is smaller than MacroTile1. + static uint64_t storeExtentBytes(ContractionProblemGemm const& problem, size_t value) + { + return multiplyElementSize( + problem.d().strides()[1] * std::min(value, problem.d().sizes()[1]), + problem.d().elementBytes()); + } + virtual bool operator()(ContractionProblemGemm const& problem) const override { - const uint64_t TWO_POW_32 = 4294967296; - return multiplyElementSize(problem.d().strides()[1] * std::min(value, problem.d().sizes()[1]), problem.d().elementBytes()) - < TWO_POW_32; + return storeExtentBytes(problem, value) < BufferOOBBytes; } virtual std::string toString() const override @@ -1573,8 +1596,11 @@ namespace TensileLite { bool rv = (*this)(problem); std::ostringstream details; - details << "D:" << problem.d().strides()[1] << "*" - << problem.d().elementBytes() << "*" << value << "<2^32"; + // Reports the same quantity operator() compares, including the + // min() against N. Reading strides()[1] * value directly would + // print a larger number than the one that decided the result + // whenever N is below MacroTile1. + details << "D:" << storeExtentBytes(problem, value) << "<0xfffff000"; PredicateDebugger::printRow(stream, rv, this->type(), details.str()); return rv; } diff --git a/projects/hipblaslt/tensilelite/tests/Predicates_test.cpp b/projects/hipblaslt/tensilelite/tests/Predicates_test.cpp index e31388ecf4c7..b7e8878e83b2 100644 --- a/projects/hipblaslt/tensilelite/tests/Predicates_test.cpp +++ b/projects/hipblaslt/tensilelite/tests/Predicates_test.cpp @@ -127,3 +127,135 @@ TEST(Predicates, WorkgroupMappingXCCCheck_FallbackTreatsXCCAs1) problem.setParams().setFallbackStatus(true); EXPECT_TRUE((*pred)(problem)) << "With fallback status, effective XCC=1 so 38 % 1 == 0"; } + +// ---------------------------------------------------------------------------- +// BufferStoreOffsetLimitCheck bounds the byte range a kernel's output stores +// can reach, so that solution selection never offers a shape the kernel would +// only partly write. The bound has to be the BufferOOB sentinel that +// KernelWriterAssembly.py programs as the store descriptor's num_records, +// 0xfffff000. A larger bound admits shapes whose stores the hardware discards +// past that offset, without raising a fault. +// +// Regression coverage for ROCM-31016, reported as +// https://github.com/ROCm/hipBLASLt/issues/2299. +// +// The M values below come from hardware rather than from arithmetic. Measured +// on an MI350X (gfx950) at N = 256, K = 48 in bfloat16: at M = 8,388,607, 22 of +// the 64 algorithms the heuristic offered returned success while leaving part +// of D unwritten, and every one of them had MacroTile1 = 256, which for this +// shape makes one workgroup's store extent span the whole tensor. M = 8,388,599 +// is the largest M in the same geometry where all 64 ran clean. +// ---------------------------------------------------------------------------- + +namespace +{ + // Column-major bf16 D of M x N with ldd == M, which is the layout the + // reported defect used. + TensileLite::ContractionProblemGemm bf16ColumnMajorD(size_t m, size_t n, size_t k = 48) + { + using namespace TensileLite; + return ContractionProblemGemm::GEMM_Strides(false, + false, + rocisa::DataType::BFloat16, + rocisa::DataType::BFloat16, + rocisa::DataType::BFloat16, + rocisa::DataType::BFloat16, + m, + n, + k, + /*batchSize=*/1, + /*lda=*/m, + /*aStride=*/-1, + /*ldb=*/k, + /*bStride=*/-1, + /*ldc=*/m, + /*cStride=*/-1, + /*ldd=*/m, + /*dStride=*/-1, + /*beta=*/0.0); + } +} + +TEST(Predicates, BufferStoreOffsetLimitCheck_PastSentinel_Rejected) +{ + using namespace TensileLite; + // The shape that reproduced the defect. Its store extent lands between the + // sentinel the kernel enforces and the 2^32 the predicate used to compare + // against, so only the corrected threshold rejects it. + constexpr size_t m = 8388607; + constexpr size_t n = 256; + constexpr size_t macroTile1 = 256; + static_assert(m * n * 2 > 0xfffff000ull, "must exceed the sentinel the kernel enforces"); + static_assert(m * n * 2 < 4294967296ull, "must stay under the threshold the predicate used"); + + auto pred = std::make_shared(macroTile1); + EXPECT_FALSE((*pred)(bf16ColumnMajorD(m, n))) + << "M=" << m << " N=" << n << " bf16: the store extent is " << (size_t)m * n * 2 + << " bytes, past the 4294963200-byte sentinel, so 22 of 64 offered algorithms left " + "part of D unwritten on gfx950."; +} + +TEST(Predicates, BufferStoreOffsetLimitCheck_BelowSentinel_Accepted) +{ + using namespace TensileLite; + // The largest shape in this geometry that the kernel writes in full, and + // the control the hardware measurement used: all 64 offered algorithms ran + // clean here. Rejecting it would cost solutions for no reason, so this + // holds the accepting side of the boundary one shape away from the test + // above. + constexpr size_t m = 8388599; + constexpr size_t n = 256; + constexpr size_t macroTile1 = 256; + static_assert(m * n * 2 < 0xfffff000ull, "must stay within the sentinel"); + + auto pred = std::make_shared(macroTile1); + EXPECT_TRUE((*pred)(bf16ColumnMajorD(m, n))) + << "M=" << m << " N=" << n << " bf16: extent " << (size_t)m * n * 2 + << " bytes fits within the sentinel and must remain selectable."; +} + +TEST(Predicates, BufferStoreOffsetLimitCheck_ExactlyAtSentinel_RejectedConservatively) +{ + using namespace TensileLite; + // One shape sits exactly on the sentinel: its last store begins at + // extent - 2 and so is still in range, but the comparison is strict and + // rejects it. Losing a single extent value is worth not having to reason + // about how wide the final store of a tile is, which varies with the + // vector width a solution uses. Recorded here so the choice is visible + // rather than looking like an off-by-one. + constexpr size_t n = 256; + constexpr size_t macroTile1 = 256; + constexpr size_t m = 0xfffff000ull / (n * 2); + static_assert(m * n * 2 == 0xfffff000ull, "extent lands exactly on the sentinel"); + + auto pred = std::make_shared(macroTile1); + EXPECT_FALSE((*pred)(bf16ColumnMajorD(m, n))); +} + +TEST(Predicates, BufferStoreOffsetLimitCheck_ReportedShape_Accepted) +{ + using namespace TensileLite; + // The shape in the original report. It was rejected by the hardware on + // ROCm 7.2.x, where the kernel's sentinel was 0x80000000, and runs + // correctly now that the sentinel is 0xfffff000. It must stay selectable: + // rejecting it would turn a fixed case back into a lost solution. + auto pred = std::make_shared(256); + EXPECT_TRUE((*pred)(bf16ColumnMajorD(5326464, 256))); +} + +TEST(Predicates, BufferStoreOffsetLimitCheck_NarrowOutputUsesItsOwnWidth) +{ + using namespace TensileLite; + // A workgroup re-bases along N, so the extent is one MacroTile1 of columns. + // When N is smaller than MacroTile1 the tensor supplies the width, and a + // tall output with only 8 columns stays selectable even though multiplying + // by MacroTile1 would put it past the sentinel. + constexpr size_t n = 8; + constexpr size_t macroTile1 = 256; + constexpr size_t m = 100000000; + static_assert(m * n * 2 < 0xfffff000ull, "the real extent fits"); + static_assert(m * macroTile1 * 2 > 0xfffff000ull, "ignoring min() would not"); + + auto pred = std::make_shared(macroTile1); + EXPECT_TRUE((*pred)(bf16ColumnMajorD(m, n))); +} From 9e67a59a63a0c4da9202056a283326c243cc4d5d Mon Sep 17 00:00:00 2001 From: Tony Davis Date: Fri, 18 Sep 2026 00:48:05 +0000 Subject: [PATCH 2/2] fix(tensilelite): format debugEval's threshold from the constant debugEval printed the buffer-store limit as a literal 0xfffff000 while operator() compared against BufferOOBBytes. The two would disagree the moment the constant changed, and the debug output is what someone reads when they are working out why a solution was rejected. Format the constant into the string instead. ROCM-31016 Co-authored-by: Cursor --- .../include/Tensile/ContractionProblemPredicates.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp b/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp index 00baf2c03219..36c1f7190fa3 100755 --- a/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp +++ b/projects/hipblaslt/tensilelite/include/Tensile/ContractionProblemPredicates.hpp @@ -1600,7 +1600,8 @@ namespace TensileLite // min() against N. Reading strides()[1] * value directly would // print a larger number than the one that decided the result // whenever N is below MacroTile1. - details << "D:" << storeExtentBytes(problem, value) << "<0xfffff000"; + details << "D:" << storeExtentBytes(problem, value) << "<0x" << std::hex + << BufferOOBBytes << std::dec; PredicateDebugger::printRow(stream, rv, this->type(), details.str()); return rv; }