Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
NUM_JOBS=$(shell nproc)
OS := $(shell uname | tr -d '\n')

ifeq ($(OS),Darwin)
NUM_JOBS := $(shell sysctl -n hw.ncpu)
else
NUM_JOBS := $(shell nproc)
endif

CXX=clang++

.PHONY: default examples/hello_world/build/hello_world tests libgpu debug build check-clang clean-build clean all watch-tests docs
Expand All @@ -20,7 +27,7 @@ pch:

# TODO(avh): change extension based on platform
# Get the current OS name
OS = $(shell uname | tr -d '\n')

# Set the specific variables for each platform
LIB_PATH ?= /usr/lib
HEADER_PATH ?= /usr/include
Expand Down Expand Up @@ -89,7 +96,13 @@ RELEASE_FLAGS = $(FLAGS) -DFASTBUILD:BOOL=OFF
TARGET_LIB=gpu

libgpu-cmake: check-clang check-cmake
$(CMAKE_CMD) $(RELEASE_FLAGS) && make -j$(NUM_JOBS) gpu
$(CMAKE_CMD) $(RELEASE_FLAGS) && cmake --build . --parallel $(NUM_JOBS) --target gpud
mkdir -p third_party/lib
ifeq ($(OS),Darwin)
find third_party/fetchcontent -name "*.dylib" -exec cp {} third_party/lib/ \;
else ifeq ($(OS),Linux)
find third_party/fetchcontent -name "*.so*" -exec cp {} third_party/lib/ \;
endif

debug-cmake: check-clang check-cmake
$(CMAKE_CMD) $(DEBUG_FLAGS) && make -j$(NUM_JOBS) $(TARGET_ALL)
Expand All @@ -102,7 +115,7 @@ all-cmake: check-clang check-cmake
################################################################################

clean-dawnlib:
rm -f third_party/lib/libwebgpu_dawn.so third_party/lib/libwebgpu_dawn.dylib
rm -f third_party/lib/*.so third_party/lib/*.so.* third_party/lib/*.dylib

clean:
read -r -p "This will delete the contents of build/*. Are you sure? [CTRL-C to abort] " response && rm -rf build/*
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ Optionally, Dawn can be built from scratch with gpu.cpp using the cmake build sc
After cloning the repo, from the top-level gpu.cpp, you should be able to build and run the hello world GELU example by typing:

```
make
make libgpu-cmake
cd examples
make clean
make hello_world
make run_hello_world
```

The first time you build and run the project this way, it will download a prebuilt shared library for the Dawn native WebGPU implementation automatically (using the setup.py script). This places the Dawn shared library in the `third_party/lib` directory. Afterwards you should see `libdawn.dylib` on MacOS or `libdawn.so` on Linux. This download only occurs once.
Expand Down
14 changes: 4 additions & 10 deletions cmake/webgpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,13 @@ endif()

option(WEBGPU_TAG "WebGPU distribution tag to use")
if(NOT WEBGPU_TAG)
set(WEBGPU_TAG "dawn")
set(WEBGPU_TAG "main")
endif()
message(STATUS "Using WebGPU distribution tag: ${WEBGPU_TAG}")

if(WEBGPU_TAG STREQUAL "dawn")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWEBGPU_BACKEND_DAWN")
# use specific commit set(WEBGPU_TAG
# "1025b977e1927b6d0327e67352f90feb4bcf8274") set(WEBGPU_TAG
# "acf972b7b909f52e183bdae3971b93bb13d4a29e")
# add_compile_options(-UABSL_INTERNAL_AT_LEAST_CXX20) set(CMAKE_CXX_FLAGS
# "${CMAKE_CXX_FLAGS} -UABSL_INTERNAL_AT_LEAST_CXX20")
message(STATUS "Using Dawn backend")
endif()
set(WEBGPU_BACKEND "DAWN" CACHE STRING "WebGPU backend")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWEBGPU_BACKEND_DAWN")
message(STATUS "Using Dawn backend")

FetchContent_Declare(
webgpu
Expand Down
4 changes: 2 additions & 2 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
endif

FLAGS=-std=c++17 $(STDLIB) -I$(GPUCPP) -I$(GPUCPP)/third_party/headers -L$(GPUCPP)/third_party/lib
LFLAGS=-ldl -lwebgpu_dawn
LFLAGS=-Wl,-rpath,$(GPUCPP)/third_party/lib -ldl -lwebgpu_dawn

.PHONY: default all_release all_debug dawnlib run_setup check-python
.PHONY: $(addsuffix _release, $(TARGETS))
Expand Down Expand Up @@ -57,7 +57,7 @@ $(foreach target,$(TARGETS),$(eval $(call CLEAN_RULES,$(target))))

clean: $(addprefix clean_, $(TARGETS))

dawnlib: $(if $(wildcard $(GPUCPP)/third_party/lib/libdawn.so $(GPUCPP)/third_party/lib/libdawn.dylib),,run_setup)
dawnlib: $(if $(wildcard $(GPUCPP)/third_party/lib/libwebgpu_dawn.so $(GPUCPP)/third_party/lib/libwebgpu_dawn.dylib),,run_setup)

run_setup: check-python
cd $(GPUCPP) && (command -v python3 >/dev/null 2>&1 && python3 setup.py || python setup.py)
Expand Down
Empty file removed third_party/fetchcontent/.gitkeep
Empty file.