Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,9 @@ def salu_ext_test(tools, spirv, env=None):
# s_and/s_or_saveexec_b64 (VCC and SGPR-pair sources), s_andn2_saveexec/wrexec_b64 (SGPR pair): D, EXEC, SCC
("cs_w64x_saveexec_b64", [6160, 12304, 5120, 2088, 6168, 8192, 7176, 1837171]),
# SHADER-W64-SDST-PAIR: v_cmp_* / carry-out SGPR destinations printed as one register (no mattr line)
("cs_w64x_cmp_sdst", [10240, 6144, 2053, 8224, 7714, 6184, 4144, 5])]
("cs_w64x_cmp_sdst", [10240, 6144, 2053, 8224, 7714, 6184, 4144, 5]),
# SHADER-W64-XROUND-BARRIERS: Any-vote reuse, deferred SCC coalescing, batched v_readfirstlane_b32
("cs_w64x_xround_coalesce", [147, 308, 1832, 444, 625, 1335, 2379, 332])]
# A 40-thread group (one partial wave) cannot use --require-wave64 (full subgroups), so it asks for subgroup size 64.
W64X_PARTIAL = [("cs_w64x_partial", [40, 40, 528, 0, 0, 532, 539, 524820]),
("cs_w64x_partial_scmp", [0, 1, 0, 1, 1, 1, 1, 0]),
Expand Down
117 changes: 117 additions & 0 deletions runtime/test/shaders/cs_w64x_xround_coalesce.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
; Coalesced and cached wave-wide exchanges in --wave64-emulate (Gen.x_round):
; v1 = lane 0..63; v4 = 100 + lane, v5 = 200 + 3*lane, v6 = 500 + 5*lane, v7 = 900 + 7*lane.
; s[10:11] = lanes 36..51 (upper half only, lowest 36); s[14:15] = lanes 8..23 (low half only, lowest 8).
; 1) Live-SCC s_and_saveexec_b64 s[20:21], s[10:11] -> s_cbranch_execz (reuses cached Any vote) -> s_cselect_b32 s30,
; 11, 22 (SCC = 1 -> 11) + 4x contiguous v_readfirstlane_b32 from lane 36 (batched across one data round after
; finding first = 36):
; out[0] = s24 + s30 = 136 + 11 = 147, out[1] = s25 = 308, out[2] = s26 + s27 = 680 + 1152 = 1832.
; 2) Deferred SCC vote coalesced with s_cbranch_execz on distinct masks (opposite polarities):
; 2a) EXEC = s[10:11] (non-zero), s_and_b64 s[18:19], s[10:11], s[14:15] (0 -> SCC = 0), s_cbranch_execz not taken,
; s_cselect_b32 s31, 333, 444 -> out[3] = 444.
; 2b) EXEC = s[18:19] (0), s_or_b64 s[22:23], s[10:11], s[14:15] (non-zero -> SCC = 1), s_cbranch_execz taken over
; s32 = 666 (keeps 555), s_cselect_b32 s33, 70, 80 -> out[4] = 555 + 70 = 625.
; 3) Deferred SCC vote coalesced with cross-half v_readlane_b32 (lane 45 -> v5 = 335, SCC = 1 -> +1000):
; out[5] = 1335.
; 4) Cached EXEC mask from s_bcnt1_i32_b64 (lanes 41..63 -> 23, first = 41) reused by a 1-round 4x v_readfirstlane_b32
; batch (141 + 323 + 705 + 1187), then EXEC rewritten to s[14:15] (first = 8 -> 108 + 224) to check invalidation:
; out[6] = 2379, out[7] = 332.
; Run: vk_compute_test cs_w64x_xround_coalesce.spv 1 dump --require-wave64
; -> out[0..7] = 147 308 1832 444 625 1335 2379 332
; mattr: +wavefrontsize64,-wavefrontsize32
v_mbcnt_lo_u32_b32 v1, -1, 0
v_mbcnt_hi_u32_b32 v1, -1, v1
v_add_nc_u32_e32 v4, 100, v1
v_mul_lo_u32 v5, 3, v1
v_add_nc_u32_e32 v5, 200, v5
v_mul_lo_u32 v6, 5, v1
v_add_nc_u32_e32 v6, 500, v6
v_mul_lo_u32 v7, 7, v1
v_add_nc_u32_e32 v7, 900, v7
v_cmp_ge_u32_e64 s[10:11], v1, 36
v_cmp_lt_u32_e64 s[12:13], v1, 52
s_and_b64 s[10:11], s[10:11], s[12:13]
v_cmp_ge_u32_e64 s[14:15], v1, 8
v_cmp_lt_u32_e64 s[16:17], v1, 24
s_and_b64 s[14:15], s[14:15], s[16:17]
; 1) Live-SCC saveexec + s_cbranch_execz + 4x batched v_readfirstlane_b32
s_mov_b32 s24, 0
s_mov_b32 s25, 0
s_mov_b32 s26, 0
s_mov_b32 s27, 0
s_mov_b32 s30, 0
s_and_saveexec_b64 s[20:21], s[10:11]
s_cbranch_execz 5
s_cselect_b32 s30, 11, 22
v_readfirstlane_b32 s24, v4
v_readfirstlane_b32 s25, v5
v_readfirstlane_b32 s26, v6
v_readfirstlane_b32 s27, v7
s_mov_b64 exec, -1
s_add_i32 s24, s24, s30
s_add_i32 s26, s26, s27
; 2a) Deferred SCC = 0 coalesced with s_cbranch_execz (EXEC != 0)
s_mov_b64 exec, s[10:11]
s_mov_b32 s31, 99
s_mov_b32 s43, 444
s_and_b64 s[18:19], s[10:11], s[14:15]
s_cbranch_execz 2
s_cselect_b32 s31, 333, s43
; 2b) Deferred SCC = 1 coalesced with s_cbranch_execz (EXEC == 0)
s_mov_b64 exec, s[18:19]
s_mov_b32 s32, 555
s_mov_b32 s43, 80
s_or_b64 s[22:23], s[10:11], s[14:15]
s_cbranch_execz 2
s_mov_b32 s32, 666
s_cselect_b32 s33, 70, s43
s_mov_b64 exec, -1
s_add_i32 s32, s32, s33
; 3) Deferred SCC = 1 coalesced with cross-half v_readlane_b32 (lane 45)
s_mov_b32 s43, 2000
s_and_b64 s[22:23], s[10:11], s[10:11]
v_readlane_b32 s34, v5, 45
s_cselect_b32 s35, 1000, s43
s_add_i32 s34, s34, s35
; 4) s_bcnt1 -> 1-round 4x v_readfirstlane_b32 batch, then EXEC rewrite invalidates first-lane cache
v_cmp_ge_u32_e64 s[28:29], v1, 41
s_mov_b64 exec, s[28:29]
s_bcnt1_i32_b64 s36, exec
v_readfirstlane_b32 s37, v4
v_readfirstlane_b32 s38, v5
v_readfirstlane_b32 s39, v6
v_readfirstlane_b32 s40, v7
s_mov_b64 exec, s[14:15]
v_readfirstlane_b32 s41, v4
v_readfirstlane_b32 s42, v5
s_mov_b64 exec, -1
s_add_i32 s36, s36, s37
s_add_i32 s36, s36, s38
s_add_i32 s36, s36, s39
s_add_i32 s36, s36, s40
s_add_i32 s41, s41, s42
v_cmpx_eq_u32_e32 0, v1
v_mov_b32_e32 v20, s24
v_mov_b32_e32 v21, 0
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, s25
v_mov_b32_e32 v21, 4
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, s26
v_mov_b32_e32 v21, 8
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, s31
v_mov_b32_e32 v21, 12
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, s32
v_mov_b32_e32 v21, 16
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, s34
v_mov_b32_e32 v21, 20
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, s36
v_mov_b32_e32 v21, 24
buffer_store_dword v20, v21, s[0:3], 0 offen
v_mov_b32_e32 v20, s41
v_mov_b32_e32 v21, 28
buffer_store_dword v20, v21, s[0:3], 0 offen
s_endpgm
3 changes: 2 additions & 1 deletion scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ def run_suite(a, work: str) -> int:
"cs_w64x_lds_war", "cs_w64x_partial", "cs_w64x_sbarrier", "cs_w64x_load_ballot_load",
"cs_w64x_mask_reuse", "cs_w64x_mask_reuse2", "cs_w64x_chain_barrier", "cs_barrier_divergent",
"cs_bpermute32", "cs_w64x_partial_scmp", "cs_w64x_partial_swizzle", "cs_w32_partial_scmp", "cs_w32_partial_permute", "cs_barrier_early_end",
"cs_barrier_loop", "cs_w64x_andn2_exec", "cs_w64x_saveexec_b64", "cs_w64x_cmp_sdst", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_wrxchg2_ext", "cs_w32_wrxchg2st64", "cs_w32_andn2_exec",
"cs_barrier_loop", "cs_w64x_andn2_exec", "cs_w64x_saveexec_b64", "cs_w64x_cmp_sdst", "cs_w64x_xround_coalesce", "cs_lds_b64_cmpst", "cs_lds_xchg64_ext", "cs_lds_atomics_ext", "cs_w32_wrxchg2_ext", "cs_w32_wrxchg2st64", "cs_w32_andn2_exec",
"cs_mask_vgpr_exec", "cs_w32_exec_computed", "cs_w64_exec_computed"):
cs_dump_wants = {
"cs_store": [0x400080FF, 0xE00003FF, 0x3C004000, 0xEEEEEEEE, 0x40003C00, 0xBC003800, 0x40FF8000, 0x3FF00000],
Expand Down Expand Up @@ -1301,6 +1301,7 @@ def run_suite(a, work: str) -> int:
"cs_w64x_branch": [0, 0, 0, 0, 5, 5, 9, 9],
"cs_w64x_mask_reuse": [8, 40, 8, 40, 2, 20, 10, 64],
"cs_w64x_mask_reuse2": [10, 20, 8, 8, 5, 2, 132, 131],
"cs_w64x_xround_coalesce": [147, 308, 1832, 444, 625, 1335, 2379, 332],
"cs_w64x_chain_barrier": [564, 563, 500, 627],
"cs_w64x_ballot": [2053, 2061, 2069, 2077, 2085, 2093, 2101, 2109],
"cs_w64x_wg128_branches": [121, 121, 343, 343, 14, 31, 19812, 22728],
Expand Down
11 changes: 5 additions & 6 deletions tests/semantic/test_wave64_emulate_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,12 +1582,11 @@ def test_known_pc_guard_unwrap_and_x_pre_helper_functions(self):
top_kinds = [(it[0], it[1]) for it in gen.emulate_plan["tree"]]
# Blocks 0, 2, 4 are all direct top-level ("block", b) items; only blocks 1 and 3 are guarded!
self.assertEqual(top_kinds, [("block", 0), ("guard", 1), ("block", 2), ("guard", 3), ("block", 4)])
self.assertIn("%x_pre_vote_fn = OpFunction", spv)
self.assertIn("%x_pre_both_fn = OpFunction", spv)
self.assertIn("%x_pre_data_fn = OpFunction", spv)
self.assertGreaterEqual(spv.count("OpFunctionCall %uint %x_pre_vote_fn"), 2)
self.assertEqual(spv.count("OpFunctionCall %uint %x_pre_both_fn"), 1)
self.assertEqual(spv.count("OpFunctionCall %uint %x_pre_data_fn"), 1)
# Inline x_round emits direct division-free mod-6 exchanges with 0x108 WorkgroupMemory barriers (no %x_pre_*_fn calls).
self.assertNotIn("%x_pre_", spv)
self.assertEqual(spv.count("OpFunctionCall"), 0)
self.assertEqual(spv.count("OpUMod"), 0)
self.assertGreaterEqual(spv.count("OpControlBarrier %c2 %c2 %c108"), 4)
# Verify binary SPIR-V assembly with tools/spirv_asm.py
import spirv_asm
binary = spirv_asm.assemble(spv, target_env="vulkan1.2")
Expand Down
Loading
Loading