Skip to content

Some changes about the dynamic libraries generated by gpu.cpp project and header-only source code 'gpu.hpp' #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2024
Merged
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
47 changes: 45 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -19,8 +19,51 @@ pch:
mkdir -p build && $(CXX) -std=c++17 $(INCLUDES) -x c++-header gpu.hpp -o build/gpu.hpp.pch

# TODO(avh): change extension based on platform
lib:
mkdir -p build && $(CXX) -std=c++17 $(INCLUDES) -L$(LIBDIR) -ldawn -ldl -shared -fPIC gpu.cpp -o build/libgpucpp.dylib
# Get the current OS name
OS = $(shell uname | tr -d '\n')
LIB_PATH ?= /usr/lib
HEADER_PATH ?= /usr/include
# Set the specific variables for each platform
ifeq ($(OS), Linux)
OS_TYPE ?= Linux

GPU_CPP_LIB_NAME ?= libgpucpp.so
DAWN_LIB_NAME ?= libdawn.so
else ifeq ($(OS), Darwin)
OS_TYPE ?= macOS

GPU_CPP_LIB_NAME ?= libgpucpp.dylib
DAWN_LIB_NAME ?= libdawn.dylib
else
OS_TYPE ?= unknown
endif

lib: check-clang dawnlib
ifneq ($(OS_TYPE), unknown)
mkdir -p build && $(CXX) -std=c++17 $(INCLUDES) -L$(LIBDIR) -ldawn -ldl -shared -fPIC gpu.cpp -o build/$(GPU_CPP_LIB_NAME)
python3 build.py
cp third_party/lib/$(DAWN_LIB_NAME) build/
else
@echo "Unsupported operating system"
endif

install:
ifneq ($(OS_TYPE), unknown)
cp build/$(GPU_CPP_LIB_NAME) $(LIB_PATH)
cp build/$(DAWN_LIB_NAME) $(LIB_PATH)
cp build/gpu.hpp $(HEADER_PATH)
else
@echo "Unsupported operating system"
endif

uninstall:
ifneq ($(OS_TYPE), unknown)
rm $(LIB_PATH)/$(GPU_CPP_LIB_NAME)
rm $(LIB_PATH)/$(DAWN_LIB_NAME)
rm $(HEADER_PATH)/gpu.hpp
else
@echo "Unsupported operating system"
endif

examples/hello_world/build/hello_world: check-clang dawnlib examples/hello_world/run.cpp check-linux-vulkan
$(LIBSPEC) && cd examples/hello_world && make build/hello_world && ./build/hello_world
32 changes: 32 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Dictionary of header files and their relative paths
header_files = {
"#include \"webgpu/webgpu.h\"": "third_party/headers/webgpu/webgpu.h",
"#include \"numeric_types/half.hpp\"": "numeric_types/half.hpp",
"#include \"utils/logging.hpp\"": "utils/logging.hpp"
}

def main():
# File paths
source_file_path = "gpu.hpp"
output_file_path = "build/gpu.hpp"

# Open source file and read contents
with open(source_file_path, "r") as source:
file_contents = source.read()

# Ergodic over header files
for key, value in header_files.items():

# Replace header files
with open(value, "r") as header_file:
header_file_contents = header_file.read()
file_contents = file_contents.replace(key, header_file_contents)


# Open output file
with open(output_file_path, "w") as output:
# Write contents to output file
output.write(file_contents)

if __name__ == "__main__":
main()