Skip to content

Commit 133caca

Browse files
wpmed92geohot
andauthored
Autogen webgpu dawn, removing wgpu-py dependency (f16 support part 1) (tinygrad#8646)
* Switch to dawn, all tests passing locally * Use dawn-python * Skip failing test * Skip midcast and fix timestamp on metal ci * Autogen webgpu * Try fetch dawn lib again * /usr/lib * Without lib prefix * Test autogen diff * Delete webgpu support, move everything to ops_webgpu * mypy fix * Simplify, refactor * Line savings * No ResultContainer * Type annotation for result * Some more simplifications * Why was this explicit sync used at all? * Refactor: delete functions that are only used once * Create shader module inline * Clear unit tests cache, maybe that solves it * That wasn't it * Try deleting cache to pass failing weight compare * weights_only=False for pytorch 2.6 * Simplify ctype array creation * Remove nanosecond precision timestamps * Simplify error handling * Refactor, add back type annotations * Deleted custom submit function, refactor * read_buffer simplify * Fix use after free, refactor * Simplify supported_features * Runtime docs --------- Co-authored-by: George Hotz <72895+geohot@users.noreply.github.com>
1 parent dbda72f commit 133caca

14 files changed

+11512
-47
lines changed

.github/workflows/test.yml

+18-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
sudo apt update -y || true
7373
sudo apt install -y --no-install-recommends git g++ cmake ninja-build llvm-15-dev zlib1g-dev libglew-dev \
7474
flex bison libfl-dev libboost-thread-dev libboost-filesystem-dev nvidia-cuda-toolkit-gcc libzstd-dev
75+
- name: Install packages (webgpu)
76+
run: |
77+
sudo curl -L https://github.com/wpmed92/pydawn/releases/download/v0.1.6/libwebgpu_dawn.so -o /usr/local/lib/libwebgpu_dawn.so
7578
- name: Install packages (amd)
7679
run: |
7780
echo 'Acquire::http::Pipeline-Depth "5";' | sudo tee -a /etc/apt/apt.conf.d/99parallel
@@ -132,6 +135,11 @@ jobs:
132135
./autogen_stubs.sh io_uring
133136
diff /tmp/libc.py.bak tinygrad/runtime/autogen/libc.py
134137
diff /tmp/io_uring.py.bak tinygrad/runtime/autogen/io_uring.py
138+
- name: Verify WebGPU autogen
139+
run: |
140+
cp tinygrad/runtime/autogen/webgpu.py /tmp/webgpu.py.bak
141+
./autogen_stubs.sh webgpu
142+
diff /tmp/webgpu.py.bak tinygrad/runtime/autogen/webgpu.py
135143
- name: Verify LLVM autogen
136144
run: |
137145
cp tinygrad/runtime/autogen/llvm.py /tmp/llvm.py.bak
@@ -401,7 +409,10 @@ jobs:
401409
path: ~/.local/lib/python3.11/site-packages
402410
key: webgpu-testing-user3-packages-${{ hashFiles('**/setup.py') }}
403411
- name: Install Dependencies
404-
run: pip install --user -e '.[webgpu,testing]' --extra-index-url https://download.pytorch.org/whl/cpu
412+
run: pip install --user -e '.[testing]' --extra-index-url https://download.pytorch.org/whl/cpu
413+
- name: Install dawn (WebGPU)
414+
run: |
415+
sudo curl -L https://github.com/wpmed92/pydawn/releases/download/v0.1.6/libwebgpu_dawn.so -o /usr/lib/libwebgpu_dawn.so
405416
- name: Install dependencies for software-based vulkan
406417
run: |
407418
sudo apt update -y || true
@@ -417,7 +428,7 @@ jobs:
417428
WEBGPU=1 DEBUG=4 FORWARD_ONLY=1 python3 test/test_ops.py TestOps.test_add
418429
- name: Run selected webgpu tests
419430
run: |
420-
WEBGPU=1 WGPU_BACKEND_TYPE=Vulkan python3 -m pytest -n=auto test/ --ignore=test/external --ignore=test/models --ignore=test/unit \
431+
WEBGPU=1 python3 -m pytest -n=auto test/ --ignore=test/external --ignore=test/models --ignore=test/unit \
421432
--ignore=test/test_copy_speed.py --ignore=test/test_rearrange_einops.py --ignore=test/test_speed_v_torch.py --ignore=test/test_transcendental.py \
422433
--ignore=test/test_fuzz_shape_ops.py --ignore=test/test_linearizer_failures.py --durations=20
423434
- name: Run process replay tests
@@ -447,6 +458,10 @@ jobs:
447458
key: metal-m1-testing-user3-packages-${{ hashFiles('**/setup.py') }}
448459
- name: Install Dependencies
449460
run: pip install --user -e '.[webgpu,testing]' --extra-index-url https://download.pytorch.org/whl/cpu
461+
- name: Install dawn (WebGPU)
462+
run: |
463+
sudo mkdir -p /usr/local/lib
464+
sudo curl -L https://github.com/wpmed92/pydawn/releases/download/v0.1.6/libwebgpu_dawn.dylib -o /usr/local/lib/libwebgpu_dawn.dylib
450465
- name: Cache downloads
451466
uses: actions/cache@v4
452467
with:
@@ -478,7 +493,7 @@ jobs:
478493
run: TRANSCENDENTAL=2 python -m pytest -n=auto test/test_ops.py::TestOps::test_sin test/test_ops.py::TestOps::test_cos test/test_ops.py::TestOps::test_tan test/test_ops.py::TestOps::test_exp test/test_ops.py::TestOps::test_log --durations=20
479494
# WebGPU e2e tests
480495
- name: Build WEBGPU Efficientnet
481-
run: WEBGPU=1 WGPU_BACKEND_TYPE=Metal python3 -m examples.compile_efficientnet
496+
run: WEBGPU=1 python3 -m examples.compile_efficientnet
482497
- name: Clean npm cache
483498
run: npm cache clean --force
484499
- name: Install Puppeteer

autogen_stubs.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,14 @@ generate_am() {
357357
fixup $BASE/am/smu_v13_0_0.py
358358
}
359359

360+
generate_webgpu() {
361+
clang2py -l /usr/local/lib/libwebgpu_dawn.so extra/webgpu/webgpu.h -o $BASE/webgpu.py
362+
fixup $BASE/webgpu.py
363+
sed -i 's/import ctypes/import ctypes, ctypes.util/g' $BASE/webgpu.py
364+
sed -i "s|ctypes.CDLL('/usr/local/lib/libwebgpu_dawn.so')|ctypes.CDLL(ctypes.util.find_library('webgpu_dawn'))|g" $BASE/webgpu.py
365+
python3 -c "import tinygrad.runtime.autogen.webgpu"
366+
}
367+
360368
if [ "$1" == "opencl" ]; then generate_opencl
361369
elif [ "$1" == "hip" ]; then generate_hip
362370
elif [ "$1" == "comgr" ]; then generate_comgr
@@ -375,6 +383,7 @@ elif [ "$1" == "kgsl" ]; then generate_kgsl
375383
elif [ "$1" == "adreno" ]; then generate_adreno
376384
elif [ "$1" == "pci" ]; then generate_pciaccess
377385
elif [ "$1" == "vfio" ]; then generate_vfio
378-
elif [ "$1" == "all" ]; then generate_opencl; generate_hip; generate_comgr; generate_cuda; generate_nvrtc; generate_hsa; generate_kfd; generate_nv; generate_amd; generate_io_uring; generate_libc; generate_am
386+
elif [ "$1" == "webgpu" ]; then generate_webgpu
387+
elif [ "$1" == "all" ]; then generate_opencl; generate_hip; generate_comgr; generate_cuda; generate_nvrtc; generate_hsa; generate_kfd; generate_nv; generate_amd; generate_io_uring; generate_libc; generate_am; generate_webgpu
379388
else echo "usage: $0 <type>"
380389
fi

docs/runtime.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ tinygrad supports various runtimes, enabling your code to scale across a wide ra
1212
| [GPU (OpenCL)](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_gpu.py) | Accelerates computations using OpenCL on GPUs | OpenCL 2.0 compatible device |
1313
| [CLANG (C Code)](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_clang.py) | Runs on CPU using the clang compiler | `clang` compiler in system `PATH` |
1414
| [LLVM (LLVM IR)](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_llvm.py) | Runs on CPU using the LLVM compiler infrastructure | llvm libraries installed and findable |
15+
| [WEBGPU](https://github.com/tinygrad/tinygrad/tree/master/tinygrad/runtime/ops_webgpu.py) | Runs on GPU using the Dawn WebGPU engine (used in Google Chrome) | Dawn library installed and findable. Download binaries [here](https://github.com/wpmed92/pydawn/releases/tag/v0.1.6). |

0 commit comments

Comments
 (0)