forked from albertozeni/GPU101-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·60 lines (48 loc) · 1.8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
### setting the enviroment ###
CCX := clang++
BINARY := linear_solve
DEPFLAGS := -MP -MD
BUILD_DIR := ./build
SRC_DIR := ./src
TESTS_DIR := ./test
CUDA_PATH := ${CUDA_PATH}
THREADS = $(shell nproc --all)
### compilation flags ###
CXXFLAGS := -Wextra -Wall # -flto
debug: CXXFLAGS += -g3 # -fsanitize=undefined -fsanitize=address # -fsanitize=memory
debug: SHARED_FLAGS := -g -DDEBUG
debug: $(BUILD_DIR)/$(BINARY)
### gather source code files ###
SRC_FILES := $(shell find $(SRC_DIR) -name '*.cpp' -or -name '*.cu')
OBJS := $(SRC_FILES:%=$(BUILD_DIR)/%.o)
INC_DIRS := $(shell find $(SRC_DIR) -type d)
INCLUDE_FLAGS := $(addprefix -I,$(INC_DIRS)) -MMD -MP
### C++ ###
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CCX) $(INCLUDE_FLAGS) $(CXXFLAGS) $(SHARED_FLAGS) -c $< -o $@
### CUDA ###
$(BUILD_DIR)/%.cu.o: %.cu
mkdir -p $(dir $@)
nvcc $(INCLUDE_FLAGS) $(SHARED_FLAGS) --dlink-time-opt -dc -dlink $< -o $@ -lcudart -lcublas -lcudadevrt
# The final build step.
$(BUILD_DIR)/$(BINARY): $(OBJS)
# see https://stackoverflow.com/questions/17278932/cuda-shared-library-linking-undefined-reference-to-cudaregisterlinkedbinary for linking with clang++
nvcc $(OBJS) $(SHARED_FLAGS) --dlink-time-opt -o $@
-include $(OBJS:.o=.d)
### tests ###
test:
$(info see ./test directory for tests)
@echo "execute this: ${CUDA_PATH}/extras/compute-sanitizer/compute-sanitizer ./${BINARY} ../kmer_V4a.mtx";
@echo "debug cuda kernerls with: cuda-gdb --args ${BINARY} ../kmer_V4a.mtx"
@echo "profiling: ${CUDA_PATH}/nsight_systems/bin/nsys-ui ${BINARY} ../kmer_V4a.mtx"
@echo "profiling: ${CUDA_PATH}/nsight_compute/ncu-ui ${BINARY} ../kmer_V4a.mtx"
cd test && $(MAKE)
### other ###
clean:
rm -rf build
diff:
$(info The status of the repository, and the volume of per-file changes:)
@git status
@git diff --stat
.PHONY: clean diff test