wgpu-shift 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gpu_shift/__init__.py +19 -0
- gpu_shift/__main__.py +8 -0
- gpu_shift/_capturer.py +191 -0
- gpu_shift/_scanner.py +71 -0
- gpu_shift/bench.py +321 -0
- gpu_shift/capture.py +669 -0
- gpu_shift/check.py +224 -0
- gpu_shift/cli.py +609 -0
- gpu_shift/demo.py +272 -0
- gpu_shift/device.py +170 -0
- gpu_shift/diff.py +510 -0
- gpu_shift/manifest.py +171 -0
- gpu_shift/mcp_server.py +352 -0
- gpu_shift/report.py +218 -0
- gpu_shift/run.py +206 -0
- gpu_shift/runtime.py +592 -0
- gpu_shift/scan.py +380 -0
- gpu_shift/setup.py +245 -0
- gpu_shift/skill_data/SKILL.md +56 -0
- gpu_shift/stage.py +248 -0
- gpu_shift/switch.py +268 -0
- wgpu_shift-0.1.0.dist-info/METADATA +125 -0
- wgpu_shift-0.1.0.dist-info/RECORD +26 -0
- wgpu_shift-0.1.0.dist-info/WHEEL +4 -0
- wgpu_shift-0.1.0.dist-info/entry_points.txt +3 -0
- wgpu_shift-0.1.0.dist-info/licenses/LICENSE +21 -0
gpu_shift/check.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""Single pass/fail release check for a gpu-shift port unit."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from gpu_shift.bench import bench_unit
|
|
9
|
+
from gpu_shift.capture import load_captured_cases
|
|
10
|
+
from gpu_shift.diff import diff_unit
|
|
11
|
+
from gpu_shift.manifest import (
|
|
12
|
+
is_source_stale,
|
|
13
|
+
load_manifest,
|
|
14
|
+
load_port_function,
|
|
15
|
+
save_manifest,
|
|
16
|
+
)
|
|
17
|
+
from gpu_shift.runtime import snapshot_vram, validate_wgsl
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class CheckItem:
|
|
22
|
+
"""Result of one deterministic release check criterion."""
|
|
23
|
+
|
|
24
|
+
name: str
|
|
25
|
+
passed: bool
|
|
26
|
+
detail: str
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class CheckResult:
|
|
31
|
+
"""Aggregate pass/fail decision for a unit."""
|
|
32
|
+
|
|
33
|
+
unit_dir: Path
|
|
34
|
+
unit_name: str
|
|
35
|
+
passed: bool
|
|
36
|
+
checks: tuple[CheckItem, ...]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def check_unit(
|
|
40
|
+
unit_dir: Path,
|
|
41
|
+
*,
|
|
42
|
+
require_speedup: bool = False,
|
|
43
|
+
min_speedup: float = 1.1,
|
|
44
|
+
) -> CheckResult:
|
|
45
|
+
"""Verify freshness, shader compilation, numerical diff, and VRAM cleanup."""
|
|
46
|
+
resolved = unit_dir.resolve()
|
|
47
|
+
manifest = load_manifest(resolved)
|
|
48
|
+
checks: list[CheckItem] = []
|
|
49
|
+
|
|
50
|
+
# 1. Required unit files exist
|
|
51
|
+
wgsl_path = resolved / "kernel.wgsl"
|
|
52
|
+
port_path = resolved / "port.py"
|
|
53
|
+
cases_index = resolved / "cases" / "index.json"
|
|
54
|
+
missing = [
|
|
55
|
+
p.name for p in (wgsl_path, port_path, cases_index) if not p.is_file()
|
|
56
|
+
]
|
|
57
|
+
checks.append(
|
|
58
|
+
CheckItem(
|
|
59
|
+
name="files_present",
|
|
60
|
+
passed=len(missing) == 0,
|
|
61
|
+
detail="All unit files present"
|
|
62
|
+
if not missing
|
|
63
|
+
else f"Missing: {', '.join(missing)}",
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# 2. Source freshness (not stale)
|
|
68
|
+
stale = is_source_stale(resolved, manifest)
|
|
69
|
+
checks.append(
|
|
70
|
+
CheckItem(
|
|
71
|
+
name="source_fresh",
|
|
72
|
+
passed=not stale,
|
|
73
|
+
detail="Original source matches captured SHA-256"
|
|
74
|
+
if not stale
|
|
75
|
+
else "Original source changed since last capture; re-run `gpu-shift capture`",
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# 3. WGSL compiles cleanly
|
|
80
|
+
if wgsl_path.is_file():
|
|
81
|
+
wgsl_ok, wgsl_err = validate_wgsl(
|
|
82
|
+
wgsl_path.read_text(encoding="utf-8"),
|
|
83
|
+
power_preference=manifest.power_preference,
|
|
84
|
+
)
|
|
85
|
+
checks.append(
|
|
86
|
+
CheckItem(
|
|
87
|
+
name="wgsl_valid",
|
|
88
|
+
passed=wgsl_ok,
|
|
89
|
+
detail="WGSL compute pipeline compiled cleanly"
|
|
90
|
+
if wgsl_ok
|
|
91
|
+
else str(wgsl_err),
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
else:
|
|
95
|
+
checks.append(
|
|
96
|
+
CheckItem(name="wgsl_valid", passed=False, detail="kernel.wgsl missing")
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# 4 & 5. Numerical diff + multi-call native VRAM / object leak soak check
|
|
100
|
+
if not missing and not stale:
|
|
101
|
+
diff_res = diff_unit(resolved)
|
|
102
|
+
|
|
103
|
+
if diff_res.passed:
|
|
104
|
+
diff_detail = (
|
|
105
|
+
f"{diff_res.passed_count}/{diff_res.total_count} cases passed "
|
|
106
|
+
f"(max_abs_err={diff_res.max_abs_err:.2e})"
|
|
107
|
+
)
|
|
108
|
+
else:
|
|
109
|
+
first_fail = next((c for c in diff_res.cases if not c.passed), None)
|
|
110
|
+
diff_detail = (
|
|
111
|
+
diff_res.error
|
|
112
|
+
or (
|
|
113
|
+
f"{diff_res.passed_count}/{diff_res.total_count} passed; "
|
|
114
|
+
f"first failure [{first_fail.label}]: {first_fail.reason}"
|
|
115
|
+
if first_fail is not None
|
|
116
|
+
else "Diff failed"
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
checks.append(
|
|
120
|
+
CheckItem(name="diff_passed", passed=diff_res.passed, detail=diff_detail)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Soak-test the loaded port across repeated calls to catch real wgpu-native
|
|
124
|
+
# buffer, texture, bind-group, shader, or VRAM leaks (even if port.py bypasses
|
|
125
|
+
# ComputeKernel).
|
|
126
|
+
vram_ok = False
|
|
127
|
+
vram_detail = "Skipped because diff did not pass"
|
|
128
|
+
if diff_res.passed:
|
|
129
|
+
_, cases = load_captured_cases(resolved)
|
|
130
|
+
soak_case = next((c for c in cases if c.kind == "captured"), cases[0])
|
|
131
|
+
port_fn = load_port_function(resolved, manifest)
|
|
132
|
+
# Warm up once so one-time cached pipeline/shader objects are created
|
|
133
|
+
port_fn(*soak_case.args, **soak_case.kwargs)
|
|
134
|
+
before = snapshot_vram(run_gc=True)
|
|
135
|
+
soak_iters = 15
|
|
136
|
+
for _ in range(soak_iters):
|
|
137
|
+
port_fn(*soak_case.args, **soak_case.kwargs)
|
|
138
|
+
after = snapshot_vram(run_gc=True)
|
|
139
|
+
|
|
140
|
+
delta_kernel = after.kernel_active_buffers - before.kernel_active_buffers
|
|
141
|
+
delta_bufs = after.wgpu_buffers - before.wgpu_buffers
|
|
142
|
+
delta_tex = after.wgpu_textures - before.wgpu_textures
|
|
143
|
+
delta_bg = after.wgpu_bind_groups - before.wgpu_bind_groups
|
|
144
|
+
delta_pipe = after.wgpu_pipelines - before.wgpu_pipelines
|
|
145
|
+
delta_shader = after.wgpu_shaders - before.wgpu_shaders
|
|
146
|
+
delta_mem = after.resource_mem_bytes - before.resource_mem_bytes
|
|
147
|
+
|
|
148
|
+
vram_ok = (
|
|
149
|
+
after.kernel_active_buffers == 0
|
|
150
|
+
and delta_kernel == 0
|
|
151
|
+
and delta_bufs <= 0
|
|
152
|
+
and delta_tex <= 0
|
|
153
|
+
and delta_bg <= 0
|
|
154
|
+
and delta_pipe <= 0
|
|
155
|
+
and delta_shader <= 0
|
|
156
|
+
and delta_mem <= 0
|
|
157
|
+
)
|
|
158
|
+
if vram_ok:
|
|
159
|
+
vram_detail = (
|
|
160
|
+
f"0 leaked GPU objects / 0 B VRAM growth across {soak_iters} dispatches "
|
|
161
|
+
f"(live buffers={after.wgpu_buffers}, resource_mem={after.resource_mem_bytes} B)"
|
|
162
|
+
)
|
|
163
|
+
else:
|
|
164
|
+
vram_detail = (
|
|
165
|
+
f"GPU resource leak detected across {soak_iters} dispatches: "
|
|
166
|
+
f"delta_buffers={delta_bufs}, delta_textures={delta_tex}, "
|
|
167
|
+
f"delta_bind_groups={delta_bg}, delta_pipelines={delta_pipe}, "
|
|
168
|
+
f"delta_shaders={delta_shader}, delta_vram={delta_mem} B"
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
checks.append(
|
|
172
|
+
CheckItem(
|
|
173
|
+
name="vram_clean",
|
|
174
|
+
passed=vram_ok,
|
|
175
|
+
detail=vram_detail,
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
else:
|
|
179
|
+
checks.append(
|
|
180
|
+
CheckItem(
|
|
181
|
+
name="diff_passed",
|
|
182
|
+
passed=False,
|
|
183
|
+
detail="Skipped because prerequisites failed",
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
checks.append(
|
|
187
|
+
CheckItem(
|
|
188
|
+
name="vram_clean",
|
|
189
|
+
passed=False,
|
|
190
|
+
detail="Skipped because diff did not run",
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
# 6. Optional real-hardware speedup requirement
|
|
195
|
+
if require_speedup:
|
|
196
|
+
if all(c.passed for c in checks):
|
|
197
|
+
bench_res = bench_unit(resolved, update_manifest=True)
|
|
198
|
+
speed_ok = bench_res.max_speedup >= min_speedup
|
|
199
|
+
checks.append(
|
|
200
|
+
CheckItem(
|
|
201
|
+
name="bench_speedup",
|
|
202
|
+
passed=speed_ok,
|
|
203
|
+
detail=bench_res.verdict,
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
else:
|
|
207
|
+
checks.append(
|
|
208
|
+
CheckItem(
|
|
209
|
+
name="bench_speedup",
|
|
210
|
+
passed=False,
|
|
211
|
+
detail="Skipped because correctness checks failed",
|
|
212
|
+
)
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
overall = all(c.passed for c in checks)
|
|
216
|
+
manifest.last_check_passed = overall
|
|
217
|
+
save_manifest(resolved, manifest)
|
|
218
|
+
|
|
219
|
+
return CheckResult(
|
|
220
|
+
unit_dir=resolved,
|
|
221
|
+
unit_name=manifest.name,
|
|
222
|
+
passed=overall,
|
|
223
|
+
checks=tuple(checks),
|
|
224
|
+
)
|