diff options
Diffstat (limited to 'scripts/bench_wave64.py')
| -rw-r--r-- | scripts/bench_wave64.py | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/scripts/bench_wave64.py b/scripts/bench_wave64.py index 72a8bf742..e6fd59737 100644 --- a/scripts/bench_wave64.py +++ b/scripts/bench_wave64.py | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | """Time a wave64 compute shader (runtime/test/shaders/cs_bench_mix.asm) native and emulated, on the AMD and NVIDIA GPU. | 1 | """Time a wave64 compute shader (runtime/test/shaders/cs_bench_mix.asm) on AMD/NVIDIA or the current Vulkan device. |
| 2 | 2 | ||
| 3 | python -I scripts/bench_wave64.py [--build DIR] [--llvm-mc PATH] [--groups N] [--reps N] [--procs N] [--shader NAME] | 3 | python -I scripts/bench_wave64.py [--build DIR] [--llvm-mc PATH] [--groups N] [--reps N] [--procs N] |
| 4 | [--shader NAME] [--emulated-only] | ||
| 4 | 5 | ||
| 5 | Three configurations: AMD with its native 64-wide subgroup (no flag), AMD with --wave64-emulate, NVIDIA with | 6 | Three configurations: AMD with its native 64-wide subgroup (no flag), AMD with --wave64-emulate, NVIDIA with |
| 6 | --wave64-emulate (the GPU is chosen with VK_LOADER_DRIVERS_SELECT='*amd*,*radeon*' / '*nv*'). Each runs `procs` processes of | 7 | --wave64-emulate (the GPU is chosen with VK_LOADER_DRIVERS_SELECT='*amd*,*radeon*' / '*nv*'). Each runs `procs` processes of |
| @@ -8,6 +9,10 @@ vk_compute_test with VKC_BENCH=`reps` timed dispatches of `groups` workgroups; t | |||
| 8 | dispatches, the spread of the per-process medians (other programs share the GPU, so look at it), the number of | 9 | dispatches, the spread of the per-process medians (other programs share the GPU, so look at it), the number of |
| 9 | translated segments (static: blocks + continuation segments; every continuation segment is one more workgroup barrier | 10 | translated segments (static: blocks + continuation segments; every continuation segment is one more workgroup barrier |
| 10 | on the path through it) and whether the output bytes of the emulated runs equal the native AMD run, which is the reference (they must). | 11 | on the path through it) and whether the output bytes of the emulated runs equal the native AMD run, which is the reference (they must). |
| 12 | |||
| 13 | With --emulated-only, run one emulated configuration on the current Vulkan device. This is for a machine without a | ||
| 14 | native 64-wide subgroup, such as Apple Silicon. Every process must complete the shader's self-check and return the same | ||
| 15 | output hash; there is deliberately no claim that the hash was compared with a native Wave64 device. | ||
| 11 | """ | 16 | """ |
| 12 | import argparse | 17 | import argparse |
| 13 | import json | 18 | import json |
| @@ -27,6 +32,7 @@ from check import EXE, pick_build_dir # noqa: E402 | |||
| 27 | COMPUTE_TEST = "vk_compute_test" + EXE | 32 | COMPUTE_TEST = "vk_compute_test" + EXE |
| 28 | CONFIGS = [("AMD native", "*amd*,*radeon*", False), ("AMD --wave64-emulate", "*amd*,*radeon*", True), | 33 | CONFIGS = [("AMD native", "*amd*,*radeon*", False), ("AMD --wave64-emulate", "*amd*,*radeon*", True), |
| 29 | ("NVIDIA --wave64-emulate", "*nv*", True)] | 34 | ("NVIDIA --wave64-emulate", "*nv*", True)] |
| 35 | EMULATED_ONLY_CONFIG = ("Current device --wave64-emulate", None, True) | ||
| 30 | 36 | ||
| 31 | 37 | ||
| 32 | def build(work, name, emulate, llvm_mc): | 38 | def build(work, name, emulate, llvm_mc): |
| @@ -54,7 +60,9 @@ def segments(spv: str) -> tuple[int, int] | None: | |||
| 54 | 60 | ||
| 55 | 61 | ||
| 56 | def run(tools, spv, groups, reps, driver, emulate): | 62 | def run(tools, spv, groups, reps, driver, emulate): |
| 57 | env = dict(os.environ, VK_LOADER_DRIVERS_SELECT=driver, VKC_BENCH=str(reps)) | 63 | env = dict(os.environ, VKC_BENCH=str(reps)) |
| 64 | if driver is not None: | ||
| 65 | env["VK_LOADER_DRIVERS_SELECT"] = driver | ||
| 58 | args = [os.path.join(tools, COMPUTE_TEST), spv, str(groups), "dump"] | 66 | args = [os.path.join(tools, COMPUTE_TEST), spv, str(groups), "dump"] |
| 59 | if not emulate: | 67 | if not emulate: |
| 60 | args.append("--require-wave64") | 68 | args.append("--require-wave64") |
| @@ -89,16 +97,20 @@ def main(): | |||
| 89 | ap.add_argument("--reps", type=positive_int, default=30) | 97 | ap.add_argument("--reps", type=positive_int, default=30) |
| 90 | ap.add_argument("--procs", type=positive_int, default=5) | 98 | ap.add_argument("--procs", type=positive_int, default=5) |
| 91 | ap.add_argument("--shader", default="cs_bench_mix") | 99 | ap.add_argument("--shader", default="cs_bench_mix") |
| 100 | ap.add_argument("--emulated-only", action="store_true", | ||
| 101 | help="benchmark Wave64 emulation on the current device without requiring a native AMD reference") | ||
| 92 | a = ap.parse_args() | 102 | a = ap.parse_args() |
| 103 | configs = [EMULATED_ONLY_CONFIG] if a.emulated_only else CONFIGS | ||
| 93 | tools = pick_build_dir(a.build, (COMPUTE_TEST,)) | 104 | tools = pick_build_dir(a.build, (COMPUTE_TEST,)) |
| 94 | with tempfile.TemporaryDirectory(prefix="bench-w64-") as work: | 105 | with tempfile.TemporaryDirectory(prefix="bench-w64-") as work: |
| 95 | spv = {False: build(work, a.shader, False, a.llvm_mc), True: build(work, a.shader, True, a.llvm_mc)} | 106 | modes = sorted({emulate for _, _, emulate in configs}) |
| 107 | spv = {emulate: build(work, a.shader, emulate, a.llvm_mc) for emulate in modes} | ||
| 96 | seg = segments(spv[True]) | 108 | seg = segments(spv[True]) |
| 97 | print(f"{a.shader}: {a.groups} workgroups of the shader's group size, {a.procs} x {a.reps} timed dispatches") | 109 | print(f"{a.shader}: {a.groups} workgroups of the shader's group size, {a.procs} x {a.reps} timed dispatches") |
| 98 | if seg: | 110 | if seg: |
| 99 | print(f"emulated: {seg[0]} segments, {seg[1]} of them continuation segments (one extra round each)") | 111 | print(f"emulated: {seg[0]} segments, {seg[1]} of them continuation segments (one extra round each)") |
| 100 | hashes, rows = {}, [] | 112 | hashes, rows = {}, [] |
| 101 | for name, driver, emulate in CONFIGS: | 113 | for name, driver, emulate in configs: |
| 102 | med, mins, seen, dev = [], [], set(), None | 114 | med, mins, seen, dev = [], [], set(), None |
| 103 | for _ in range(a.procs): | 115 | for _ in range(a.procs): |
| 104 | t, h, dev = run(tools, spv[emulate], a.groups, a.reps, driver, emulate) | 116 | t, h, dev = run(tools, spv[emulate], a.groups, a.reps, driver, emulate) |
| @@ -116,13 +128,24 @@ def main(): | |||
| 116 | rows.append((name, dev, statistics.median(med), min(mins), min(med), max(med))) | 128 | rows.append((name, dev, statistics.median(med), min(mins), min(med), max(med))) |
| 117 | for name, dev, m, lo, a_, b_ in rows: | 129 | for name, dev, m, lo, a_, b_ in rows: |
| 118 | print(f"{name:26} {dev:34} median {m:8.3f} ms best {lo:8.3f} process medians {a_:.3f}..{b_:.3f}") | 130 | print(f"{name:26} {dev:34} median {m:8.3f} ms best {lo:8.3f} process medians {a_:.3f}..{b_:.3f}") |
| 119 | ref_name = CONFIGS[0][0] | 131 | if a.emulated_only: |
| 132 | name = EMULATED_ONLY_CONFIG[0] | ||
| 133 | result = hashes.get(name) | ||
| 134 | if not result: | ||
| 135 | print(f"no complete result from {name}") | ||
| 136 | return 1 | ||
| 137 | if len(result) != 1: | ||
| 138 | print(f"OUTPUT HASH CHANGED between processes: {', '.join(sorted(result))}") | ||
| 139 | return 1 | ||
| 140 | print(f"stable output hash: {next(iter(result))} (self-checked; no native reference)") | ||
| 141 | return 0 | ||
| 142 | ref_name = configs[0][0] | ||
| 120 | ref = hashes.get(ref_name) | 143 | ref = hashes.get(ref_name) |
| 121 | if not ref or len(ref) != 1: | 144 | if not ref or len(ref) != 1: |
| 122 | print(f"no reference output from {ref_name}: cannot compare") | 145 | print(f"no reference output from {ref_name}: cannot compare") |
| 123 | return 1 | 146 | return 1 |
| 124 | bad = [n for n, _, _ in CONFIGS[1:] if n in hashes and hashes[n] != ref] | 147 | bad = [n for n, _, _ in configs[1:] if n in hashes and hashes[n] != ref] |
| 125 | missing = [n for n, _, _ in CONFIGS[1:] if n not in hashes] | 148 | missing = [n for n, _, _ in configs[1:] if n not in hashes] |
| 126 | print(f"reference output hash: {next(iter(ref))} ({ref_name})") | 149 | print(f"reference output hash: {next(iter(ref))} ({ref_name})") |
| 127 | if bad: | 150 | if bad: |
| 128 | print(f"OUTPUT DIFFERS from the reference: {', '.join(bad)}") | 151 | print(f"OUTPUT DIFFERS from the reference: {', '.join(bad)}") |