Skip to content

[Comgr] Add end-to-end LIT coverage for amd_comgr_hotswap_rewrite#2291

Merged
yxsamliu merged 1 commit into
ROCm:amd-stagingfrom
harsh-amd:hotswap-lit-e2e
Apr 24, 2026
Merged

[Comgr] Add end-to-end LIT coverage for amd_comgr_hotswap_rewrite#2291
yxsamliu merged 1 commit into
ROCm:amd-stagingfrom
harsh-amd:hotswap-lit-e2e

Conversation

@harsh-amd
Copy link
Copy Markdown

Summary

End-to-end LIT coverage for amd_comgr_hotswap_rewrite. Drives the full compile -> hotswap-rewrite -> verify chain on a real clang-produced gfx1250 code object, using the in-tree %clang / %llvm-readelf / %llvm-objdump / %FileCheck substitutions -- no external toolchain required.

Follow-up to #2203. Implements part (A) of the testing-infrastructure plan laid out in that PR's comment thread: the dedicated infra-PR that goes in before any real-patch PR lands.

Changes

  • test-lit/hotswap-rewrite-e2e.hip (new): compiles a tiny kernel with %clang --offload-arch=gfx1250 --offload-device-only, pipes the resulting code object through hotswap-rewrite, and verifies the output with %llvm-readelf -h / %llvm-readelf --notes / %llvm-readelf --section-headers / %llvm-objdump -d.
  • test-lit/lit.cfg.py: add %llvm-readelf substitution (only %llvm-objdump was wired up previously).
  • test-lit/comgr-sources/hotswap-rewrite.c: optional --output <path> flag to write the rewrite output to a file so LIT tests can inspect it. Existing --zero-size negative-path coverage and the NULL-args / unsupported-ISA / malformed-ELF stanzas are unchanged.

What this covers today

Patches in comgr-hotswap-b0a0.cpp are weak stubs returning 0 in #2203, so the dispatcher currently emits an output that is bytewise-identical to the input. Even with no patches applied we assert:

  • Input is a gfx1250 ELF (e_flags contains gfx1250, AMDHSA metadata note records amdhsa.target: amdgcn-amd-amdhsa--gfx1250).
  • amd_comgr_hotswap_rewrite returns AMD_COMGR_STATUS_SUCCESS.
  • Output ELF preserves the gfx1250 identity on both channels (e_flags + AMDHSA note).
  • .text section is still present and PROGBITS.
  • llvm-objdump recognizes the output as elf64-amdgpu and disassembles through s_endpgm.

Future per-patch PRs

Each subsequent real-patch PR (in-place / trampoline / WMMA / scratch) will layer its own llvm-objdump | FileCheck stanza on top of this harness to assert the specific opcode changes / trampolines its policy introduces. No further infra PRs needed -- part (B) of the plan in #2203 is a per-PR convention rather than a dedicated PR.

Test plan

  • `llvm-lit tools/comgr/test-lit/hotswap-rewrite-e2e.hip` passes locally
  • Existing `tools/comgr/test-lit/hotswap-rewrite.c` still passes (driver changes are backward-compatible)
  • `check-comgr` green in CI (PSDB / compiler-ci-amd-staging)

cc @lamb-j @chinmaydd

Made with Cursor

@z1-cciauto
Copy link
Copy Markdown
Collaborator

@harsh-amd harsh-amd force-pushed the hotswap-lit-e2e branch 2 times, most recently from 6614457 to dfce3c4 Compare April 22, 2026 17:18
@z1-cciauto
Copy link
Copy Markdown
Collaborator

@lamb-j lamb-j added the hotswap Related to the Comgr Hotswap feature label Apr 22, 2026
Copy link
Copy Markdown

@chinmaydd chinmaydd left a comment

Choose a reason for hiding this comment

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

Generally LGTM, but @lamb-j is more familiar with testing infra.

Comment thread amd/comgr/test-lit/lit.cfg.py Outdated
Comment on lines +23 to +32
# Each LLVM backend built into the in-tree tools becomes a
# `<target>-registered-target` feature, matching the upstream LLVM lit.cfg
# convention. Tests that need a specific backend (e.g. the HotSwap LIT
# harness driving clang with --offload-arch=gfx*) can gate on these rather
# than fail noisily on builds that omit AMDGPU / X86 / etc.
for target in config.llvm_targets_to_build.split(";"):
target = target.strip()
if target:
config.available_features.add(target.lower() + "-registered-target")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Don't think we actually have a way to exercise the case where AMDGPU target is omitted. We'd fail on the Comgr link, so probably not worth to add here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we drop this, the config.llvm_targets_to_build = r'@LLVM_TARGETS_TO_BUILD@' addition in lit.site.cfg.py.in and the REQUIRES: in the test can also go.

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.

You're right. Comgr calls LLVMInitializeAMDGPU*() unconditionally so libamd_comgr.so wouldn't link without AMDGPU in the first place -- the REQUIRES: gate was defensive code that can never fire. Dropped all three pieces in 5f1e46a7:

  • REQUIRES: amdgpu-registered-target from hotswap-rewrite-e2e.hip
  • the <target>-registered-target feature loop in lit.cfg.py
  • the config.llvm_targets_to_build = r'@LLVM_TARGETS_TO_BUILD@' plumbing in lit.site.cfg.py.in

Net: -17 lines. I originally added it because I'd promised it in the #2203 follow-up plan, but the promise was overblown; happy to drop it here and note the reasoning inline on the #2203 thread if that makes the audit trail cleaner. If a future LIT test genuinely needs backend-gating (e.g. an x86-only stanza), we can re-add the feature machinery then.

@lamb-j
Copy link
Copy Markdown
Collaborator

lamb-j commented Apr 22, 2026

[2026-04-22T18:39:19.249Z] PASS: Comgr :: hotswap-rewrite.c (8 of 25)
[2026-04-22T18:39:19.249Z] PASS: Comgr :: hotswap-rewrite-e2e.hip (12 of 25)

Cool. I do think we should probably create a hotswap/ directory to keep things organized, but we can do that later.

@harsh-amd
Copy link
Copy Markdown
Author

Agreed on the hotswap/ subdirectory organization. There's enough hotswap-flavored test surface incoming (this e2e plus the opcode-level stanzas on every subsequent real-patch PR) that the split pays off quickly. I'd rather not do it in this PR since it means moving the already-landed test-lit/hotswap-rewrite.c and the test-lit/comgr-sources/hotswap-rewrite.c driver into the new location -- clean as a dedicated NFC-ish reorg PR after the first couple of patch PRs have landed and we know what the tree actually looks like. Tracked mentally as a follow-up alongside the comgr-utils extraction from #2201. cc @chinmaydd.

@z1-cciauto
Copy link
Copy Markdown
Collaborator

Adds test-lit/hotswap-rewrite-e2e.hip: drives the full
compile -> hotswap-rewrite -> verify chain on a real clang-produced
gfx1250 code object. Uses the in-tree %clang / %llvm-readelf /
%llvm-objdump / %FileCheck substitutions so the test runs out of the
LLVM monorepo build without any external toolchain.

Current assertions (weak patch stubs in PR ROCm#2203 keep the output
bytewise-identical to the input, so we check what we can verify today):

- Input is a gfx1250 ELF (e_flags carries gfx1250, AMDHSA metadata note
  records amdhsa.target = amdgcn-amd-amdhsa--gfx1250).
- amd_comgr_hotswap_rewrite returns AMD_COMGR_STATUS_SUCCESS.
- Output ELF preserves the gfx1250 identity on both channels.
- .text is still present and marked PROGBITS.
- llvm-objdump recognizes the output as elf64-amdgpu and disassembles
  at least through s_endpgm.

Future per-patch PRs (in-place / trampoline / WMMA / scratch) will
layer their own `llvm-objdump | FileCheck` stanzas on top of this
harness to assert their specific opcode / trampoline changes.

Supporting changes:

- amd/comgr/test-lit/lit.cfg.py: add %llvm-readelf substitution (only
  %llvm-objdump was wired up previously).
- amd/comgr/test-lit/comgr-sources/hotswap-rewrite.c: optional
  --output <path> flag to write the rewrite output to a file so LIT
  tests can inspect it with llvm-readelf / llvm-objdump. Existing
  --zero-size negative-path coverage is unchanged.

Made-with: Cursor
@z1-cciauto
Copy link
Copy Markdown
Collaborator

@yxsamliu yxsamliu merged commit ab27c60 into ROCm:amd-staging Apr 24, 2026
36 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotswap Related to the Comgr Hotswap feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants