Skip to content

AMDGPU: scope hotswap trampolines and clamp entry prefetch#3195

Merged
harsh-amd merged 2 commits into
ROCm:amd-stagingfrom
harsh-amd:comgr-entry-trampoline-inst-pref-hotswap
Jul 9, 2026
Merged

AMDGPU: scope hotswap trampolines and clamp entry prefetch#3195
harsh-amd merged 2 commits into
ROCm:amd-stagingfrom
harsh-amd:comgr-entry-trampoline-inst-pref-hotswap

Conversation

@harsh-amd

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

Copy link
Copy Markdown

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

@github-actions github-actions Bot added comgr Related to Code Object Manager hotswap Related to the Comgr Hotswap feature labels Jul 5, 2026
@harsh-amd harsh-amd changed the title AMDGPU: clamp hotswap entry-stub inst prefetch AMDGPU: scope hotswap trampolines and clamp entry prefetch Jul 5, 2026
@chinmaydd

Copy link
Copy Markdown

LIT tests are failing and seem genuine (?)

@harsh-amd harsh-amd force-pushed the comgr-entry-trampoline-inst-pref-hotswap branch 2 times, most recently from 6f1f253 to cff7756 Compare July 7, 2026 23:36
@harsh-amd

Copy link
Copy Markdown
Author

LIT tests are failing and seem genuine (?)

this should be fixed now. please take another look.

Comment thread amd/comgr/test-unit/HotswapMCTest.cpp Outdated
7u);
KernelEntryStubInstPrefLines);
EXPECT_EQ(
AMDHSA_BITS_GET(OutRsrc3, hsa::COMPUTE_PGM_RSRC3_GFX11_INST_PREF_SIZE),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should test with INST_PREF_SIZE for gfx12 rather than 11

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.

I have removed the gfx11 check. this now only checks the gfx12 inst_pref field.

uint32_t MaxInstPrefLines = 0;
for (const KernelDescriptorInfo &KD : Descriptors) {
std::optional<uint32_t> InstPrefLines =
Elf.getKernelDescriptorInstPrefSize(KD.KernelName, LS.Cpu);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If I understand correctly, we have 2 different sources for the prefetch. Is that intentional ?

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.

this is intentional. deferred trampolines use the original kernel descriptor prefetch for the trailing guard. entry stubs clamp their own descriptor value separately. I added comments to make this clearer.

Work.push_back(KD);
uint32_t StubInstPrefLines =
std::min(*InstPrefLines, KernelEntryStubInstPrefLines);
MaxInstPrefLines = std::max(MaxInstPrefLines, StubInstPrefLines);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If I understand correctly, there are now 2 sources for the prefetch value ? Can they disagree?

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.

they can disagree intentionally. the original value may be larger, but the entry stub descriptor is clamped to the 256-byte stub stride. I renamed this to make that explicit.

Comment thread amd/comgr/src/comgr-hotswap-elf.cpp Outdated
Comment on lines +286 to +287
if (Sled.WritePos > Sled.FunctionEnd ||
Needed > Sled.FunctionEnd - Sled.WritePos)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Check may be redundant ?

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.

I have folded this into one usable-end check.

Comment thread amd/comgr/src/comgr-hotswap-b0a0.cpp Outdated
log() << "hotswap: error: trampoline prefetch guard size " << GuardBytes
<< " exceeds size_t.\n";
return false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably redundant

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.

I have removed it. the guard size is bounded by the descriptor field here.

Comment thread amd/comgr/test-unit/HotswapElfTest.cpp Outdated
TEST(FindNearestSled, SkipsSledsOutsideInstructionFunctionRange) {
std::vector<NopSled> Sleds;
Sleds.push_back({0, 32, 0, 0, 32});
Sleds.push_back({96, 128, 96, 96, 160});

@chinmaydd chinmaydd Jul 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

// {Start, End, WritePos, FunctionStart, FunctionEnd}
Sleds.push_back({/*Start=*/96, /*End=*/128, /*WritePos=*/96,
                 /*FunctionStart=*/96, /*FunctionEnd=*/160});

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.

I have added field comments for the sled initializers.

@harsh-amd harsh-amd force-pushed the comgr-entry-trampoline-inst-pref-hotswap branch from cff7756 to 627fea4 Compare July 8, 2026 18:21
@harsh-amd harsh-amd enabled auto-merge (squash) July 8, 2026 18:25
@harsh-amd harsh-amd force-pushed the comgr-entry-trampoline-inst-pref-hotswap branch from 627fea4 to 737d5a5 Compare July 8, 2026 22:25
@harsh-amd harsh-amd merged commit fd34dbb into ROCm:amd-staging Jul 9, 2026
28 checks passed
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