Skip to content

Commit 53a6f92

Browse files
committed
AMDGPU: add hotswap entry trampoline lit coverage
1 parent 7eb0c18 commit 53a6f92

6 files changed

Lines changed: 182 additions & 17 deletions

amd/comgr/test-lit/hotswap-barrier-isfirst.s

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,48 @@
3535
// API2: RESULT: SUCCESS
3636
// RUN: cmp %t.out.elf %t.out2.elf
3737

38+
// COM: One-sided stepping annotations must also be honored. An explicit A0
39+
// COM: source with a generic target is not B0->A0, and a generic source with
40+
// COM: an explicit B0 target is not B0->A0 either.
41+
// RUN: AMD_COMGR_HOTSWAP_ENTRY_TRAMPOLINES=0 hotswap-rewrite %t.elf \
42+
// RUN: amdgcn-amd-amdhsa--gfx1250:gfx1250-b0-specific- \
43+
// RUN: amdgcn-amd-amdhsa--gfx1250 \
44+
// RUN: --output %t.a0generic.elf \
45+
// RUN: | %FileCheck --check-prefix=A0GENERIC-API %s
46+
// A0GENERIC-API: RESULT: SUCCESS
47+
// RUN: %llvm-objdump -d %t.a0generic.elf | %FileCheck --check-prefix=NO-PATCH %s
48+
49+
// RUN: AMD_COMGR_HOTSWAP_ENTRY_TRAMPOLINES=0 hotswap-rewrite %t.elf \
50+
// RUN: amdgcn-amd-amdhsa--gfx1250 \
51+
// RUN: amdgcn-amd-amdhsa--gfx1250:gfx1250-b0-specific+ \
52+
// RUN: --output %t.genericb0.elf \
53+
// RUN: | %FileCheck --check-prefix=GENERICB0-API %s
54+
// GENERICB0-API: RESULT: SUCCESS
55+
// RUN: %llvm-objdump -d %t.genericb0.elf | %FileCheck --check-prefix=NO-PATCH %s
56+
57+
// NO-PATCH: s_barrier_signal_isfirst -1
58+
// NO-PATCH-NEXT: s_barrier_wait 0xffff
59+
// NO-PATCH-NEXT: s_barrier_signal_isfirst -3
60+
// NO-PATCH-NEXT: s_barrier_wait 0xfffd
61+
// NO-PATCH-NEXT: s_endpgm
62+
63+
// COM: With explicit B0->B0 stepping, default entry trampolines must not
64+
// COM: accidentally enable B0-to-A0 instruction patches. The isfirst opcodes
65+
// COM: remain, while the kernel descriptor is still redirected through an
66+
// COM: appended entry stub.
67+
// RUN: hotswap-rewrite %t.elf \
68+
// RUN: amdgcn-amd-amdhsa--gfx1250:gfx1250-b0-specific+ \
69+
// RUN: amdgcn-amd-amdhsa--gfx1250:gfx1250-b0-specific+ \
70+
// RUN: --output %t.b0b0.elf \
71+
// RUN: | %FileCheck --check-prefix=B0B0-API %s
72+
// B0B0-API: RESULT: SUCCESS
73+
// RUN: %llvm-objdump -d %t.b0b0.elf | %FileCheck --check-prefix=B0B0 %s
74+
// B0B0: s_barrier_signal_isfirst -1
75+
// B0B0-NEXT: s_barrier_wait 0xffff
76+
// B0B0-NEXT: s_barrier_signal_isfirst -3
77+
// B0B0-NEXT: s_barrier_wait 0xfffd
78+
// B0B0: global_wb
79+
3880
.amdgcn_target "amdgcn-amd-amdhsa--gfx1250"
3981
.text
4082
.globl test_barrier_isfirst
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// COM: HotSwap entry trampolines are supported across gfx125x.
2+
3+
// RUN: %clang -target amdgcn-amd-amdhsa -mcpu=gfx1251 -nostdlib %s -o %t.gfx1251.elf
4+
// RUN: hotswap-rewrite %t.gfx1251.elf \
5+
// RUN: amdgcn-amd-amdhsa--gfx1251 amdgcn-amd-amdhsa--gfx1251 \
6+
// RUN: --output %t.gfx1251.out.elf \
7+
// RUN: | %FileCheck --check-prefix=API %s
8+
// RUN: %llvm-objdump -d %t.gfx1251.out.elf | %FileCheck --check-prefix=DISASM %s
9+
10+
// RUN: sed -e '/^\.amdgcn_target/d' \
11+
// RUN: -e 's/gfx1251/gfx12-5-generic/g' %s > %t.generic.s
12+
// RUN: %clang -target amdgcn-amd-amdhsa -mcpu=gfx12-5-generic -nostdlib \
13+
// RUN: %t.generic.s -o %t.generic.elf
14+
// RUN: hotswap-rewrite %t.generic.elf \
15+
// RUN: amdgcn-amd-amdhsa--gfx12-5-generic \
16+
// RUN: amdgcn-amd-amdhsa--gfx12-5-generic \
17+
// RUN: --output %t.generic.out.elf \
18+
// RUN: | %FileCheck --check-prefix=API %s
19+
// RUN: %llvm-objdump -d %t.generic.out.elf | %FileCheck --check-prefix=DISASM %s
20+
21+
// API: RESULT: SUCCESS
22+
23+
// DISASM-LABEL: <entry_tramp_family_kernel>:
24+
// DISASM: s_endpgm
25+
// DISASM: global_wb
26+
// DISASM-NEXT: v_nop
27+
// DISASM-NEXT: s_get_pc_i64 s[8:9]
28+
// DISASM-NEXT: s_add_co_u32 s8
29+
// DISASM-NEXT: s_add_co_ci_u32 s9
30+
// DISASM-NEXT: s_set_pc_i64 s[8:9]
31+
32+
.amdgcn_target "amdgcn-amd-amdhsa--gfx1251"
33+
.text
34+
.globl entry_tramp_family_kernel
35+
.p2align 8
36+
.type entry_tramp_family_kernel,@function
37+
entry_tramp_family_kernel:
38+
v_mov_b32_e32 v0, 0
39+
s_endpgm
40+
.Lentry_tramp_family_kernel_end:
41+
.size entry_tramp_family_kernel, .Lentry_tramp_family_kernel_end-entry_tramp_family_kernel
42+
43+
.rodata
44+
.p2align 8
45+
.amdhsa_kernel entry_tramp_family_kernel
46+
.amdhsa_next_free_vgpr 1
47+
.amdhsa_next_free_sgpr 1
48+
.amdhsa_inst_pref_size 7
49+
.end_amdhsa_kernel
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// COM: The entry-trampoline rewrite must redirect every kernel descriptor in
2+
// COM: the code object, not just the first one. Each descriptor gets its own
3+
// COM: appended PC-relative entry stub.
4+
5+
// RUN: %clang -target amdgcn-amd-amdhsa -mcpu=gfx1250 -nostdlib %s -o %t.elf
6+
7+
// RUN: hotswap-rewrite %t.elf \
8+
// RUN: amdgcn-amd-amdhsa--gfx1250 amdgcn-amd-amdhsa--gfx1250 \
9+
// RUN: --output %t.out.elf \
10+
// RUN: | %FileCheck --check-prefix=API %s
11+
// API: RESULT: SUCCESS
12+
13+
// RUN: %llvm-objdump -d %t.out.elf | %FileCheck --check-prefix=DISASM %s
14+
15+
// DISASM-LABEL: <entry_tramp_first>:
16+
// DISASM: s_endpgm
17+
// DISASM-LABEL: <entry_tramp_second>:
18+
// DISASM: s_endpgm
19+
// DISASM: global_wb
20+
// DISASM-NEXT: v_nop
21+
// DISASM-NEXT: s_get_pc_i64 s[8:9]
22+
// DISASM-NEXT: s_add_co_u32 s8
23+
// DISASM-NEXT: s_add_co_ci_u32 s9
24+
// DISASM-NEXT: s_set_pc_i64 s[8:9]
25+
// DISASM: global_wb
26+
// DISASM-NEXT: v_nop
27+
// DISASM-NEXT: s_get_pc_i64 s[8:9]
28+
// DISASM-NEXT: s_add_co_u32 s8
29+
// DISASM-NEXT: s_add_co_ci_u32 s9
30+
// DISASM-NEXT: s_set_pc_i64 s[8:9]
31+
32+
.amdgcn_target "amdgcn-amd-amdhsa--gfx1250"
33+
.text
34+
.globl entry_tramp_first
35+
.p2align 8
36+
.type entry_tramp_first,@function
37+
entry_tramp_first:
38+
v_mov_b32_e32 v0, 1
39+
s_endpgm
40+
.Lentry_tramp_first_end:
41+
.size entry_tramp_first, .Lentry_tramp_first_end-entry_tramp_first
42+
43+
.globl entry_tramp_second
44+
.p2align 8
45+
.type entry_tramp_second,@function
46+
entry_tramp_second:
47+
v_mov_b32_e32 v0, 2
48+
s_endpgm
49+
.Lentry_tramp_second_end:
50+
.size entry_tramp_second, .Lentry_tramp_second_end-entry_tramp_second
51+
52+
.rodata
53+
.p2align 8
54+
.amdhsa_kernel entry_tramp_first
55+
.amdhsa_next_free_vgpr 1
56+
.amdhsa_next_free_sgpr 1
57+
.end_amdhsa_kernel
58+
59+
.p2align 8
60+
.amdhsa_kernel entry_tramp_second
61+
.amdhsa_next_free_vgpr 1
62+
.amdhsa_next_free_sgpr 1
63+
.end_amdhsa_kernel

amd/comgr/test-lit/hotswap-kernel-entry-trampoline.s

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
// NO-TRAMP: s_endpgm
2323
// NO-TRAMP-NOT: global_wb
2424

25+
// COM: Entry trampolines are independent of the B0-to-A0 patch policy, so an
26+
// COM: explicit B0->A0 rewrite should still redirect the descriptor to a stub.
27+
// RUN: hotswap-rewrite %t.elf \
28+
// RUN: amdgcn-amd-amdhsa--gfx1250:gfx1250-b0-specific+ \
29+
// RUN: amdgcn-amd-amdhsa--gfx1250:gfx1250-b0-specific- \
30+
// RUN: --output %t.b0a0.elf \
31+
// RUN: | %FileCheck --check-prefix=API %s
32+
// RUN: %llvm-objdump -d %t.b0a0.elf | %FileCheck --check-prefix=DISASM %s
33+
2534
// DISASM-LABEL: <entry_tramp_kernel>:
2635
// DISASM: s_endpgm
2736
// DISASM: global_wb
@@ -34,6 +43,13 @@
3443
// METADATA: .name: entry_tramp_kernel
3544
// METADATA: .sgpr_count: 10
3645

46+
// RUN: hotswap-rewrite %t.out.elf \
47+
// RUN: amdgcn-amd-amdhsa--gfx1250 amdgcn-amd-amdhsa--gfx1250 \
48+
// RUN: --output %t.out2.elf \
49+
// RUN: | %FileCheck --check-prefix=API2 %s
50+
// API2: RESULT: SUCCESS
51+
// RUN: cmp %t.out.elf %t.out2.elf
52+
3753
// COM: If the requested entry trampoline cannot allocate an aligned scratch
3854
// COM: SGPR pair, the rewrite fails instead of returning a partial output.
3955
// RUN: sed 's/.sgpr_count: 8/.sgpr_count: 105/' %s > %t.highsgpr.s

amd/comgr/test-lit/hotswap-rewrite-e2e.hip

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
// COM: compile -> hotswap-rewrite -> verify chain using the in-tree
55
// COM: clang + llvm-readelf + llvm-objdump substitutions.
66
// COM:
7-
// COM: Patches in amd/comgr/src/comgr-hotswap-b0a0.cpp are weak stubs
8-
// COM: returning 0 until the concrete patch .cpp files land, so the
9-
// COM: dispatcher currently emits an output that is bytewise-identical
10-
// COM: to the input. Even with no patches applied we can assert that
11-
// COM: (1) the rewrite returns SUCCESS, (2) the output is a valid
12-
// COM: gfx1250 ELF that preserves the ISA identification, and (3) .text
13-
// COM: is still present and disassemblable as AMDGPU code. The
14-
// COM: per-patch PRs will layer in their own `llvm-objdump | FileCheck`
15-
// COM: stanzas on top of this harness to assert their specific opcode
16-
// COM: changes / trampolines.
7+
// COM: This kernel intentionally does not contain instructions matched by
8+
// COM: the current hotswap patch set. The test is still useful as a real
9+
// COM: code-object smoke test: it asserts that (1) rewrite returns SUCCESS,
10+
// COM: (2) the output remains a valid gfx1250 ELF with preserved ISA
11+
// COM: identification, and (3) .text is still present and disassemblable.
12+
// COM: Patch-specific LIT tests cover opcode changes and trampolines.
1713

1814
// COM: Compile a tiny kernel targeting gfx1250 to a raw code object.
1915
// RUN: %clang --offload-arch=gfx1250 --offload-device-only \
@@ -25,7 +21,7 @@
2521
// RUN: %llvm-readelf -h %t.input.elf | %FileCheck --check-prefix=INPUT-FLAGS %s
2622
// INPUT-FLAGS: Flags:{{.*}}gfx1250
2723
// RUN: %llvm-readelf --notes %t.input.elf | %FileCheck --check-prefix=INPUT-META %s
28-
// INPUT-META: amdhsa.target: amdgcn-amd-amdhsa-{{.*}}gfx1250
24+
// INPUT-META: amdhsa.target: amdgcn-amd-amdhsa{{--|-unknown-}}gfx1250
2925

3026
// COM: Run hotswap-rewrite; save the output so we can inspect it.
3127
// RUN: AMD_COMGR_HOTSWAP_ENTRY_TRAMPOLINES=0 hotswap-rewrite %t.input.elf \
@@ -34,14 +30,13 @@
3430
// RUN: | %FileCheck --check-prefix=STATUS %s
3531
// STATUS: RESULT: SUCCESS
3632

37-
// COM: Output ELF is valid and still identifies as gfx1250 (patches are
38-
// COM: weak stubs, so the identity should be preserved untouched; future
39-
// COM: patch PRs that intentionally change the target ISA note will
40-
// COM: update this stanza).
33+
// COM: Output ELF is valid and still identifies as gfx1250; this smoke
34+
// COM: kernel has no patch-triggering instructions, so the rewrite should
35+
// COM: preserve the target identification.
4136
// RUN: %llvm-readelf -h %t.output.elf | %FileCheck --check-prefix=OUTPUT-FLAGS %s
4237
// OUTPUT-FLAGS: Flags:{{.*}}gfx1250
4338
// RUN: %llvm-readelf --notes %t.output.elf | %FileCheck --check-prefix=OUTPUT-META %s
44-
// OUTPUT-META: amdhsa.target: amdgcn-amd-amdhsa-{{.*}}gfx1250
39+
// OUTPUT-META: amdhsa.target: amdgcn-amd-amdhsa{{--|-unknown-}}gfx1250
4540

4641
// COM: .text section is still present and marked executable.
4742
// RUN: %llvm-readelf --section-headers %t.output.elf \

amd/comgr/test-lit/hotswap-rewrite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// ZEROSIZE: RESULT: INVALID_ARGUMENT
2424

2525
// COM: Supported GFX1250 pair on a malformed ELF (no .text section).
26-
// COM: retargetCodeObjectB0A0 rejects inputs that fail ELF64 parsing or have
26+
// COM: retargetCodeObject rejects inputs that fail ELF64 parsing or have
2727
// COM: an empty .text section with INVALID_ARGUMENT -- returning SUCCESS with
2828
// COM: an unchanged copy there would silently hide caller-side bugs.
2929
// RUN: AMD_COMGR_HOTSWAP_ENTRY_TRAMPOLINES=0 hotswap-rewrite %t.elf amdgcn-amd-amdhsa--gfx1250 amdgcn-amd-amdhsa--gfx1250 \

0 commit comments

Comments
 (0)