-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
82 lines (60 loc) · 2.28 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
CC = g++
CXXOPTS = -std=c++17 -Wall -Werror -lpthread -O2
NVCCOPTS = -arch=sm_75
SDIR = src
NVSDIR = src_cuda
INC = -I src
CUDA_INC = -I src_cuda
CUDA_INC += -I NVIDIA_SDK_Samples/common/inc
CUDA_INC += -I /usr/local/cuda/include
ODIR = obj
XDIR = bin
# Make directories for object files
$(shell mkdir -p obj/cpu)
$(shell mkdir -p obj/cuda)
$(shell mkdir -p obj/cuda_shared)
# Object file lists
# Separate into lists (by folder) for cpu, cuda, cuda_shared, and thrust
OBJS_CPU = $(addprefix obj/cpu/, argparse.o io.o kmeans.o main.o random.o)
OBJS_CUDA = $(addprefix obj/cuda/, argparse.o io.o kmeans_kernels.o main.o random.o)
OBJS_CUDA_SHARED = $(addprefix obj/cuda_shared/, argparse.o io.o kmeans_kernels.o main.o random.o)
all: sequential
sequential: $(OBJS_CPU)
mkdir -p bin
$(CC) $(ODIR)/cpu/*.o $(CXXOPTS) $(INC) -o $(XDIR)/kmeans_cpu
cuda: $(OBJS_CUDA)
mkdir -p bin
nvcc $(ODIR)/cuda/*.o $(NVCCOPTS) $(INC) $(CUDA_INC) -o $(XDIR)/kmeans_cuda
cuda_shared: $(OBJS_CUDA_SHARED)
mkdir -p bin
nvcc $(ODIR)/cuda_shared/*.o $(NVCCOPTS) $(INC) $(CUDA_INC) -o $(XDIR)/kmeans_cuda_shared
thrust:
clean:
rm -f $(XDIR)/*
# Create object file (.o) from source (.cpp)
# % matches a pattern (argparse, io, kmeans, main, ...)
# $< expands to 1st item in prerequisite list
# $@ expands to target
# Different versions of main by preprocessor define (-D) flags
$(ODIR)/cpu/main.o: $(SDIR)/main.cpp
$(CC) $(INC) $(CUDA_INC) -D CPU -c $< -o $@
$(ODIR)/cuda/main.o: $(SDIR)/main.cpp
nvcc $(NVCCOPTS) $(INC) $(CUDA_INC) -D CUDA -c $< -o $@
$(ODIR)/cuda_shared/main.o: $(SDIR)/main.cpp
nvcc $(NVCCOPTS) $(INC) $(CUDA_INC) -D CUDA_SHARED -c $< -o $@
$(ODIR)/thrust/main.o: $(SDIR)/main.cpp
nvcc $(NVCCOPTS) $(INC) $(CUDA_INC) -D THRUST -c $< -o $@
# Kernels
$(ODIR)/cuda/kmeans_kernels.o: $(NVSDIR)/kmeans_kernels.cu
nvcc $(NVCCOPTS) $(INC) $(CUDA_INC) -D CUDA -c $< -o $@
$(ODIR)/cuda_shared/kmeans_kernels.o: $(NVSDIR)/kmeans_kernels.cu
nvcc $(NVCCOPTS) $(INC) $(CUDA_INC) -D CUDA_SHARED -c $< -o $@
# Other object files
$(ODIR)/cpu/%.o: $(SDIR)/%.cpp
$(CC) $(INC) $(CUDA_INC) -c $< -o $@
$(ODIR)/cuda/%.o: $(SDIR)/%.cpp
$(CC) $(INC) $(CUDA_INC) -c $< -o $@
$(ODIR)/cuda_shared/%.o: $(SDIR)/%.cpp
$(CC) $(INC) $(CUDA_INC) -c $< -o $@
$(ODIR)/thrust/%.o: $(SDIR)/%.cpp
$(CC) $(INC) $(CUDA_INC) -c $< -o $@