-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (82 loc) · 4.39 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
97
98
# Makefile Variables #
# ------------------ #
# The name of the generated executable file
EXECUTABLE=assignment
# Directory names used for incremental build files, executable files, and the executable type (release/debug)
BUILD_DIR := build
BIN_DIR := bin
RELEASE_DIR := release
DEBUG_DIR := debug
# C and CUDA source files to be compiled
# Add any new source files you create to be compiled and linked into the executables to the list
SRCS=internal/main.cu internal/common.c internal/mainStandardDeviation.cu internal/mainConvolution.cu internal/mainDataStructure.cu src/cpu.c src/openmp.c src/cuda.cu
# Header files which if changed will result in a rebuild.
# Add any additional header files you create to this list for rebuild support.
DEPS=internal/main.h internal/common.h internal/config.h src/cpu.h src/cuda.cuh src/openmp.h
# src/helper.h external/stb_image.h external/stb_image_write.h
# Generate the list of object files from the list of source files.
OBJS=$(addsuffix .o,$(SRCS))
# Select the host C compiler and provide compiler options, for all builds, release builds and debug builds.
CC=gcc
CCFLAGS= -fopenmp -I. -Iinternal -Wall
CCFLAGS_RELEASE= -O3 -DNDEBUG
# -O1 is passed to gcc for debug builds to allow linking via nvcc with inline methods in a C host compiler. This prevents debugging of the inline methods unfortunately
CCFLAGS_DEBUG= -g -O1 -DDEBUG
# Select the device NVCC compiler and provide compiler options, for all builds, release builds and debug builds.
# Use the CUDA_ARCH variable to control the compute capability to build for.
CUDA_ARCH=61
NVCC=nvcc
NVCCFLAGS= -gencode arch=compute_$(CUDA_ARCH),code=sm_$(CUDA_ARCH) -gencode arch=compute_$(CUDA_ARCH),code=compute_$(CUDA_ARCH) -I. -Isrc -Wno-deprecated-gpu-targets
NVCCFLAGS_RELEASE= -lineinfo -O3 -DNDEBUG
NVCCFLAGS_DEBUG= -g -G -DDEBUG
# Build rules #
# ----------- #
# Default build rule - build the release executable
all: release
# Build the release mode executable (and ensure directories exist)
release: $(BIN_DIR)/$(RELEASE_DIR)/$(EXECUTABLE)
# Build the debug mode executable (and ensure directories exist)
debug: $(BIN_DIR)/$(DEBUG_DIR)/$(EXECUTABLE)
# Makefile rules using special Makefile variables:
# $@ is left hand side of rule
# $< is first item from the right hand side of rule
# $^ is all items from right hand side of the rule
# Compile CUDA object files for release builds
$(BUILD_DIR)/$(RELEASE_DIR)/%.cu.o : %.cu $(DEPS) $(MAKEFILE_LIST)
@mkdir -p $(dir $@)
$(NVCC) -c -o $@ $< $(NVCCFLAGS) $(NVCCFLAGS_RELEASE) $(addprefix -Xcompiler ,$(CCFLAGS)) $(addprefix -Xcompiler ,$(CCFLAGS_RELEASE))
# Compiler C object files for release builds
$(BUILD_DIR)/$(RELEASE_DIR)/%.c.o : %.c $(DEPS) $(MAKEFILE_LIST)
@mkdir -p $(dir $@)
$(CC) -c -o $@ $< $(CCFLAGS) $(CCFLAGS_RELEASE)
# Link the executable for release builds
$(BIN_DIR)/$(RELEASE_DIR)/$(EXECUTABLE) : $(addprefix $(BUILD_DIR)/$(RELEASE_DIR)/,$(OBJS))
@mkdir -p $(dir $@)
$(NVCC) -o $@ $^ $(NVCCFLAGS) $(NVCCFLAGS_RELEASE) $(addprefix -Xcompiler ,$(CCFLAGS)) $(addprefix -Xcompiler ,$(CCFLAGS_RELEASE))
# Rules for debug objects / executables. Note that these are duplicates with minor changes.
$(BUILD_DIR)/$(DEBUG_DIR)/%.cu.o : %.cu $(DEPS) $(MAKEFILE_LIST)
@mkdir -p $(dir $@)
$(NVCC) -c -o $@ $< $(NVCCFLAGS) $(NVCCFLAGS_DEBUG) $(addprefix -Xcompiler ,$(CCFLAGS)) $(addprefix -Xcompiler ,$(CCFLAGS_DEBUG))
# Compiler C object files for debug builds
$(BUILD_DIR)/$(DEBUG_DIR)/%.c.o : %.c $(DEPS) $(MAKEFILE_LIST)
@mkdir -p $(dir $@)
$(CC) -c -o $@ $< $(CCFLAGS) $(CCFLAGS_DEBUG)
# Link the executable for debug builds
$(BIN_DIR)/$(DEBUG_DIR)/$(EXECUTABLE) : $(addprefix $(BUILD_DIR)/$(DEBUG_DIR)/,$(OBJS))
@mkdir -p $(dir $@)
$(NVCC) -o $@ $^ $(NVCCFLAGS) $(NVCCFLAGS_DEBUG) $(addprefix -Xcompiler ,$(CCFLAGS)) $(addprefix -Xcompiler ,$(CCFLAGS_DEBUG))
# PHONY rules do not generate files with the same name as the rule.
.PHONY : all release debug clean help
# Clean generated files.
clean:
@echo "clean"
@rm -rf $(BIN_DIR)
@rm -rf $(BUILD_DIR)
# Provide usage instructions
help:
@echo " Usage:"
@echo " make help Shows this help documentation"
@echo " make all Build the default configuraiton (release)"
@echo " make release Build the release executable ($(BIN_DIR)/$(RELEASE_DIR)/$(EXECUTABLE)) "
@echo " make debug Build the release executable ($(BIN_DIR)/$(DEBUG_DIR)/$(EXECUTABLE)) "
@echo " make clean Clean the build and bin directories"