Skip to content

Commit ba32717

Browse files
committed
feat: 1. Modified the 'lib' rule in the Makefile file located in the root directory of the project, allowing it to generate gpu.cpp dynamic libraries with different suffixes based on the system.
2. By the build.py script, the header files in the gpu.hpp file are expanded in order to make gpu.hpp become true header-only source code. 3. 'install' and 'uninstall' rules are provided for scientific researchers who do not care about how to package applications, enabling them to quickly utilize gpu.cpp for gpu computation.
1 parent 01cbcf9 commit ba32717

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

Makefile

+45-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,51 @@ pch:
1919
mkdir -p build && $(CXX) -std=c++17 $(INCLUDES) -x c++-header gpu.hpp -o build/gpu.hpp.pch
2020

2121
# TODO(avh): change extension based on platform
22-
lib:
23-
mkdir -p build && $(CXX) -std=c++17 $(INCLUDES) -L$(LIBDIR) -ldawn -ldl -shared -fPIC gpu.cpp -o build/libgpucpp.dylib
22+
# Get the current OS name
23+
OS = $(shell uname | tr -d '\n')
24+
LIB_PATH ?= /usr/lib
25+
HEADER_PATH ?= /usr/include
26+
# Set the specific variables for each platform
27+
ifeq ($(OS), Linux)
28+
OS_TYPE ?= Linux
29+
30+
GPU_CPP_LIB_NAME ?= libgpucpp.so
31+
DAWN_LIB_NAME ?= libdawn.so
32+
else ifeq ($(OS), Darwin)
33+
OS_TYPE ?= macOS
34+
35+
GPU_CPP_LIB_NAME ?= libgpucpp.dylib
36+
DAWN_LIB_NAME ?= libdawn.dylib
37+
else
38+
OS_TYPE ?= unknown
39+
endif
40+
41+
lib: check-clang dawnlib
42+
ifneq ($(OS_TYPE), unknown)
43+
mkdir -p build && $(CXX) -std=c++17 $(INCLUDES) -L$(LIBDIR) -ldawn -ldl -shared -fPIC gpu.cpp -o build/$(GPU_CPP_LIB_NAME)
44+
python3 build.py
45+
cp third_party/lib/$(DAWN_LIB_NAME) build/
46+
else
47+
@echo "Unsupported operating system"
48+
endif
49+
50+
install:
51+
ifneq ($(OS_TYPE), unknown)
52+
cp build/$(GPU_CPP_LIB_NAME) $(LIB_PATH)
53+
cp build/$(DAWN_LIB_NAME) $(LIB_PATH)
54+
cp build/gpu.hpp $(HEADER_PATH)
55+
else
56+
@echo "Unsupported operating system"
57+
endif
58+
59+
uninstall:
60+
ifneq ($(OS_TYPE), unknown)
61+
rm $(LIB_PATH)/$(GPU_CPP_LIB_NAME)
62+
rm $(LIB_PATH)/$(DAWN_LIB_NAME)
63+
rm $(HEADER_PATH)/gpu.hpp
64+
else
65+
@echo "Unsupported operating system"
66+
endif
2467

2568
examples/hello_world/build/hello_world: check-clang dawnlib examples/hello_world/run.cpp check-linux-vulkan
2669
$(LIBSPEC) && cd examples/hello_world && make build/hello_world && ./build/hello_world

build.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Dictionary of header files and their relative paths
2+
header_files = {
3+
"#include \"webgpu/webgpu.h\"": "third_party/headers/webgpu/webgpu.h",
4+
"#include \"numeric_types/half.hpp\"": "numeric_types/half.hpp",
5+
"#include \"utils/logging.hpp\"": "utils/logging.hpp"
6+
}
7+
8+
def main():
9+
# File paths
10+
source_file_path = "gpu.hpp"
11+
output_file_path = "build/gpu.hpp"
12+
13+
# Open source file and read contents
14+
with open(source_file_path, "r") as source:
15+
file_contents = source.read()
16+
17+
# Ergodic over header files
18+
for key, value in header_files.items():
19+
20+
# Replace header files
21+
with open(value, "r") as header_file:
22+
header_file_contents = header_file.read()
23+
file_contents = file_contents.replace(key, header_file_contents)
24+
25+
26+
# Open output file
27+
with open(output_file_path, "w") as output:
28+
# Write contents to output file
29+
output.write(file_contents)
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)