Skip to content

Fix gfx1250 TDM illegal memory access - #10871

Closed
dsaffars wants to merge 4 commits into
developfrom
users/dsaffars/vwb4_illegal_memory_address
Closed

dsaffars wants to merge 4 commits into
developfrom
users/dsaffars/vwb4_illegal_memory_address

Conversation

@dsaffars

@dsaffars dsaffars commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

JIRA ID: AIHPBLAS-4324

Fix gfx1250 TDM illegal memory access when DepthU=128 forces non-iterate TDM with halved VectorWidthB=4. Prefer TDMIterateMode (iterate_enable) and keep auto-derived VectorWidth=8 instead of halving VW to fit the 1024 B pad_interval cap.

Motivation

Tuning configs with DepthU=128, TDMInst=3, and auto-derived vector widths hit hipErrorIllegalAddress. The same macro-tile with DepthU=64 passes.

Root cause: when LBSPP = roundUp(DepthU × bpe × VectorWidth, 256) exceeds 1024 B, Tensile Stage 2 halved VectorWidthB (8→4) so the non-iterate pad_interval field could encode the padding. That produced kernels like:

  • TDMIM0 VWB4 LBSPPB1024 → illegal global access

The working workaround is explicit iterate mode:

  • TDMIM2 VWB8 LBSPPB2048 → passes

The non-iterate TDM descriptor path with reduced VectorWidth does not match the LDS layout on gfx1250. Halving VW to satisfy pad_interval is not a safe fallback for this case — iterate mode is.

Technical Details

New helper: TensorDataMoverLoad.needsIterateModeForPad

Centralizes the iterate-vs-non-iterate decision in TensorDataMover.py. Returns True when non-iterate TDM must not be used:

Condition Example
LBSPP == 0 xccremap (LdsBlockSizePerPad: 0) — no padding, do not force iterate
LBSPP > 1024 Direct hardware cap (pad_interval max → 1024 B)
roundUp256(int(DepthU × bpe × 8)) > 1024 Halved-VW broken path at LBSPPB ≤ 1024

The VW=8 reference LBSPP uses int(depth_u * bpe * 8), matching Solution.py's LBSPP formula. This is required for fractional bpe (fp4 0.5, bf6/fp6 0.75) where round(DepthU × bpe) × 8 can under-estimate (e.g. DU=257, bpe=0.5 → true LBSPP 1280, wrong formula gives 1024).

Solution.py Stage 1 (TDMIterateMode: -1)

  • Uses configured LdsBlockSizePerPad{A,B} when not -1 (not always computed from VW) — fixes xccremap false iterate rejection.
  • Calls needsIterateModeForPad instead of lbspp > 1024 alone.

Solution.py Stage 2 (VW halving preserved, with guards)

Stage 2 halving is kept for pad_interval encoding edge cases, but gated:

  1. Skip if already in iterate mode (_TDMIterateMode).
  2. Skip if VW was user-specified (_inputVW*_was_auto) — do not silently rewrite yaml VW.
  3. Skip if LdsBlockSizePerPad != -1 — halving VW does not change explicit LBSPP.
  4. If TDMIterateMode is explicit (not -1) and needsIterateModeForPad → force iterate instead of halving.
  5. Otherwise run the original vw //= 2 loop until pad_interval encoding fits.

Coexists with develop's TLU rejection (#10935): iterate mode requires K-major global layout (TLU{A,B} must be false).

Characterization yaml

streamk_tdm_prefetchgl2.yaml: DepthU: 256 → 128 so the mxf8 SGPR-budget test stays non-iterate at VWB=8, LBSPPB=1024. DU=256 would force iterate and overflow the SGPR budget for that test harness.

Test plan

cd projects/hipblaslt/tensilelite
python -m pytest Tensile/Tests/unit/test_TensorDataMoverPad.py -q
python -m pytest Tensile/Tests/unit/characterization/_codegen/ -q

test_TensorDataMoverPad.py (9 cases):

  • BF16: DU=128 direct and halved-VW paths, DU=64 safe cases, LBSPP=0
  • fp4 (bpe=0.5): non-integer DepthU×bpe (DU=257), cap boundary (DU=256)
  • bf6/fp6 (bpe=0.75): halved-VW path (DU=171)

@therock-pr-bot

therock-pr-bot Bot commented Aug 17, 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

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #10871   +/-   ##
========================================
  Coverage    69.36%   69.36%           
========================================
  Files         2779     2779           
  Lines       458135   458133    -2     
  Branches     67569    67568    -1     
========================================
  Hits        317781   317781           
+ Misses      117213   117211    -2     
  Partials     23141    23141           
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 38.05% <ø> (ø) Carriedforward from 1ecfcc9
TensileLite-Unit 76.58% <ø> (+<0.01%) ⬆️ Carriedforward from 1ecfcc9
hipBLAS 90.62% <ø> (ø) Carriedforward from 1ecfcc9
hipBLASLt 34.89% <ø> (ø)
hipCUB 82.68% <ø> (ø) Carriedforward from 1ecfcc9
hipDNN 86.79% <ø> (ø) Carriedforward from 1ecfcc9
hipFFT 43.60% <ø> (ø) Carriedforward from 1ecfcc9
hipRAND 76.12% <ø> (ø) Carriedforward from 1ecfcc9
hipSOLVER 69.03% <ø> (ø) Carriedforward from 1ecfcc9
hipSPARSE 86.99% <ø> (ø) Carriedforward from 1ecfcc9
rocBLAS 48.26% <ø> (ø) Carriedforward from 1ecfcc9
rocFFT 47.64% <ø> (ø) Carriedforward from 1ecfcc9
rocRAND 57.05% <ø> (ø) Carriedforward from 1ecfcc9
rocSOLVER 77.12% <ø> (ø) Carriedforward from 1ecfcc9
rocSPARSE 74.62% <ø> (ø) Carriedforward from 1ecfcc9
rocThrust 91.60% <ø> (ø) Carriedforward from 1ecfcc9

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
.../tensilelite/Tensile/Components/TensorDataMover.py 70.96% <ø> (ø)
...lt/tensilelite/Tensile/SolutionStructs/Solution.py 59.00% <ø> (+0.03%) ⬆️
🚀 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.

# LBSPP = roundUp(DepthU * bpe * VectorWidth, 256). When full VW=8 would
# exceed the non-iterate cap and VectorWidth was halved to fit pad_interval,
# the non-iterate descriptor path does not match the LDS layout.
if vector_width < 8:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need this condition?
Shouldn't we just rely on full_vw_lbspp > TensorDataMoverLoad.MAX_NON_ITERATE_LBSPP_BYTES to decide if we need iterative mode or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Pushed a new patch

@nakajee

nakajee commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Please fix the typo (150) in the title.

@dsaffars dsaffars changed the title Fix gfx150 TDM illegal memory access Fix gfx1250 TDM illegal memory access Aug 17, 2026
multiple = 256
for tc in ["A", "B"]:
if state.get("_TDMIterateMode%s" % tc, False):
continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not think we need to remove this condition?
Why did you remove it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This condition is about if not state.get("_inputVW%s_was_auto" % tc, False):

if dwords > 0 and (dwords & (dwords - 1)) == 0:
pad_interval = int(math.log2(dwords)) - 1
if pad_interval <= 7:
break # current VW fits pad_interval encoding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not think we need to remove this vw //= 2 logic.
This logic is just inconsistent with LdsBlockSizePerPadA/B != -1 case.
So, I think we just need to skip wv //=2 if LdsBlockSizePerPadA/B != -1

@minsukim-amd
minsukim-amd requested a review from aazz44ss August 18, 2026 01:55
@aazz44ss
aazz44ss requested a review from chicyang August 18, 2026 12:30

@jichangjichang jichangjichang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did TDMIM0 VWB4 LBSPPB1024 cause illegal memory acess?
We need the root cause why TDMIM0 padding cause illegal memory access

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes gfx1250 TDM illegal global memory access for DepthU=128 cases where Tensile previously “solved” the 1024B pad_interval encoding limit by halving VectorWidth{A,B} (e.g., 8→4), by instead preferring TDM iterate mode selection via a shared helper.

Changes:

  • Added TensorDataMoverLoad.needsIterateModeForPad() to centralize iterate-vs-non-iterate selection for TDM padding constraints.
  • Updated Solution.py Stage 1/2 TDM iterate-mode decision logic to use the helper and removed the Stage 2 VectorWidth-halving loop.
  • Added unit tests for the helper and adjusted a gfx1250 characterization YAML to keep the test case within SGPR budget.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
projects/hipblaslt/tensilelite/Tensile/Components/TensorDataMover.py Adds the new helper for deciding when to force TDM iterate mode for padding.
projects/hipblaslt/tensilelite/Tensile/SolutionStructs/Solution.py Uses the helper in Stage 1/2 and removes VectorWidth halving in favor of iterate mode.
projects/hipblaslt/tensilelite/Tensile/Tests/unit/test_TensorDataMoverPad.py New unit tests validating pad interval encoding and iterate-mode selection logic.
projects/hipblaslt/tensilelite/Tensile/Tests/unit/characterization/_codegen/data/test_data/_designed/gfx1250/streamk_tdm_prefetchgl2.yaml Adjusts DepthU to avoid SGPR budget overflow in the designed gfx1250 case.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dsaffars
dsaffars force-pushed the users/dsaffars/vwb4_illegal_memory_address branch from b78fc29 to 85fa7fe Compare August 19, 2026 11:44
return False
if ldsBlockSizePerPad > TensorDataMoverLoad.MAX_NON_ITERATE_LBSPP_BYTES:
return True
full_vw_bytes = int(depth_u * bpe * 8)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not understand why we need this condition.
Why do we need to ignore VectorWidth setting and use 8 (= maximum of VectorWidth)?

lbspp = roundUpToNearestMultiple(int(state["_DepthU%s" % tc] * bpe_tc * vw), 256)
else:
lbspp = lbspp_cfg
if TensorDataMoverLoad.needsIterateModeForPad(lbspp, state["_DepthU%s" % tc], bpe_tc):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My understanding is just to use original if condition if lbspp > 1024 here.
I think we just need to add the logic to use lbspp = lbspp_cfg if lbspp_cfg is not -1.

lbspp = roundUpToNearestMultiple(int(depthU_tc * tmpBpe * vw), multiple)
# When TDMIterateMode is explicit (not -1), Stage 1 does not auto-select
# iterate; block VW halving and force iterate for the gfx1250 broken path.
if iterModeMask != -1 and TensorDataMoverLoad.needsIterateModeForPad(lbspp, depthU_tc, tmpBpe):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we simply reject the kernel if both TDMIterateMode and LdsBlockSizePerPad are not -1 and the setting is inconsistent?

@babakpst

Copy link
Copy Markdown
Contributor

Already addressed.

@babakpst babakpst closed this Aug 27, 2026
@dsaffars
dsaffars deleted the users/dsaffars/vwb4_illegal_memory_address branch September 7, 2026 11:30
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.

5 participants