Skip to content

AMDGPU: guard hotswap entry stub idempotency decode#3182

Merged
chinmaydd merged 3 commits into
ROCm:amd-stagingfrom
harsh-amd:comgr-entry-trampoline-prefix-guard
Jul 7, 2026
Merged

AMDGPU: guard hotswap entry stub idempotency decode#3182
chinmaydd merged 3 commits into
ROCm:amd-stagingfrom
harsh-amd:comgr-entry-trampoline-prefix-guard

Conversation

@harsh-amd

@harsh-amd harsh-amd commented Jul 3, 2026

Copy link
Copy Markdown

Summary

Guard the COMGR HotSwap kernel-entry trampoline idempotency matcher with a cheap raw-byte prefix check before invoking LLVM's AMDGPU disassembler.

The existing matcher disassembled KernelEntryStubStride bytes at every descriptor's current entry point to decide whether the descriptor already targeted an appended entry stub. Real gfx1250 code objects can contain valid kernel entry byte streams that still trip disassembler corner cases before HotSwap rewriting completes. The matcher only needs the full decode for plausible entry stubs, so this change first checks for the generated stub prefix (global_wb; v_nop) and treats all other entries as not already stubbed.

This preserves the existing full structural matcher for already-rewritten stubs, so rewrite idempotency remains intact.

Testing

  • /tmp/llvm-pr3182-build/bin/HotswapMCTests --gtest_filter='BuildKernelEntryTrampoline.*'
  • Manual RUN-line replay of amd/comgr/test-lit/hotswap-kernel-entry-trampoline.s using the existing COMGR lit helper
  • Reproduced the gfx1250 GPU2 hipBLASLt MXF8/BF16 smoke failure with ROCR_VISIBLE_DEVICES=2 and captured the reduced kernel-entry bytes used by the new regression
  • On gfx1250 GPU0 with ROCr PR 8082 runtime plus this COMGR change:
    hipblaslt-test --gtest_filter="*_/matmul_test.matmul/smoke_matmul_gemm_tn_mxf8_dst_bf16_1250_smoke_*"
    passed 16/16 tests.

@github-actions github-actions Bot added comgr Related to Code Object Manager hotswap Related to the Comgr Hotswap feature labels Jul 3, 2026
Ctx.Elf.getKernelStaticLdsSize(KernelName);
// Trampoline could not be applied: the original ds_*_addtid_b32 stays
// in the code object and will silently truncate M0 to 16 bits on A0
// (DEGFXMI400-12025) whenever the runtime LDS layout exceeds 64 KiB.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason we are removing references to internal tickets ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That was intentional. I replaced the internal ticket with the architecture-level failure mode (gfx1250 A0 16-bit M0 truncation) so the public code comment is self-contained.

Comment on lines +20 to +23
/// - ds_*_addtid_b32 : compute the LDS address through the ALU and
/// issue a regular ds_*_b32, bypassing the gfx1250 A0 16-bit M0
/// truncation. On B0 the DS unit reads 20 bits of M0; on A0 it reads only
/// 16, silently dropping bits [19:16].

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Indent regression

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in dee924e.

llvm::ArrayRef<uint8_t> ShortCandidate(Stub.data(), MinInstSize);
EXPECT_FALSE(hasKernelEntryTrampolinePrefix(ShortCandidate, S));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this inspired from an actual test case ? If yes, it would be nice to add a test that trips up the decoder.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes. The real-entry bytes are from the gfx1250 hipBLASLt MXF8/BF16 smoke. I added that reduction plus a separate decode case so the prefix gate covers the decoder-trip path too.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice, thanks

@chinmaydd chinmaydd merged commit 0154802 into ROCm:amd-staging Jul 7, 2026
54 of 59 checks passed
harsh-amd added a commit that referenced this pull request Jul 9, 2026
## Summary
- clamp gfx12 hotswap entry-stub INST_PREF_SIZE to the trampoline stub
span so the descriptor no longer advertises prefetch past the appended
trampoline/guard layout
- rewrite the descriptor in COMGR hotswap, keeping trampoline-related
loader policy out of ROCr
- scope NOP-sled discovery and rewriting to the owning function so COMGR
does not borrow sleds from adjacent code
- harden entry-trampoline idempotency decoding and add lit/unit coverage
for descriptor preservation, NOP-sled function scoping, and related
trampoline encodings

Depends on #3182. Review commit: d49d6b2.

## Testing
- cmake --build build --target HotswapMCTests hotswap-rewrite -j 32
- ./build/bin/HotswapMCTests
- ./build/bin/llvm-lit -sv build/tools/comgr/test-lit --filter
hotswap-kernel-entry-trampoline
- ./build/bin/llvm-lit -sv build/tools/comgr/test-lit --filter
hotswap-nop-sled-function-scope
- git diff --check
- TheRock gfx1250 final dist validation on mi400 GPU 1:
- hipblaslt-test
--gtest_filter=*_/matmul_test.matmul/smoke_matmul_gemm_tn_mxf8_dst_bf16_1250_smoke_*
passed 16 tests
- /mnt/ck-build/bin/example_gemm_multiply_multiply_xdl_fp8 passed;
verbose hotswap log showed trampoline prefetch guard bytes appended
- ASAN (`build-asan`, `LLVM_USE_SANITIZER=Address`;
`ASAN_OPTIONS=detect_leaks=0 LSAN_OPTIONS=detect_leaks=0` due local
LSan/ptrace limitation):
  - built HotswapMCTests, HotswapElfTests, and hotswap-rewrite
  - ./build-asan/bin/HotswapMCTests passed 39 tests
  - ./build-asan/bin/HotswapElfTests passed 14 tests
- ./build-asan/bin/llvm-lit -sv build-asan/tools/comgr/test-lit --filter
hotswap-kernel-entry-trampoline passed 1/1
- ./build-asan/bin/llvm-lit -sv build-asan/tools/comgr/test-lit --filter
hotswap-nop-sled-function-scope passed 1/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comgr Related to Code Object Manager hotswap Related to the Comgr Hotswap feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants