[AMDGPU] comgr: Add DS_ADDTID trampoline patch for A0 16-bit M0 truncation#2302
Open
xintin wants to merge 4 commits into
Open
[AMDGPU] comgr: Add DS_ADDTID trampoline patch for A0 16-bit M0 truncation#2302xintin wants to merge 4 commits into
xintin wants to merge 4 commits into
Conversation
Collaborator
961821a to
d70fc7a
Compare
d70fc7a to
8db0906
Compare
jmmartinez
reviewed
May 20, 2026
8db0906 to
42c9d6b
Compare
chinmaydd
reviewed
May 20, 2026
xintin
added a commit
that referenced
this pull request
May 20, 2026
Adds a small `ElfView` helper that reads `group_segment_fixed_size` from the kernel descriptor symbol `<KernelName>.kd`. Returns` std::nullopt` when the descriptor symbol is missing. Split out as a precursor to the `ds_*_addtid_b32` trampoline patch (PR #2302). That patch will use the helper to gate a diagnostic for kernels with LDS allocations larger than the A0 16-bit M0 truncation limit. Unit test `ElfView.GetKernelLdsSizeReturnsNulloptWhenKdMissing` covers the missing-descriptor path with a hand-crafted minimal ELF; the positive path will be exercised through lit once a consumer lands. --------- Signed-off-by: xintin <gaurav.verma@amd.com>
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
chinmaydd
reviewed
May 21, 2026
…ation
Rewrites `ds_*_addtid_b32` into an ALU-computed `ds_*_b32` so the
address bypasses the 16-bit M0 read on A0 (DEGFXMI400-12025). A
diagnostic is emitted when the kernel's LDS allocation exceeds 64 KiB.
Tests: lit `hotswap-trampoline-addtid{,-nosled}.s` and gtest `AddTid`
in `HotswapMCTest.cpp`.
Stacked on llvm#2583.
Assisted-by: Cursor
Signed-off-by: xintin <gaurav.verma@amd.com>
65115ab to
12de2b6
Compare
Signed-off-by: xintin <gaurav.verma@amd.com>
12de2b6 to
cd69a96
Compare
chinmaydd
approved these changes
May 21, 2026
Signed-off-by: xintin <gaurav.verma@amd.com>
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.
Stacked on #2583.
Problem
ds_load_addtid_b32andds_store_addtid_b32compute LDS addresses asM0 + laneID * 4 + offset. On B0 the DS unit reads 20 bits of M0 (1 MB); on A0 it reads only 16 (64 KB), silently truncating bits [19:16] (DEGFXMI400-12025). gfx1250 supports up to 320 KB LDS per WGP, so the upper 256 KB is unreachable through ADDTID. When B0-compiled code using ADDTID is hotswapped onto A0, M0 values above 65535 wrap and produce silently wrong LDS accesses.Fix
patchDsAddtid(incomgr-hotswap-patch-trampoline.cpp) rewrites each ADDTID instruction into an ALU sequence (v_mbcnt_lo_u32_b32/v_mbcnt_hi_u32_b32for laneID,v_lshlrev_b32×4,v_add_u32with M0 as a 32-bit operand) followed by a regulards_load_b32/ds_store_b32.The M0 read is bypassed and the original offset is preserved.
Emission goes through
emitReplacementCode(NOP sled preferred, deferred-trampoline fallback). GDS=1 is rejected with a diagnostic.allocScratchVgpr. If none is available the patch bails; when the kernel's LDS exceeds 64 KiB a warning is also logged so the A0 truncation risk surfaces to the user. The LDS size is read throughElfView::getKernelLdsSize, added in [AMDGPU] comgr: Add ElfView::getKernelLdsSize helper #2583.Testing
test-lit/hotswap-trampoline-addtid.s: sled-based rewrite, operand pinned DISASM across the full 6-instruction body.test-lit/hotswap-trampoline-addtid-nosled.s: deferred-trampoline fallback.test-unit/HotswapMCTest.cppAddTidsuite: ADDTID assemble/decode round-trips, operand layout, GDS rejection, trampoline asm assembly,buildTrampolineintegration.