Repository navigation
Fix gfx1250 TDM illegal memory access #10871
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3223,8 +3223,12 @@ def depthUIteration( | |
| continue | ||
| vw = state["VectorWidth%s" % tc] | ||
| bpe_tc = state["ProblemType"]["MacDataType%s" % tc].numBytes() | ||
| lbspp = roundUpToNearestMultiple(int(state["_DepthU%s" % tc] * bpe_tc * vw), 256) | ||
| if lbspp > 1024: | ||
| lbspp_cfg = state["LdsBlockSizePerPad%s" % tc] | ||
| if lbspp_cfg == -1: | ||
| 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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| state["_TDMIterateMode%s" % tc] = True | ||
| # Resolve -1 into the concrete mask for kernel naming. backupValues | ||
| # restores -1 before each DepthU candidate, so this overwrite is safe. | ||
|
|
@@ -3251,8 +3255,10 @@ def depthUIteration( | |
| "TDMIterateMode %s requires TLU%s to be False" % (tc, tc)) | ||
| return | ||
|
|
||
| # Stage 2: for non-iterate tensors, halve auto-derived VW until LBSPP | ||
| # fits the pad_interval 1024 B limit. | ||
| # Stage 2: for non-iterate tensors with auto LBSPP, halve auto-derived VW until | ||
| # LBSPP fits pad_interval encoding. Skip when LdsBlockSizePerPad is explicit | ||
| # (halving VW there does not change LBSPP). When full VW=8 LBSPP would exceed | ||
| # the non-iterate cap, prefer iterate (needsIterateModeForPad) over halving. | ||
| multiple = 256 | ||
| for tc in ["A", "B"]: | ||
| if state.get("_TDMIterateMode%s" % tc, False): | ||
|
|
@@ -3261,11 +3267,20 @@ def depthUIteration( | |
| continue | ||
| if not state["UnrollMajorLDS%s" % tc]: | ||
| continue | ||
| if state["LdsBlockSizePerPad%s" % tc] != -1: | ||
| continue | ||
| vw = state["VectorWidth%s" % tc] | ||
| if vw <= 1: | ||
| continue | ||
| tmpBpe = state["ProblemType"]["MacDataType%s" % tc].numBytes() | ||
| depthU_tc = state["_DepthU%s" % tc] | ||
| 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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| state["_TDMIterateMode%s" % tc] = True | ||
| state["TDMIterateMode"] = state["TDMIterateMode"] | (1 if tc == "A" else 2) | ||
| continue | ||
| origVw = vw | ||
| while vw > 1: | ||
| candidate = roundUpToNearestMultiple(int(depthU_tc * tmpBpe * vw), multiple) | ||
|
|
@@ -4360,7 +4375,8 @@ def calSwizzlePackK(state, tc): | |
| extraComment = ": DepthU(%u) < Min-DU for swizzleB + LSU(%u)"%(depthUB, state["LocalSplitU"]) | ||
|
|
||
| # Subtile bypasses the 1024B pad_interval limit via iterate mode; | ||
| # non-subtile TDM handles it earlier via _TDMIterateMode + VW halving. | ||
| # non-subtile TDM handles it earlier via _TDMIterateMode and VW halving | ||
| # (iterate preferred over halving when needsIterateModeForPad applies). | ||
| # this depthU is valid, done unless user wants to double (for TN) | ||
| if validDepthU: | ||
| state["DepthU"] = depthU | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| ################################################################################ | ||
| # | ||
| # Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| # of this software and associated documentation files (the "Software"), to deal | ||
| # in the Software without restriction, including without limitation the rights | ||
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| # copies of the Software, and to permit persons to whom the Software is | ||
| # furnished to do so, subject to the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included in | ||
| # all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| # SOFTWARE. | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
| ################################################################################ | ||
| import pytest | ||
|
|
||
| from Tensile.Components.TensorDataMover import TensorDataMoverLoad | ||
|
|
||
| pytestmark = pytest.mark.unit | ||
|
|
||
|
|
||
| class TestTensorDataMoverPadHelpers: | ||
| """Unit tests for TDM pad / iterate-mode selection helpers.""" | ||
|
|
||
| def test_cal_pad_interval_1024(self) -> None: | ||
| """LBSPP=1024 encodes as pad_interval=7 (the hardware maximum). | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.calPadInterval(1024) == 7 | ||
|
|
||
| def test_needs_iterate_du128_vwb8(self) -> None: | ||
| """DU=128 BF16 VWB=8 exceeds the non-iterate pad cap. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(2048, 128, 2.0) is True | ||
|
|
||
| def test_needs_iterate_du128_vwb4_halved(self) -> None: | ||
| """Halved VWB=4 at DU=128 must use iterate when full VW=8 LBSPP exceeds cap. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(1024, 128, 2.0) is True | ||
|
|
||
| def test_no_iterate_du64_vwb8(self) -> None: | ||
| """DU=64 BF16 VWB=8 stays on the non-iterate path. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(1024, 64, 2.0) is False | ||
|
|
||
| def test_no_iterate_du64_vwb4_when_full_vw_fits(self) -> None: | ||
| """VWB=4 at DU=64 is safe when full VW=8 LBSPP still fits the 1024 B cap. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(512, 64, 2.0) is False | ||
|
|
||
| def test_no_iterate_lbspp_zero(self) -> None: | ||
| """LBSPP=0 disables padding; iterate mode must not be forced. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(0, 64, 2.0) is False | ||
|
|
||
| def test_needs_iterate_fp4_non_integer_row_bytes(self) -> None: | ||
| """fp4 (bpe=0.5) with non-integer DepthU*bpe must not under-estimate VW=8 LBSPP. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(1024, 257, 0.5) is True | ||
|
|
||
| def test_needs_iterate_bf6_halved_path(self) -> None: | ||
| """bf6/fp6 (bpe=0.75) halved-VW path must detect full VW=8 LBSPP over cap. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(768, 171, 0.75) is True | ||
|
|
||
| def test_no_iterate_fp4_at_cap(self) -> None: | ||
| """fp4 at exactly 1024 B VW=8 LBSPP stays non-iterate. | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
| assert TensorDataMoverLoad.needsIterateModeForPad(1024, 256, 0.5) is False |
There was a problem hiding this comment.
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)?