Skip to content
Merged
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
3 changes: 2 additions & 1 deletion runtime/test/shaders/cs_w32_lds_u8_d16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
; Run: vk_compute_test cs_w32_lds_u8_d16.spv 1 dump
; -> out[0..7] = 0xBEEF00FF 0x00FF1234 0xBEEFFF80 0xFF801234 0xBEEF007F 0x007F1234 0xBEEF0080 0xFFFF1234
; mattr: +wavefrontsize32,-wavefrontsize64
; Only lane 0 accesses LDS and writes output; identical writes from all lanes would still race.
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v2, 0
v_mov_b32_e32 v3, 0x7f80ff01
ds_write_b32 v2, v3
Expand All @@ -36,7 +38,6 @@ ds_read_u8_d16 v16, v1 offset:2
v_mov_b32_e32 v1, 1
ds_read_i8_d16_hi v17, v1
s_waitcnt lgkmcnt(0)
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v21, 0
buffer_store_dword v10, v21, s[0:3], 0 offen
v_mov_b32_e32 v21, 4
Expand Down
2 changes: 1 addition & 1 deletion tests/semantic/fixtures/disasm/cs_w32_lds_u8_d16.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; cs_w32_lds_u8_d16 test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/cs_w32_lds_u8_d16.asm
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v2, 0
v_mov_b32_e32 v3, 0x7f80ff01
ds_write_b32 v2, v3
Expand All @@ -22,7 +23,6 @@
v_mov_b32_e32 v1, 1
ds_read_i8_d16_hi v17, v1
s_waitcnt lgkmcnt(0)
v_cmpx_eq_u32_e32 0, v0
v_mov_b32_e32 v21, 0
buffer_store_dword v10, v21, s[0:3], 0 offen
v_mov_b32_e32 v21, 4
Expand Down
34 changes: 31 additions & 3 deletions tests/semantic/test_lds_read_u8_d16.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

The input is the GPU test runtime/test/shaders/cs_w32_lds_u8_d16.asm (fixture from regen_fixtures.py): it stores
LDS dword 0 = 0x7F80FF01, presets every destination to 0xBEEF1234 and reads single bytes with a non-zero offset
or base. It is translated for wave32 and run as one invocation (lane 0); the eight words it stores are compared
with values derived here from the ISA text above (the same values check.py / run_gpu_tests.py expect).
or base. It is translated for wave32 and run as the full 32-invocation workgroup; only lane 0 accesses LDS and
stores output. The eight words are compared with values derived here from the ISA text above (the same values
check.py / run_gpu_tests.py expect).
"""
import struct
import unittest
from unittest import mock

import support
import spirv_mini_interp as si
Expand Down Expand Up @@ -61,7 +63,7 @@ def to_hi(old, h):
def run():
spv = support.translate_fixture("cs_w32_lds_u8_d16", fssm=FSSM)
memory = si.run_workgroup(
spv, 1, 32,
spv, 32, 32,
inputs_for=lambda i: {"%wg_id": (0, 0, 0), "%local_id": (i, 0, 0), "%sg_lane": i},
push_constants=VSHARP + [0] * 28, memory={})
stray = sorted(a for a in memory if not 0 <= a < 32 or a % 4)
Expand All @@ -81,6 +83,32 @@ def test_translated_shader(self):
with self.subTest(word=k):
self.assertEqual(g, w, f"out[{k}] = {g if g is None else hex(g)}, want {hex(w)}")

def test_only_one_lds_store_in_full_workgroup(self):
# The interpreter deliberately serializes racing LDS stores, so correct output alone cannot catch
# multiple lanes writing the same value. Observe writes to its shared Workgroup array instead.
writes = []

class TrackedWords(list):
def __setitem__(self, index, value):
writes.append((index, value))
super().__setitem__(index, value)

class TrackedWorkgroup(dict):
def __setitem__(self, name, box):
box[0] = TrackedWords(box[0])
super().__setitem__(name, box)

workgroup = TrackedWorkgroup()
invocation = si._invocation

def tracked_invocation(*args, **kwargs):
kwargs["workgroup"] = workgroup
return invocation(*args, **kwargs)

with mock.patch.object(si, "_invocation", side_effect=tracked_invocation):
self.assertEqual(run(), EXPECTED)
self.assertEqual(writes, [(0, 0x7F80FF01)])


if __name__ == "__main__":
unittest.main()
Loading