Skip to content

Commit ed70960

Browse files
committedAug 2, 2024·
move wasm build from experimental to examples, delete deprecated emscripten-free wasm experiments
1 parent b4b44e0 commit ed70960

File tree

17 files changed

+57
-716
lines changed

17 files changed

+57
-716
lines changed
 

‎examples/README.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
# Examples (Work-in-Progress)
1+
# gpu.cpp examples
22

3-
Here are some standalone projects exemplifying how to use this library as well
4-
as what's under the hood.
3+
This directory contains examples of how to use gpu.cpp.
54

6-
Note some of these examples are still a work-in-progress and may not be fully
7-
functional.
5+
Each example is a standalone project that can be built and run independently by
6+
running `make` from within the example directory.
87

9-
In order of beginning to advanced:
8+
Before running any of these examples, make sure you've downloaded the Dawn
9+
native webgpu installation binary by running `make dawnlib` from the root
10+
directory of the repository.
11+
12+
## Basic Examples
1013

1114
| Example | Description |
1215
|---------|-------------|
1316
| [hello_world](hello_world) | Minimal example to get started with gpu.cpp, implements a GELU neural network activation function. |
14-
| [gpu_puzzles](gpu_puzzles) | (WIP) Implementation of Sasha Rush's GPU puzzles
15-
| [render](render) | GPU rendering of a signed distance function for a 3D sphere. |
16-
| [shadertui](shadertui) | A terminal UI taker on shadertoy demonstrating runtime live reloading of WGSL. |
17+
| [gpu_puzzles](gpu_puzzles) | Implementation of Sasha Rush's GPU puzzles. |
18+
| [shadertui](shadertui) | An example of runtime live reloading of WGSL - demonstrated using a terminal shadertoy-like scii rendering. |
19+
| [render](render) | GPU ascii rendering of a signed distance function for two rotating 3D spheres. |
1720
| [physics](physics) | Parallel physics simulation of a double pendulum with each thread starting at a different initial condition. |
21+
| [web](web) | A minimal example of how to use gpu.cpp to build a WebAssembly module that runs in the browser. Before building this example, make sure you've installed the emscripten sdk by following the [instructions here](https://emscripten.org/docs/getting_started/downloads.html) and run `source emsdk_env.sh` from the `emsdk/` directory that was created when you cloned the emscripten repository. |
22+
23+
## Advanced Examples
24+
25+
| Example | Description |
26+
|---------|-------------|
1827
| [matmul](matmul) | Tiled matrix multiplication. |
1928
| [transpose](transpose) | Tiled matrix transpose. |
2029
| [webgpu_from_scratch](webgpu_from_scratch) | A minimal from-scratch example of how to use WebGPU directly without this library. This is useful to understand the code internals of gpu.cpp. Note this takes a while to build as it compiles the WebGPU C API implementation. |

‎experimental/wasm/emscripten/CMakeLists.txt ‎examples/web/CMakeLists.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,4 @@ set(SHELL_FILE_PATH "../custom_shell.html")
1313
# see https://emscripten.org/docs/api_reference/emscripten.h.html#pseudo-synchronous-functions
1414
target_link_options(run PRIVATE "-sUSE_WEBGPU=1" "-sASYNCIFY=1" "--shell-file=${SHELL_FILE_PATH}")
1515

16-
# em++ compiler arguments
17-
target_compile_options(run PRIVATE "-sUSE_WEBGPU=1" "-sASYNCIFY=1" "--shell-file=${SHELL_FILE_PATH}")
18-
19-
20-
target_include_directories(run PRIVATE "../../../")
21-
target_include_directories(run PRIVATE "../../../numeric_types")
22-
target_include_directories(run PRIVATE "../../../utils")
16+
target_include_directories(run PRIVATE "../../")

‎examples/web/Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
GPUCPP=../..
2+
FLAGS=-std=c++17 -s USE_WEBGPU=1 -s ASYNCIFY=1 -I$(GPUCPP)
3+
4+
.PHONY: default cmake check-emsdk browser clean
5+
6+
default: server
7+
8+
build/run.html: check-emsdk run.cpp custom_shell.html
9+
em++ run.cpp -o build/run.html \
10+
$(FLAGS) \
11+
--shell-file custom_shell.html \
12+
13+
build/run.wasm: check-emsdk run.cpp custom_shell.html
14+
em++ run.cpp -o build/run.wasm \
15+
$(FLAGS) \
16+
--shell-file custom_shell.html \
17+
18+
# make clean explicit here because custom_shell.html changes don't trigger a rebuild
19+
cmake: check-emsdk clean
20+
emcmake cmake -B build && cmake --build build -j4
21+
python3 -m http.server --directory .
22+
23+
server: build/run.html
24+
@echo "\n┌───────────────────────────────────────────────────────────────────────────────────┐"
25+
@echo "│ Open http://localhost:8000/build/run.html in your browser to see the output. │"
26+
@echo "│ │"
27+
@echo "│ Press Ctrl+C to stop the server. │"
28+
@echo "└───────────────────────────────────────────────────────────────────────────────────┘\n\n"
29+
python3 -m http.server --directory .
30+
31+
open-browser:
32+
open http://127.0.0.1:8000/build/run.html
33+
34+
clean:
35+
rm -rf build/*
36+
37+
check-emsdk:
38+
@which em++ > /dev/null || (echo "emsdk not found. Please install emsdk and run 'source emsdk_env.sh' in the emsdk directory." && exit 1)
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎experimental/wasm/emscripten/Makefile

-23
This file was deleted.

‎experimental/wasm/pure_wasm/Makefile

-46
This file was deleted.

‎experimental/wasm/pure_wasm/README.md

-17
This file was deleted.

‎experimental/wasm/pure_wasm/build/.gitkeep

Whitespace-only changes.
-15 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.