wgpu-shift 0.1.0__tar.gz

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.
Files changed (185) hide show
  1. wgpu_shift-0.1.0/.github/workflows/ci.yml +27 -0
  2. wgpu_shift-0.1.0/.github/workflows/publish.yml +38 -0
  3. wgpu_shift-0.1.0/.gitignore +22 -0
  4. wgpu_shift-0.1.0/CONTRIBUTING.md +43 -0
  5. wgpu_shift-0.1.0/DECISIONS.md +16 -0
  6. wgpu_shift-0.1.0/LICENSE +21 -0
  7. wgpu_shift-0.1.0/PKG-INFO +125 -0
  8. wgpu_shift-0.1.0/README.md +97 -0
  9. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/TASK.md +37 -0
  10. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_000.npz +0 -0
  11. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_001.npz +0 -0
  12. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_002.npz +0 -0
  13. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_003.npz +0 -0
  14. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_004.npz +0 -0
  15. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_005.npz +0 -0
  16. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_006.npz +0 -0
  17. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/case_007.npz +0 -0
  18. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/cases/index.json +306 -0
  19. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/kernel.wgsl +150 -0
  20. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/manifest.json +13 -0
  21. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_cdist/port.py +36 -0
  22. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/TASK.md +37 -0
  23. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_000.npz +0 -0
  24. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_001.npz +0 -0
  25. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_002.npz +0 -0
  26. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_003.npz +0 -0
  27. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_004.npz +0 -0
  28. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_005.npz +0 -0
  29. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_006.npz +0 -0
  30. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/case_007.npz +0 -0
  31. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/cases/index.json +306 -0
  32. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/kernel.wgsl +119 -0
  33. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/manifest.json +13 -0
  34. wgpu_shift-0.1.0/benchmarks/real_world/kernels/scipy_convolve2d/port.py +34 -0
  35. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/TASK.md +47 -0
  36. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_000.npz +0 -0
  37. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_001.npz +0 -0
  38. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_002.npz +0 -0
  39. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_003.npz +0 -0
  40. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_004.npz +0 -0
  41. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_005.npz +0 -0
  42. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_006.npz +0 -0
  43. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/case_007.npz +0 -0
  44. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/cases/index.json +233 -0
  45. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/kernel.wgsl +132 -0
  46. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/manifest.json +13 -0
  47. wgpu_shift-0.1.0/benchmarks/real_world/kernels/skimage_bilateral/port.py +89 -0
  48. wgpu_shift-0.1.0/benchmarks/real_world/run_all.py +189 -0
  49. wgpu_shift-0.1.0/benchmarks/real_world/scipy_cdist.py +20 -0
  50. wgpu_shift-0.1.0/benchmarks/real_world/scipy_convolve2d.py +20 -0
  51. wgpu_shift-0.1.0/benchmarks/real_world/skimage_bilateral.py +29 -0
  52. wgpu_shift-0.1.0/docs/README_TR.md +97 -0
  53. wgpu_shift-0.1.0/docs/assets/banner-dark.png +0 -0
  54. wgpu_shift-0.1.0/docs/assets/banner.png +0 -0
  55. wgpu_shift-0.1.0/docs/assets/check.gif +0 -0
  56. wgpu_shift-0.1.0/docs/assets/demo.gif +0 -0
  57. wgpu_shift-0.1.0/docs/assets/logo.png +0 -0
  58. wgpu_shift-0.1.0/docs/how-it-works.md +67 -0
  59. wgpu_shift-0.1.0/docs/real-world.md +59 -0
  60. wgpu_shift-0.1.0/evals/README.md +26 -0
  61. wgpu_shift-0.1.0/evals/audio_smooth/demo.py +18 -0
  62. wgpu_shift-0.1.0/evals/audio_smooth/reference/kernel.wgsl +44 -0
  63. wgpu_shift-0.1.0/evals/audio_smooth/reference/port.py +30 -0
  64. wgpu_shift-0.1.0/evals/audio_smooth/task.py +28 -0
  65. wgpu_shift-0.1.0/evals/cosine_similarity/demo.py +18 -0
  66. wgpu_shift-0.1.0/evals/cosine_similarity/reference/kernel.wgsl +53 -0
  67. wgpu_shift-0.1.0/evals/cosine_similarity/reference/port.py +27 -0
  68. wgpu_shift-0.1.0/evals/cosine_similarity/task.py +26 -0
  69. wgpu_shift-0.1.0/evals/image_edges/demo.py +17 -0
  70. wgpu_shift-0.1.0/evals/image_edges/reference/kernel.wgsl +49 -0
  71. wgpu_shift-0.1.0/evals/image_edges/reference/port.py +25 -0
  72. wgpu_shift-0.1.0/evals/image_edges/task.py +26 -0
  73. wgpu_shift-0.1.0/evals/rgb_contrast/demo.py +17 -0
  74. wgpu_shift-0.1.0/evals/rgb_contrast/reference/kernel.wgsl +51 -0
  75. wgpu_shift-0.1.0/evals/rgb_contrast/reference/port.py +28 -0
  76. wgpu_shift-0.1.0/evals/rgb_contrast/task.py +24 -0
  77. wgpu_shift-0.1.0/evals/row_softmax/demo.py +17 -0
  78. wgpu_shift-0.1.0/evals/row_softmax/reference/kernel.wgsl +162 -0
  79. wgpu_shift-0.1.0/evals/row_softmax/reference/port.py +26 -0
  80. wgpu_shift-0.1.0/evals/row_softmax/task.py +23 -0
  81. wgpu_shift-0.1.0/evals/run_evals.py +323 -0
  82. wgpu_shift-0.1.0/evals/running_total/demo.py +17 -0
  83. wgpu_shift-0.1.0/evals/running_total/task.py +18 -0
  84. wgpu_shift-0.1.0/evals/scale_and_bounds/demo.py +17 -0
  85. wgpu_shift-0.1.0/evals/scale_and_bounds/reference/kernel.wgsl +33 -0
  86. wgpu_shift-0.1.0/evals/scale_and_bounds/reference/port.py +35 -0
  87. wgpu_shift-0.1.0/evals/scale_and_bounds/task.py +32 -0
  88. wgpu_shift-0.1.0/evals/small_clamp/demo.py +17 -0
  89. wgpu_shift-0.1.0/evals/small_clamp/reference/kernel.wgsl +44 -0
  90. wgpu_shift-0.1.0/evals/small_clamp/reference/port.py +28 -0
  91. wgpu_shift-0.1.0/evals/small_clamp/task.py +15 -0
  92. wgpu_shift-0.1.0/evals/tasks.json +90 -0
  93. wgpu_shift-0.1.0/examples/denoise/demo.py +50 -0
  94. wgpu_shift-0.1.0/examples/denoise/denoise.py +43 -0
  95. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/TASK.md +68 -0
  96. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_000.npz +0 -0
  97. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_001.npz +0 -0
  98. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_002.npz +0 -0
  99. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_003.npz +0 -0
  100. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_004.npz +0 -0
  101. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_005.npz +0 -0
  102. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_006.npz +0 -0
  103. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/case_007.npz +0 -0
  104. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/cases/index.json +337 -0
  105. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/kernel.wgsl +112 -0
  106. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/manifest.json +13 -0
  107. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/port.py +45 -0
  108. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/report/REPORT.md +33 -0
  109. wgpu_shift-0.1.0/examples/denoise/kernels/bilateral_filter/report/card.svg +32 -0
  110. wgpu_shift-0.1.0/examples/nbody/demo.py +28 -0
  111. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/TASK.md +56 -0
  112. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_000.npz +0 -0
  113. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_001.npz +0 -0
  114. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_002.npz +0 -0
  115. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_003.npz +0 -0
  116. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_004.npz +0 -0
  117. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_005.npz +0 -0
  118. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_006.npz +0 -0
  119. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/case_007.npz +0 -0
  120. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/cases/index.json +338 -0
  121. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/kernel.wgsl +110 -0
  122. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/manifest.json +13 -0
  123. wgpu_shift-0.1.0/examples/nbody/kernels/nbody_accel/port.py +38 -0
  124. wgpu_shift-0.1.0/examples/nbody/nbody.py +31 -0
  125. wgpu_shift-0.1.0/examples/pairwise/demo.py +29 -0
  126. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/TASK.md +49 -0
  127. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_000.npz +0 -0
  128. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_001.npz +0 -0
  129. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_002.npz +0 -0
  130. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_003.npz +0 -0
  131. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_004.npz +0 -0
  132. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_005.npz +0 -0
  133. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_006.npz +0 -0
  134. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/case_007.npz +0 -0
  135. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/cases/index.json +306 -0
  136. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/kernel.wgsl +147 -0
  137. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/manifest.json +13 -0
  138. wgpu_shift-0.1.0/examples/pairwise/kernels/pairwise_l2/port.py +36 -0
  139. wgpu_shift-0.1.0/examples/pairwise/pairwise.py +24 -0
  140. wgpu_shift-0.1.0/examples/tiny_add/demo.py +28 -0
  141. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/TASK.md +41 -0
  142. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_000.npz +0 -0
  143. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_001.npz +0 -0
  144. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_002.npz +0 -0
  145. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_003.npz +0 -0
  146. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_004.npz +0 -0
  147. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_005.npz +0 -0
  148. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_006.npz +0 -0
  149. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/case_007.npz +0 -0
  150. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/cases/index.json +322 -0
  151. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/kernel.wgsl +28 -0
  152. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/manifest.json +13 -0
  153. wgpu_shift-0.1.0/examples/tiny_add/kernels/add_scaled/port.py +30 -0
  154. wgpu_shift-0.1.0/examples/tiny_add/tiny_add.py +16 -0
  155. wgpu_shift-0.1.0/pyproject.toml +67 -0
  156. wgpu_shift-0.1.0/skills/gpu-shift/SKILL.md +56 -0
  157. wgpu_shift-0.1.0/src/gpu_shift/__init__.py +19 -0
  158. wgpu_shift-0.1.0/src/gpu_shift/__main__.py +8 -0
  159. wgpu_shift-0.1.0/src/gpu_shift/_capturer.py +191 -0
  160. wgpu_shift-0.1.0/src/gpu_shift/_scanner.py +71 -0
  161. wgpu_shift-0.1.0/src/gpu_shift/bench.py +321 -0
  162. wgpu_shift-0.1.0/src/gpu_shift/capture.py +669 -0
  163. wgpu_shift-0.1.0/src/gpu_shift/check.py +224 -0
  164. wgpu_shift-0.1.0/src/gpu_shift/cli.py +609 -0
  165. wgpu_shift-0.1.0/src/gpu_shift/demo.py +272 -0
  166. wgpu_shift-0.1.0/src/gpu_shift/device.py +170 -0
  167. wgpu_shift-0.1.0/src/gpu_shift/diff.py +510 -0
  168. wgpu_shift-0.1.0/src/gpu_shift/manifest.py +171 -0
  169. wgpu_shift-0.1.0/src/gpu_shift/mcp_server.py +352 -0
  170. wgpu_shift-0.1.0/src/gpu_shift/report.py +218 -0
  171. wgpu_shift-0.1.0/src/gpu_shift/run.py +206 -0
  172. wgpu_shift-0.1.0/src/gpu_shift/runtime.py +592 -0
  173. wgpu_shift-0.1.0/src/gpu_shift/scan.py +380 -0
  174. wgpu_shift-0.1.0/src/gpu_shift/setup.py +245 -0
  175. wgpu_shift-0.1.0/src/gpu_shift/skill_data/SKILL.md +56 -0
  176. wgpu_shift-0.1.0/src/gpu_shift/stage.py +248 -0
  177. wgpu_shift-0.1.0/src/gpu_shift/switch.py +268 -0
  178. wgpu_shift-0.1.0/tests/test_examples.py +26 -0
  179. wgpu_shift-0.1.0/tests/test_gpu_smoke.py +14 -0
  180. wgpu_shift-0.1.0/tests/test_phase2.py +262 -0
  181. wgpu_shift-0.1.0/tests/test_pipeline.py +257 -0
  182. wgpu_shift-0.1.0/tests/test_runtime.py +132 -0
  183. wgpu_shift-0.1.0/tests/test_safety_guards.py +226 -0
  184. wgpu_shift-0.1.0/tests/test_v02_diagnostics_and_evals.py +240 -0
  185. wgpu_shift-0.1.0/uv.lock +428 -0
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ lint-and-test:
10
+ runs-on: windows-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - name: Install uv
15
+ uses: astral-sh/setup-uv@v5
16
+
17
+ - name: Sync environment
18
+ run: uv sync
19
+
20
+ - name: Lint with ruff
21
+ run: uv run ruff check .
22
+
23
+ - name: Check WebGPU adapters
24
+ run: uv run gpu-shift doctor
25
+
26
+ - name: Run test suite
27
+ run: uv run pytest -v
@@ -0,0 +1,38 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - name: Install uv
14
+ uses: astral-sh/setup-uv@v5
15
+
16
+ - name: Build sdist and wheel
17
+ run: uv build
18
+
19
+ - name: Upload dist artifact
20
+ uses: actions/upload-artifact@v4
21
+ with:
22
+ name: dist
23
+ path: dist/
24
+
25
+ publish:
26
+ needs: [build]
27
+ runs-on: ubuntu-latest
28
+ permissions:
29
+ id-token: write
30
+ steps:
31
+ - name: Download dist artifact
32
+ uses: actions/download-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+
37
+ - name: Publish package to PyPI
38
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,22 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+
15
+ # gpu-shift runtime artifacts
16
+ .gpu-shift/
17
+
18
+ # OS / IDE
19
+ .DS_Store
20
+ Thumbs.db
21
+ .vscode/
22
+ .idea/
@@ -0,0 +1,43 @@
1
+ # Contributing to gpu-shift
2
+
3
+ Thanks for your interest in contributing! `gpu-shift` is intentionally small, flat, and easy to work on.
4
+
5
+ ## Local Setup
6
+
7
+ ```bash
8
+ uv sync
9
+ uv run gpu-shift doctor
10
+ uv run pytest -v
11
+ uv run ruff check .
12
+ ```
13
+
14
+ Core dependencies are intentionally limited to `wgpu` and `numpy` (plus Python 3.11+ stdlib).
15
+
16
+ ## Codebase Layout
17
+
18
+ One command maps to one module under `src/gpu_shift/`:
19
+
20
+ - `device.py`: WebGPU adapter discovery, cached device access, `doctor` smoke test
21
+ - `manifest.py`: `kernels/<fn>/manifest.json`, SHA-256 source freshness, dynamic loading
22
+ - `runtime.py`: `ComputeKernel`, `ComputeSession`, uniform padding, WGSL validation, VRAM tracking
23
+ - `scan.py` & `_scanner.py`: `cProfile` + AST hotspot ranking
24
+ - `stage.py`: Creates `kernels/<fn>/` without touching original files
25
+ - `capture.py` & `_capturer.py`: Captures CPU calls into `.npz` + GPU edge-case synthesis
26
+ - `diff.py`: Replays captured cases against GPU and checks shape, NaN/Inf, `atol`/`rtol`
27
+ - `bench.py`: Measures end-to-end CPU vs GPU latency and computes `min_elements` crossover
28
+ - `check.py`: Deterministic release check (freshness, WGSL, diff, 15-dispatch VRAM soak)
29
+ - `switch.py`: Reversible `enable`/`disable`, crossover router, `cpu|shadow|gpu|auto` modes
30
+ - `run.py`: Two-phase stateful `gpu-shift run` workflow
31
+ - `report.py`: Generates `REPORT.md` and `card.svg`
32
+ - `cli.py` & `mcp_server.py`: CLI parser and zero-dep stdio MCP server
33
+
34
+ Core functions return plain dataclasses; keep printing and exit codes inside `cli.py`.
35
+
36
+ ## Great First Contributions
37
+
38
+ 1. **Self-contained examples (`examples/`):** 30-60 line pure Python/NumPy hot loops (image filters, DSP, pairwise distances, physics) with zero external downloads and a verified GPU port.
39
+ 2. **GPU edge-case traps (`capture.py`):** New numeric or memory-layout traps that catch real WGSL bugs.
40
+ 3. **Real-world benchmark reports:** Measured before/after speedups on different GPUs (NVIDIA, AMD, Intel, Apple Silicon).
41
+ 4. **Multi-language front-ends:** TypeScript/JS, Rust, or C/C++ front-ends sharing the same WGSL shader + check model.
42
+
43
+ Please read [DECISIONS.md](DECISIONS.md) before proposing large architectural changes.
@@ -0,0 +1,16 @@
1
+ # Design Decisions
2
+
3
+ Short record of why `gpu-shift` is structured the way it is.
4
+
5
+ | # | Decision | Reason |
6
+ | --- | --- | --- |
7
+ | D1 | Do not build a Python-to-WGSL compiler; the coding agent or developer writes `kernel.wgsl` + thin `port.py`, while `gpu-shift` handles scanning, staging, capture, diffing, benchmarking, and release checks. | Compilers break on real-world Python/NumPy semantics. Deterministic ground-truth verification plus clean WGSL error feedback is simpler and far more reliable. |
8
+ | D2 | Use WebGPU/WGSL via `wgpu-py` as the default backend. | Runs across NVIDIA, AMD, Intel, and Apple Silicon using signed wheels, without CUDA toolkit installation or native compiler toolchains. |
9
+ | D3 | One command = one flat module under `src/gpu_shift/`, returning plain dataclasses with no `print()` or `sys.exit()` inside core logic. | Keeps the codebase easy to read for new contributors and lets CLI, `--json`, tests, and the MCP server share the exact same functions. |
10
+ | D4 | Keep dependencies strictly to `wgpu` and `numpy` (stdlib for everything else). | Enables fast, zero-friction `uvx gpu-shift` runs with minimal dependency conflicts. |
11
+ | D5 | Never touch the original source file during `stage`, `capture`, `diff`, `bench`, or `check`. Only `enable` appends a marked block, and `disable` removes it byte-for-byte. | Safe to try on any repository; easy to inspect in git diff and revert completely. |
12
+ | D6 | Hash the clean original source (stripping switch blocks) in `manifest.json` and fail `diff`/`check` when stale. | Prevents silently passing against an outdated capture after the original CPU function changes, while letting `enable`/`disable` toggle without false staleness. |
13
+ | D7 | Separate `bench` from default `check` (opt-in via `check --require-speedup`), and measure full CPU->GPU->CPU transfers to compute `min_elements` crossover. | Correctness can be verified even on CPU/software renderers in CI, while real hardware benchmarking automatically keeps small arrays on CPU where transfers would lose. |
14
+ | D8 | Run a 15-dispatch soak test in `check` using `wgpu.diagnostics.object_counts` (buffers, textures, bind groups, pipelines, shaders, and live `resource_mem` VRAM bytes). | Catches real native GPU/VRAM leaks even when a custom `port.py` bypasses `ComputeKernel` and calls `wgpu` directly. |
15
+ | D9 | Fuse compute dispatch + staging `copy_buffer_to_buffer` into one `queue.submit()`, read via `read_mapped(copy=False)` into aligned NumPy arrays, and provide opt-in `ComputeSession` (`with kernel.session():`) for multi-frame loops. | Halves queue submissions and eliminates redundant `bytearray` copies while keeping default `dispatch()` at `0 B` resident VRAM and letting tight loops reuse buffers + `BindGroup` with guaranteed `__exit__` cleanup. |
16
+ | D10 | Guard runtime against software CPU emulators (`adapter_type="CPU"`), pre-check WebGPU workgroup/buffer limits (`GpuLimitError`), lock `ComputeKernel`/`ComputeSession`, key device cache by PID, and probe in-place mutation + non-determinism in `capture`. | Prevents silent slowdowns on GPU-less VMs/Docker, avoids permanently disabling GPU after one oversized call, stays safe under threads/fork, and surfaces subtle CPU semantics (`random`, in-place mutation, `float64 -> float32`) early. |
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gpu-shift contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.5
2
+ Name: wgpu-shift
3
+ Version: 0.1.0
4
+ Summary: Move slow Python/NumPy CPU loops to any GPU via WebGPU/WGSL with deterministic verification, native VRAM leak soaking, and crossover benchmarking.
5
+ Project-URL: Homepage, https://github.com/boraiks/gpu-shift
6
+ Project-URL: Repository, https://github.com/boraiks/gpu-shift
7
+ Project-URL: Issues, https://github.com/boraiks/gpu-shift/issues
8
+ Author: Bora
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: benchmark,coding-agent,compute-shader,gpu,mcp,numpy,webgpu,wgpu,wgsl
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Scientific/Engineering
23
+ Classifier: Topic :: Software Development :: Testing
24
+ Requires-Python: >=3.11
25
+ Requires-Dist: numpy>=1.26
26
+ Requires-Dist: wgpu>=0.19
27
+ Description-Content-Type: text/markdown
28
+
29
+ <p align="center">
30
+ <picture>
31
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner-dark.png">
32
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner.png">
33
+ <img src="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner.png" width="560" alt="gpu-shift">
34
+ </picture>
35
+ </p>
36
+
37
+ <p align="center"><sub>English · <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/README_TR.md">Türkçe</a></sub></p>
38
+
39
+ <p align="center"><b>Shift slow CPU loops onto any GPU - no CUDA, no guesswork.</b><br>
40
+ Point it at your script: it finds the hotspot, captures real CPU truth, and verifies every GPU port<br>
41
+ for accuracy, zero VRAM leaks, and real end-to-end speedup before turning it on.</p>
42
+
43
+ <p align="center">
44
+ <a href="https://pypi.org/project/wgpu-shift/"><img src="https://img.shields.io/pypi/v/wgpu-shift?color=2563EB&label=PyPI" alt="PyPI - wgpu-shift"></a>
45
+ <img src="https://img.shields.io/badge/python-3.11%2B-2563EB?logo=python&logoColor=white" alt="Python 3.11+">
46
+ <img src="https://img.shields.io/badge/NVIDIA%20%C2%B7%20AMD%20%C2%B7%20Intel%20%C2%B7%20Apple%20Silicon-no%20CUDA-10B981" alt="Works on NVIDIA, AMD, Intel, and Apple Silicon without CUDA">
47
+ <a href="https://github.com/boraiks/gpu-shift/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-555" alt="MIT license"></a>
48
+ </p>
49
+
50
+ <p align="center"><b><a href="#use-it-on-your-code">Install</a></b> · <a href="#try-it-now">Live demo</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md">Real-world ports</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/how-it-works.md">How it works</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/evals/README.md">Eval suite</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/DECISIONS.md">Decisions</a></p>
51
+
52
+ <p align="center">
53
+ <img src="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/demo.gif" alt="1:1 real-time benchmark comparing original scikit-image and SciPy CPU functions against gpu-shift GPU ports: GPU completes in 0.04 to 0.07 s while CPU takes 5.01 to 5.11 s, with all 24 captured cases matching and 0 VRAM leaks." width="780">
54
+ <br>
55
+ <sub>1:1 real-time run on an RTX 4060 Laptop GPU, data transfers included. <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md">How it was measured</a>.</sub>
56
+ </p>
57
+
58
+ `gpu-shift` (PyPI package: `wgpu-shift`) is not an auto-compiler. You (or your coding agent) write the GPU shader one function at a time; `gpu-shift` finds what is slow, proves outputs match CPU, checks for 0 B VRAM leaks, and keeps small or transfer-bound inputs on CPU automatically. Built on `wgpu-py`, so the same port runs on NVIDIA, AMD, Intel, and Apple Silicon without CUDA.
59
+
60
+ | Upstream library, same output as CPU | Original CPU | With `gpu-shift` |
61
+ | --- | ---: | ---: |
62
+ | [`scikit-image`](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md#1-scikit-image-0260---denoise_bilateral) `denoise_bilateral` (512x512, 50 frames) | 5.01 s | **0.04 s (121x)** |
63
+ | [`scipy.signal.convolve2d`](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md#2-scipy-1181---scipysignalconvolve2d) (1024x1024, 20 frames) | 5.06 s | **0.06 s (88x)** |
64
+ | [`scipy.spatial.distance.cdist`](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md#3-scipy-1181---scipyspatialdistancecdist) (2048x128, 20 calls) | 5.11 s | **0.07 s (72x)** |
65
+
66
+ Reproduce locally: `uv run --with scipy --with scikit-image python benchmarks/real_world/run_all.py`
67
+
68
+ ## Try it now
69
+
70
+ Test your own GPU in 15 seconds, no clone required:
71
+
72
+ ```sh
73
+ uvx wgpu-shift demo
74
+ ```
75
+
76
+ *(Windows Smart App Control: `uv run --with wgpu-shift python -m gpu_shift demo`)*
77
+
78
+ ## Use it on your code
79
+
80
+ Install once from PyPI (`wgpu-shift` installs both `gpu-shift` and `wgpu-shift` commands) and wire it into your coding agent (Claude Code, Antigravity/Gemini, Codex, Cursor, or OpenCode):
81
+
82
+ ```sh
83
+ pip install wgpu-shift # or: uv tool install wgpu-shift
84
+ gpu-shift setup # backs up existing configs; undo anytime with `gpu-shift setup --remove`
85
+ ```
86
+
87
+ Or run directly from the terminal without touching your source file until checks pass:
88
+
89
+ ```sh
90
+ gpu-shift run -- python app.py # 1. scans hotspot, captures CPU truth + edge traps, writes TASK.md
91
+ # implement kernels/<fn>/kernel.wgsl + port.py (yourself or via your agent), then re-run:
92
+ gpu-shift run -- python app.py # 2. runs diff, VRAM check, transfer-inclusive bench, enables if faster
93
+ gpu-shift disable kernels/<fn> # reverts the original file byte-for-byte
94
+ ```
95
+
96
+ At runtime, `GPU_SHIFT_MODE=auto|cpu|shadow|gpu` lets you compare or force either backend, and machines without a hardware GPU fall back to CPU silently. Full CLI reference (`scan`, `stage`, `capture`, `diff`, `bench`, `check`, `report`) and built-in examples live in [How it works](https://github.com/boraiks/gpu-shift/blob/main/docs/how-it-works.md).
97
+
98
+ <p align="center">
99
+ <img src="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/check.gif" alt="gpu-shift check verifying source freshness, WGSL compilation, 8/8 numerical diff, and 0 B VRAM growth, followed by gpu-shift run keeping tiny_add on CPU when transfer cost dominates." width="780">
100
+ <br>
101
+ <sub><code>check</code> enforces parity and 0 B VRAM growth; <code>run</code> keeps lightweight ops on CPU when transfer cost dominates.</sub>
102
+ </p>
103
+
104
+ ## Languages
105
+
106
+ | Language | Status | Notes |
107
+ | --- | --- | --- |
108
+ | **Python / NumPy** | Ready (`v0.1`) | CLI, MCP server, `SKILL.md`, 8-task eval suite, and runtime safety guards |
109
+ | **TypeScript / JavaScript** | Planned | Same WGSL kernel and verification loop for Node.js / Deno / Bun |
110
+ | **Rust** | Planned | `wgpu` crate bridge sharing `kernel.wgsl` and checks |
111
+ | **C / C++** | Planned | `wgpu-native` C ABI bridge for hot numerical loops |
112
+
113
+ Also planned: optional `triton` / `mlx` backends. Contributions welcome.
114
+
115
+ ## Docs
116
+
117
+ - [How it works](https://github.com/boraiks/gpu-shift/blob/main/docs/how-it-works.md) - CLI reference, agent setup paths, runtime modes, and built-in examples
118
+ - [Real-world ports](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md) - `scikit-image` and `SciPy` timings, optimizations, and upstream quirks caught by `diff`
119
+ - [Python eval suite](https://github.com/boraiks/gpu-shift/blob/main/evals/README.md) - 8 labeled tasks covering 1D/2D/3D arrays, multi-output tuples, and CPU/serial-loop traps
120
+ - [Design decisions](https://github.com/boraiks/gpu-shift/blob/main/DECISIONS.md) - trade-offs and non-goals
121
+ - [Contributing](https://github.com/boraiks/gpu-shift/blob/main/CONTRIBUTING.md) - local dev setup and codebase layout
122
+
123
+ ## License
124
+
125
+ [MIT](https://github.com/boraiks/gpu-shift/blob/main/LICENSE). Shaders and ports generated in your own repository belong to you.
@@ -0,0 +1,97 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner-dark.png">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner.png">
5
+ <img src="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner.png" width="560" alt="gpu-shift">
6
+ </picture>
7
+ </p>
8
+
9
+ <p align="center"><sub>English · <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/README_TR.md">Türkçe</a></sub></p>
10
+
11
+ <p align="center"><b>Shift slow CPU loops onto any GPU - no CUDA, no guesswork.</b><br>
12
+ Point it at your script: it finds the hotspot, captures real CPU truth, and verifies every GPU port<br>
13
+ for accuracy, zero VRAM leaks, and real end-to-end speedup before turning it on.</p>
14
+
15
+ <p align="center">
16
+ <a href="https://pypi.org/project/wgpu-shift/"><img src="https://img.shields.io/pypi/v/wgpu-shift?color=2563EB&label=PyPI" alt="PyPI - wgpu-shift"></a>
17
+ <img src="https://img.shields.io/badge/python-3.11%2B-2563EB?logo=python&logoColor=white" alt="Python 3.11+">
18
+ <img src="https://img.shields.io/badge/NVIDIA%20%C2%B7%20AMD%20%C2%B7%20Intel%20%C2%B7%20Apple%20Silicon-no%20CUDA-10B981" alt="Works on NVIDIA, AMD, Intel, and Apple Silicon without CUDA">
19
+ <a href="https://github.com/boraiks/gpu-shift/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-555" alt="MIT license"></a>
20
+ </p>
21
+
22
+ <p align="center"><b><a href="#use-it-on-your-code">Install</a></b> · <a href="#try-it-now">Live demo</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md">Real-world ports</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/how-it-works.md">How it works</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/evals/README.md">Eval suite</a> · <a href="https://github.com/boraiks/gpu-shift/blob/main/DECISIONS.md">Decisions</a></p>
23
+
24
+ <p align="center">
25
+ <img src="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/demo.gif" alt="1:1 real-time benchmark comparing original scikit-image and SciPy CPU functions against gpu-shift GPU ports: GPU completes in 0.04 to 0.07 s while CPU takes 5.01 to 5.11 s, with all 24 captured cases matching and 0 VRAM leaks." width="780">
26
+ <br>
27
+ <sub>1:1 real-time run on an RTX 4060 Laptop GPU, data transfers included. <a href="https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md">How it was measured</a>.</sub>
28
+ </p>
29
+
30
+ `gpu-shift` (PyPI package: `wgpu-shift`) is not an auto-compiler. You (or your coding agent) write the GPU shader one function at a time; `gpu-shift` finds what is slow, proves outputs match CPU, checks for 0 B VRAM leaks, and keeps small or transfer-bound inputs on CPU automatically. Built on `wgpu-py`, so the same port runs on NVIDIA, AMD, Intel, and Apple Silicon without CUDA.
31
+
32
+ | Upstream library, same output as CPU | Original CPU | With `gpu-shift` |
33
+ | --- | ---: | ---: |
34
+ | [`scikit-image`](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md#1-scikit-image-0260---denoise_bilateral) `denoise_bilateral` (512x512, 50 frames) | 5.01 s | **0.04 s (121x)** |
35
+ | [`scipy.signal.convolve2d`](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md#2-scipy-1181---scipysignalconvolve2d) (1024x1024, 20 frames) | 5.06 s | **0.06 s (88x)** |
36
+ | [`scipy.spatial.distance.cdist`](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md#3-scipy-1181---scipyspatialdistancecdist) (2048x128, 20 calls) | 5.11 s | **0.07 s (72x)** |
37
+
38
+ Reproduce locally: `uv run --with scipy --with scikit-image python benchmarks/real_world/run_all.py`
39
+
40
+ ## Try it now
41
+
42
+ Test your own GPU in 15 seconds, no clone required:
43
+
44
+ ```sh
45
+ uvx wgpu-shift demo
46
+ ```
47
+
48
+ *(Windows Smart App Control: `uv run --with wgpu-shift python -m gpu_shift demo`)*
49
+
50
+ ## Use it on your code
51
+
52
+ Install once from PyPI (`wgpu-shift` installs both `gpu-shift` and `wgpu-shift` commands) and wire it into your coding agent (Claude Code, Antigravity/Gemini, Codex, Cursor, or OpenCode):
53
+
54
+ ```sh
55
+ pip install wgpu-shift # or: uv tool install wgpu-shift
56
+ gpu-shift setup # backs up existing configs; undo anytime with `gpu-shift setup --remove`
57
+ ```
58
+
59
+ Or run directly from the terminal without touching your source file until checks pass:
60
+
61
+ ```sh
62
+ gpu-shift run -- python app.py # 1. scans hotspot, captures CPU truth + edge traps, writes TASK.md
63
+ # implement kernels/<fn>/kernel.wgsl + port.py (yourself or via your agent), then re-run:
64
+ gpu-shift run -- python app.py # 2. runs diff, VRAM check, transfer-inclusive bench, enables if faster
65
+ gpu-shift disable kernels/<fn> # reverts the original file byte-for-byte
66
+ ```
67
+
68
+ At runtime, `GPU_SHIFT_MODE=auto|cpu|shadow|gpu` lets you compare or force either backend, and machines without a hardware GPU fall back to CPU silently. Full CLI reference (`scan`, `stage`, `capture`, `diff`, `bench`, `check`, `report`) and built-in examples live in [How it works](https://github.com/boraiks/gpu-shift/blob/main/docs/how-it-works.md).
69
+
70
+ <p align="center">
71
+ <img src="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/check.gif" alt="gpu-shift check verifying source freshness, WGSL compilation, 8/8 numerical diff, and 0 B VRAM growth, followed by gpu-shift run keeping tiny_add on CPU when transfer cost dominates." width="780">
72
+ <br>
73
+ <sub><code>check</code> enforces parity and 0 B VRAM growth; <code>run</code> keeps lightweight ops on CPU when transfer cost dominates.</sub>
74
+ </p>
75
+
76
+ ## Languages
77
+
78
+ | Language | Status | Notes |
79
+ | --- | --- | --- |
80
+ | **Python / NumPy** | Ready (`v0.1`) | CLI, MCP server, `SKILL.md`, 8-task eval suite, and runtime safety guards |
81
+ | **TypeScript / JavaScript** | Planned | Same WGSL kernel and verification loop for Node.js / Deno / Bun |
82
+ | **Rust** | Planned | `wgpu` crate bridge sharing `kernel.wgsl` and checks |
83
+ | **C / C++** | Planned | `wgpu-native` C ABI bridge for hot numerical loops |
84
+
85
+ Also planned: optional `triton` / `mlx` backends. Contributions welcome.
86
+
87
+ ## Docs
88
+
89
+ - [How it works](https://github.com/boraiks/gpu-shift/blob/main/docs/how-it-works.md) - CLI reference, agent setup paths, runtime modes, and built-in examples
90
+ - [Real-world ports](https://github.com/boraiks/gpu-shift/blob/main/docs/real-world.md) - `scikit-image` and `SciPy` timings, optimizations, and upstream quirks caught by `diff`
91
+ - [Python eval suite](https://github.com/boraiks/gpu-shift/blob/main/evals/README.md) - 8 labeled tasks covering 1D/2D/3D arrays, multi-output tuples, and CPU/serial-loop traps
92
+ - [Design decisions](https://github.com/boraiks/gpu-shift/blob/main/DECISIONS.md) - trade-offs and non-goals
93
+ - [Contributing](https://github.com/boraiks/gpu-shift/blob/main/CONTRIBUTING.md) - local dev setup and codebase layout
94
+
95
+ ## License
96
+
97
+ [MIT](https://github.com/boraiks/gpu-shift/blob/main/LICENSE). Shaders and ports generated in your own repository belong to you.
@@ -0,0 +1,37 @@
1
+ # GPU Port Task: `scipy_cdist`
2
+
3
+ ## Target
4
+ - Source file: `../../scipy_cdist.py` (lines 9-13)
5
+ - Function: `scipy_cdist(a: np.ndarray, b: np.ndarray)`
6
+ - Tolerances: `rtol=0.0001`, `atol=1e-05`
7
+
8
+ ## Original CPU Implementation
9
+
10
+ ```python
11
+ def scipy_cdist(a: np.ndarray, b: np.ndarray) -> np.ndarray:
12
+ """Upstream SciPy pairwise Euclidean distance matrix."""
13
+ x = np.ascontiguousarray(a, dtype=np.float32)
14
+ y = np.ascontiguousarray(b, dtype=np.float32)
15
+ return cdist(x, y, metric="euclidean").astype(np.float32, copy=False)
16
+ ```
17
+
18
+ ## What to Edit
19
+ 1. Implement the WGSL compute shader in `kernel.wgsl`.
20
+ 2. Implement `run_gpu(a: np.ndarray, b: np.ndarray)` in `port.py` using `ComputeKernel`.
21
+ 3. Do NOT edit the original source file by hand (`gpu-shift enable` handles it after `check` passes).
22
+
23
+ ## Rules for Reliable WGSL Ports
24
+ - Always guard thread indices against array/image bounds (recorded cases include odd/prime dimensions like `17x13` and `1x1`).
25
+ - Handle empty arrays (0 elements) on CPU before calling `ComputeKernel.dispatch`.
26
+ - Convert input arrays to contiguous `np.float32` (or matching WGSL dtype) inside `port.py`; pack uniform structs with `pack_uniforms(...)` (automatically 16-byte padded).
27
+ - Keep the exact output shape and dtype expected by callers.
28
+
29
+ ## Verification Loop
30
+
31
+ ```bash
32
+ gpu-shift capture benchmarks/real_world/kernels/scipy_cdist -- <your command>
33
+ gpu-shift diff benchmarks/real_world/kernels/scipy_cdist
34
+ gpu-shift bench benchmarks/real_world/kernels/scipy_cdist
35
+ gpu-shift check benchmarks/real_world/kernels/scipy_cdist
36
+ gpu-shift enable benchmarks/real_world/kernels/scipy_cdist
37
+ ```