forked from ThreeMonth03/Conjugate-Gradient-Method-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
88 lines (75 loc) · 2.75 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
WORKING_DIR = $(shell pwd)
#Flags
CXX = /usr/bin/g++-10
NVCC = nvcc
FLAGS_CPU = -g -O3 -m64 -Wall -shared -std=c++17 -fPIC -fopenmp -pthread -ffast-math -ftree-vectorize
FLAGS_GPU_COMPILE = -g -O3 -m64 -shared -std=c++17 -rdc=true -Xcompiler '-fPIC' --compiler-bindir=$(CXX) -Xcompiler -fopenmp
FLAGS_GPU_LINK = -shared -Xcompiler '-fPIC' --compiler-bindir=$(CXX) -lgomp
PYBINCLUDE = $(shell python3-config --includes) $(shell python3 -m pybind11 --includes)
FLAGS_DEP = -MMD -MP
DIRS_CPU = $(WORKING_DIR)/cpp/matrix/naive $(WORKING_DIR)/cpp/cg_method $(WORKING_DIR)/cpp/matrix/cpu
CXXINCLUDE_CPU := $(patsubst %,-I %,$(DIRS_CPU))
DIRS_GPU = $(WORKING_DIR)/cpp/matrix/gpu
CXXINCLUDE_GPU := $(patsubst %,-I %,$(DIRS_GPU))
#PATH
MODULE_SHARE_OBJS_RLT_DIR = cpp
MODULE_SHARE_OBJS_ABS_DIR = $(WORKING_DIR)/$(MODULE_SHARE_OBJS_RLT_DIR)
PYTHONPATH := $(MODULE_SHARE_OBJS_ABS_DIR):$(PYTHONPATH)
export PYTHONPATH
#Includes
CPP_FILE_CPU = $(wildcard $(MODULE_SHARE_OBJS_RLT_DIR)/matrix/cpu/*.cpp)
CPP_FILE_GPU = $(wildcard $(MODULE_SHARE_OBJS_RLT_DIR)/matrix/gpu/*.cu)
CPP_FILE_SHARED = $(wildcard $(MODULE_SHARE_OBJS_RLT_DIR)/pybind/*.cpp) $(wildcard $(MODULE_SHARE_OBJS_RLT_DIR)/cg_method/*.cpp) $(wildcard $(MODULE_SHARE_OBJS_RLT_DIR)/matrix/naive/*.cpp)
MODULE_SHARE_OBJS = $(MODULE_SHARE_OBJS_RLT_DIR)/_cgpy$(shell python3-config --extension-suffix)
#dependency
DEPS = $(TARGET:.o=.d)
-include $(DEPS)
# CPU/GPU selection in linking stage
TARGET_CPU = $(CPP_FILE_CPU:.cpp=.o)
TARGET_GPU = $(CPP_FILE_GPU:.cu=.o)
TARGET_SHARED = $(CPP_FILE_SHARED:.cpp=.o)
TARGET += $(TARGET_SHARED)
ifeq ($(GPU),1)
LINKER = $(NVCC)
LINK_FLAGS = $(FLAGS_GPU_LINK)
TARGET += $(TARGET_GPU)
else
LINKER = $(CXX)
LINK_FLAGS = $(FLAGS_CPU)
TARGET += $(TARGET_CPU)
endif
#Makefile
.PHONY: all demo test clean rebuild
default: all
rebuild:
$(MAKE) all
$(MAKE) test
all:
make clean
make $(MODULE_SHARE_OBJS)
$(MODULE_SHARE_OBJS): $(TARGET)
$(LINKER) $(LINK_FLAGS) $^ -o $@
$(TARGET_CPU): %.o : %.cpp
$(CXX) $(FLAGS_CPU) $(FLAGS_DEP) $(PYBINCLUDE) $(CXXINCLUDE_CPU) -c $< -o $@
$(TARGET_GPU): %.o : %.cu
$(NVCC) $(FLAGS_GPU_COMPILE) $(FLAGS_DEP) $(PYBINCLUDE) $(CXXINCLUDE_GPU) -c $< -o $@
$(TARGET_SHARED): %.o : %.cpp
$(CXX) $(FLAGS_CPU) $(FLAGS_DEP) $(PYBINCLUDE) $(CXXINCLUDE_CPU) -c $< -o $@
demo:
$(MAKE) all
mkdir -p demo/results
python3 demo/demo_matrix.py | tee demo/results/matrix_performance.txt
python3 demo/demo_cg_method.py | tee demo/results/cg_method_performance.txt
test:
$(MAKE) all
python3 -m pytest -v tests/test_matrix.py
python3 -m pytest -v tests/test_cg_method.py
clean:
rm -rf *.so cpp/*.so cpp/*/*.so
rm -rf cpp/*/*.o
rm -rf */__pycache__ cpp/*/__pycache__
rm -rf .pytest_cache */.pytest_cache
rm -rf demo/results
rm -rf cpp/*/*.d
rm -rf cpp/*/*/*.d
rm -rf cpp/*/*/*.o