Metadata-Version: 2.5
Name: wgpu-shift
Version: 0.1.0
Summary: Move slow Python/NumPy CPU loops to any GPU via WebGPU/WGSL with deterministic verification, native VRAM leak soaking, and crossover benchmarking.
Project-URL: Homepage, https://github.com/boraiks/gpu-shift
Project-URL: Repository, https://github.com/boraiks/gpu-shift
Project-URL: Issues, https://github.com/boraiks/gpu-shift/issues
Author: Bora
License: MIT
License-File: LICENSE
Keywords: benchmark,coding-agent,compute-shader,gpu,mcp,numpy,webgpu,wgpu,wgsl
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Requires-Dist: numpy>=1.26
Requires-Dist: wgpu>=0.19
Description-Content-Type: text/markdown

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner-dark.png">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner.png">
    <img src="https://raw.githubusercontent.com/boraiks/gpu-shift/main/docs/assets/banner.png" width="560" alt="gpu-shift">
  </picture>
</p>

<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>

<p align="center"><b>Shift slow CPU loops onto any GPU - no CUDA, no guesswork.</b><br>
Point it at your script: it finds the hotspot, captures real CPU truth, and verifies every GPU port<br>
for accuracy, zero VRAM leaks, and real end-to-end speedup before turning it on.</p>

<p align="center">
  <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>
  <img src="https://img.shields.io/badge/python-3.11%2B-2563EB?logo=python&logoColor=white" alt="Python 3.11+">
  <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">
  <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>
</p>

<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>

<p align="center">
  <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">
  <br>
  <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>
</p>

`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.

| Upstream library, same output as CPU | Original CPU | With `gpu-shift` |
| --- | ---: | ---: |
| [`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)** |
| [`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)** |
| [`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)** |

Reproduce locally: `uv run --with scipy --with scikit-image python benchmarks/real_world/run_all.py`

## Try it now

Test your own GPU in 15 seconds, no clone required:

```sh
uvx wgpu-shift demo
```

*(Windows Smart App Control: `uv run --with wgpu-shift python -m gpu_shift demo`)*

## Use it on your code

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):

```sh
pip install wgpu-shift   # or: uv tool install wgpu-shift
gpu-shift setup          # backs up existing configs; undo anytime with `gpu-shift setup --remove`
```

Or run directly from the terminal without touching your source file until checks pass:

```sh
gpu-shift run -- python app.py        # 1. scans hotspot, captures CPU truth + edge traps, writes TASK.md
# implement kernels/<fn>/kernel.wgsl + port.py (yourself or via your agent), then re-run:
gpu-shift run -- python app.py        # 2. runs diff, VRAM check, transfer-inclusive bench, enables if faster
gpu-shift disable kernels/<fn>        # reverts the original file byte-for-byte
```

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).

<p align="center">
  <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">
  <br>
  <sub><code>check</code> enforces parity and 0 B VRAM growth; <code>run</code> keeps lightweight ops on CPU when transfer cost dominates.</sub>
</p>

## Languages

| Language | Status | Notes |
| --- | --- | --- |
| **Python / NumPy** | Ready (`v0.1`) | CLI, MCP server, `SKILL.md`, 8-task eval suite, and runtime safety guards |
| **TypeScript / JavaScript** | Planned | Same WGSL kernel and verification loop for Node.js / Deno / Bun |
| **Rust** | Planned | `wgpu` crate bridge sharing `kernel.wgsl` and checks |
| **C / C++** | Planned | `wgpu-native` C ABI bridge for hot numerical loops |

Also planned: optional `triton` / `mlx` backends. Contributions welcome.

## Docs

- [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
- [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`
- [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
- [Design decisions](https://github.com/boraiks/gpu-shift/blob/main/DECISIONS.md) - trade-offs and non-goals
- [Contributing](https://github.com/boraiks/gpu-shift/blob/main/CONTRIBUTING.md) - local dev setup and codebase layout

## License

[MIT](https://github.com/boraiks/gpu-shift/blob/main/LICENSE). Shaders and ports generated in your own repository belong to you.
