-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmakefile
96 lines (81 loc) · 3.26 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
89
90
91
92
93
94
95
96
#if cuda architecture not specified then assume 50, i.e. -arch=sm_50
#arch value for required architecture should be:
#arch=50 for Maxwell
#arch=60 for Pascal
#arch=70 for Volta (and Turing)
#arch=80 for Ampere
#arch=90 for Ada (and Hopper)
#example: $ make configure arch=80 sprec=1 python=3.8 cuda=12.0
ifndef arch
arch = $(file < arch.txt)
endif
ifndef python
python = $(file < python.txt)
endif
ifndef cuda
cuda = $(file < cuda.txt)
endif
#if you want to compile cuda code in double precision then $ make configure sprec=0
ifndef sprec
sprec = 1
endif
ifndef conda-env-path
conda-env-path = $(file < conda-env-path.txt)
endif
ifeq ($(conda-env-path),)
python-include-path := -I/usr/include/python$(python)/
install-linker := -lpython$(python)
python-distribution := "Using system installed"
else
python-include-path := -I$(conda-env-path)/include/python$(python)/
install-linker := $(shell $(conda-env-path)/bin/python$(python)-config --ldflags --embed) -Wl,-rpath,$(conda-env-path)/lib
python-distribution := "Using python from conda $(conda-env-path)"
endif
#Boris program version
BVERSION := 380
#Source directories for make
SRC_DIR := Boris
OBJ_DIR := Boris/Boris_o
CUOBJ_DIR := Boris/Boris_cuo
SRC_CPP_FILES := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_CPP_FILES))
SRC_CU_FILES := $(wildcard $(SRC_DIR)/*.cu)
CUOBJ_FILES := $(patsubst $(SRC_DIR)/%.cu,$(CUOBJ_DIR)/%.o,$(SRC_CU_FILES))
.PHONY: clean
clean:
rm -f $(OBJ_FILES) $(CUOBJ_FILES) $(CUOBJ_DIR)/rdc_link.o BorisLin
#compile only cpp files
cpp: $(OBJ_FILES)
@echo Done
#compile only cu files
cuda: $(CUOBJ_FILES)
@echo Done
#configure CUDA compilation first: architecture and float precision. Also set Python version and CUDA Toolkit version.
configure:
$(file > BorisCUDALib/cuBLib_Flags.h,#pragma once)
$(file >> BorisCUDALib/cuBLib_Flags.h,)
$(file >> BorisCUDALib/cuBLib_Flags.h,)
$(file >> BorisCUDALib/cuBLib_Flags.h,#define __CUDA_ARCH__ $(arch)0)
$(file >> BorisCUDALib/cuBLib_Flags.h,)
$(file >> BorisCUDALib/cuBLib_Flags.h,)
$(file >> BorisCUDALib/cuBLib_Flags.h,#define SINGLEPRECISION $(sprec))
$(file > arch.txt,$(arch))
$(file > python.txt,$(python))
$(file > cuda.txt,$(cuda))
$(file > conda-env-path.txt,$(conda-env-path))
mkdir -p $(OBJ_DIR)
mkdir -p $(CUOBJ_DIR)
@echo Configured for -arch=sm_$(arch) and SINGLEPRECISION = $(sprec). $(python-distribution) python version $(python). CUDA Toolkit version $(cuda).
#compile both cpp and cu files
compile: $(OBJ_FILES) $(CUOBJ_FILES)
@echo Done
install:
nvcc -arch=sm_$(arch) -dlink -w $(CUOBJ_DIR)/*.o -o $(CUOBJ_DIR)/rdc_link.o
g++ $(OBJ_DIR)/*.o $(CUOBJ_DIR)/*.o -fopenmp $(install-linker) -ltbb -lfftw3 -lX11 -L/usr/local/cuda-$(cuda)/targets/x86_64-linux/lib/ -lcudart -lcufft -lcudadevrt -o BorisLin
#rm -f $(OBJ_FILES) $(CUOBJ_FILES) $(CUOBJ_DIR)/rdc_link.o
@echo Done
#for python3.8 make sure to get dev version : sudo apt-get install python3.8-dev
Boris/Boris_o/%.o: Boris/%.cpp
g++ -I/usr/local/cuda-$(cuda)/targets/x86_64-linux/include/ -c -Ofast -std=c++17 $(python-include-path) -IBorisLib -IBorisCUDALib -fopenmp $< -o $@
Boris/Boris_cuo/%.o: Boris/%.cu
nvcc -I/usr/local/cuda-$(cuda)/targets/x86_64-linux/include/ -rdc=true -c -std=c++14 -IBorisLib -IBorisCUDALib -w -arch=sm_$(arch) $< -o $@