-
Notifications
You must be signed in to change notification settings - Fork 3
/
makefile.acc
94 lines (76 loc) · 3.71 KB
/
makefile.acc
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
# Compiler and Flags
CC := nvc++
NVHPC_INCLUDE_PATH := /leonardo/prod/spack/5.2/install/0.21/linux-rhel8-icelake/gcc-8.5.0/nvhpc-24.3-v63z4inohb4ywjeggzhlhiuvuoejr2le/Linux_x86_64/24.3
CUDA_INCLUDE_PATH := $(NVHPC_INCLUDE_PATH)/cuda/12.3/include
export LD_LIBRARY_PATH=/leonardo/prod/spack/5.2/install/0.21/linux-rhel8-icelake/gcc-8.5.0/nvhpc-24.3-v63z4inohb4ywjeggzhlhiuvuoejr2le/Linux_x86_64/24.3/cuda/12.3/targets/x86_64-linux/lib/stubs:$LD_LIBRARY_PATH
CUDA_LIB_PATH=$NVHPC_INCLUDE_PATH/cuda/12.3/targets/x86_64-linux/lib
export LD_LIBRARY_PATH=$CUDA_LIB_PATH:$LD_LIBRARY_PATH
CXXFLAGS := -std=c++11 -O3 -I$(CUDA_INCLUDE_PATH)
OMPFLAGS := -fopenmp -mp -c -I$(CUDA_INCLUDE_PATH)
# OpenACC / GPU Specific Compiler and Flags
ACCFLAGS := -mp -acc -gpu=cc80,managed,cuda12.3,lineinfo -Minfo=acc ###-Minline=1000
LINKFLAGS := -I$(CUDA_INCLUDE_PATH) -lcudart -lcublas -lcufft -lcusolver -lm -lcudart -cudalib=nvtx3 # Linking CUDA runtime
# Directories
BIN_FOLDER := bin
OBJ_FOLDER := bin/obj
SRC_FOLDER := src
OMP_BIN_FOLDER := omp_bin
OMP_OBJ_FOLDER := omp_bin/obj
OMP_SRC_FOLDER := omp_src
ACC_BIN_FOLDER := acc_bin
ACC_OBJ_FOLDER := acc_bin/obj
ACC_SRC_FOLDER := acc_src
TEST_BIN_FOLDER := test_bin
TEST_OBJ_FOLDER := test_bin/obj
TEST_SRC_FOLDER := test_src
# All target (with optional OpenMP and OpenACC executables)
all: $(BIN_FOLDER)/vit.exe $(OMP_BIN_FOLDER)/vit.exe $(ACC_BIN_FOLDER)/vit.exe
# Clean build
clean:
# Remove all object and binary directories
rm -rf $(BIN_FOLDER) $(OBJ_FOLDER) $(OMP_BIN_FOLDER) $(OMP_OBJ_FOLDER) \
$(ACC_BIN_FOLDER) $(ACC_OBJ_FOLDER) $(TEST_BIN_FOLDER) $(TEST_OBJ_FOLDER) \
./out_comparison ./test_files
# OBJs (for CPU build using standard g++)
$(OBJ_FOLDER)/%.o: $(SRC_FOLDER)/%.cpp
@mkdir -p $(OBJ_FOLDER)
$(CC) -c $(CXXFLAGS) $^ -o $@
# Executable for CPU
$(BIN_FOLDER)/vit.exe: $(OBJ_FOLDER)/datatypes.o $(OBJ_FOLDER)/modules.o $(OBJ_FOLDER)/mlp.o \
$(OBJ_FOLDER)/conv2d.o $(OBJ_FOLDER)/attention.o $(OBJ_FOLDER)/block.o $(OBJ_FOLDER)/patch_embed.o \
$(OBJ_FOLDER)/vision_transformer.o $(OBJ_FOLDER)/utils.o $(OBJ_FOLDER)/main.o
@mkdir -p $(BIN_FOLDER)
$(CC) $(CXXFLAGS) $^ -o $@
# OBJs for OpenMP Build
$(OMP_OBJ_FOLDER)/%.o: $(OMP_SRC_FOLDER)/%.cpp
@mkdir -p $(OMP_OBJ_FOLDER)
$(CC) -c $(CXXFLAGS) $(OMPFLAGS) $^ -o $@
# Executable for OpenMP Build
$(OMP_BIN_FOLDER)/vit.exe: $(OMP_OBJ_FOLDER)/datatypes.o $(OMP_OBJ_FOLDER)/modules.o \
$(OBJ_FOLDER)/mlp.o $(OMP_OBJ_FOLDER)/conv2d.o $(OMP_OBJ_FOLDER)/attention.o \
$(OBJ_FOLDER)/block.o $(OBJ_FOLDER)/patch_embed.o $(OMP_OBJ_FOLDER)/vision_transformer.o \
$(OBJ_FOLDER)/utils.o $(OBJ_FOLDER)/main.o
@mkdir -p $(OMP_BIN_FOLDER)
$(CC) $(CXXFLAGS) $(OMPFLAGS) $^ -o $@
# OBJs for OpenACC Build (GPU)
$(ACC_OBJ_FOLDER)/%.o: $(ACC_SRC_FOLDER)/%.cpp
@mkdir -p $(ACC_OBJ_FOLDER)
$(CC) -c $(ACCFLAGS) $^ -o $@
# Executable for OpenACC Build (GPU)
$(ACC_BIN_FOLDER)/vit.exe: $(ACC_OBJ_FOLDER)/datatypes.o $(ACC_OBJ_FOLDER)/modules.o \
$(OBJ_FOLDER)/mlp.o $(ACC_OBJ_FOLDER)/conv2d.o $(ACC_OBJ_FOLDER)/attention.o \
$(OBJ_FOLDER)/block.o $(OBJ_FOLDER)/patch_embed.o $(ACC_OBJ_FOLDER)/vision_transformer.o \
$(OBJ_FOLDER)/utils.o $(OBJ_FOLDER)/main.o
@mkdir -p $(ACC_BIN_FOLDER)
$(CC) $(ACCFLAGS) $^ -o $@ $(LINKFLAGS)
# Test OBJs (same for CPU, OpenMP, or OpenACC)
$(TEST_OBJ_FOLDER)/%.o: $(TEST_SRC_FOLDER)/%.cpp
@mkdir -p $(TEST_OBJ_FOLDER)
$(CC) -c $(CXXFLAGS) $^ -o $@
# Test Executables (CPU Build)
$(TEST_BIN_FOLDER)/test_%.exe: $(OBJ_FOLDER)/datatypes.o $(OBJ_FOLDER)/modules.o $(OBJ_FOLDER)/mlp.o \
$(OBJ_FOLDER)/conv2d.o $(OBJ_FOLDER)/attention.o $(OBJ_FOLDER)/block.o \
$(OBJ_FOLDER)/patch_embed.o $(OBJ_FOLDER)/vision_transformer.o \
$(OBJ_FOLDER)/utils.o $(OBJ_FOLDER)/main.o $(TEST_OBJ_FOLDER)/%.o
@mkdir -p $(TEST_BIN_FOLDER)
$(CC) $(CXXFLAGS) $^ -o $@