forked from InfiniTensor/Learning-CUDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
103 lines (92 loc) · 3.7 KB
/
Makefile
File metadata and controls
103 lines (92 loc) · 3.7 KB
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
99
100
101
102
103
# *********************************************************************
# Learning-CUDA Makefile
# Targets:
# make : Build + run tests (default, non-verbose)
# make build : Only compile (no run)
# make run : Run tests (after build, non-verbose)
# make run VERBOSE=true : Run tests with verbose output
# make clean : Delete temporary files
# *********************************************************************
# -------------------------------
# Configuration
# -------------------------------
PLATFORM ?= nvidia
PLATFORM_DEFINE ?= -DPLATFORM_NVIDIA
STUDENT_SUFFIX := cu
CFLAGS := -std=c++17 -O0
EXTRA_LIBS :=
# Compiler & Tester object selection based on PLATFORM
ifeq ($(PLATFORM),nvidia)
CC := nvcc
TEST_OBJ := tester/tester_nv.o
PLATFORM_DEFINE := -DPLATFORM_NVIDIA
else ifeq ($(PLATFORM),iluvatar)
CC := clang++
CFLAGS := -std=c++17 -O3
TEST_OBJ := tester/tester_iluvatar.o
PLATFORM_DEFINE := -DPLATFORM_ILUVATAR
EXTRA_LIBS := -lcudart -I/usr/local/corex/include -L/usr/local/corex/lib64 -fPIC
else ifeq ($(PLATFORM),moore)
CC := mcc
CFLAGS := -std=c++11 -O3
TEST_OBJ := tester/tester_moore.o
STUDENT_SUFFIX := mu
PLATFORM_DEFINE := -DPLATFORM_MOORE
EXTRA_LIBS := -I/usr/local/musa/include -L/usr/lib/gcc/x86_64-linux-gnu/11/ -L/usr/local/musa/lib -lmusart
else ifeq ($(PLATFORM),metax)
CC := mxcc
TEST_OBJ := tester/tester_metax.o
STUDENT_SUFFIX := maca
PLATFORM_DEFINE := -DPLATFORM_METAX
else
$(error Unsupported PLATFORM '$(PLATFORM)' (expected: nvidia, iluvatar, moore, metax))
endif
# Executable name
TARGET := test_kernels
# Kernel implementation
STUDENT_SRC := src/kernels.$(STUDENT_SUFFIX)
# Compiled student object (auto-generated)
STUDENT_OBJ := $(addsuffix .o,$(basename $(STUDENT_SRC)))
# Tester's actual verbose argument (e.g., --verbose, -v)
TEST_VERBOSE_FLAG := --verbose
# User-provided verbose mode (true/false; default: false)
VERBOSE :=
# -------------------------------
# Process User Input (VERBOSE → Tester Flag)
# -------------------------------
# Translates `VERBOSE=true` (case-insensitive) to the tester's verbose flag.
# If VERBOSE is not "true" (or empty), no flag is passed.
VERBOSE_ARG := $(if $(filter true True TRUE, $(VERBOSE)), $(TEST_VERBOSE_FLAG), )
# -------------------------------
# Phony Targets
# -------------------------------
.PHONY: all build run clean
# Default target: Build + run tests (non-verbose)
all: build run
# Build target: Compile student code + link with test logic
build: $(TARGET)
# Run target: Execute tests (supports `VERBOSE=true` for verbose output)
run: $(TARGET)
@echo "=== Running tests (output from $(STUDENT_OBJ)) ==="
@# Show verbose mode status (friendly for users)
@if [ -n "$(VERBOSE_ARG)" ]; then \
echo "=== Verbose mode: Enabled (using '$(TEST_VERBOSE_FLAG)') ==="; \
else \
echo "=== Verbose mode: Disabled ==="; \
fi
./$(TARGET) $(VERBOSE_ARG)
# Clean target: Delete temporary files (executable + src object)
clean:
@echo "=== Cleaning temporary files ==="
rm -f $(TARGET) $(STUDENT_OBJ)
# -------------------------------
# Dependency Rules (Core Logic)
# -------------------------------
# Generate executable: Link kernel code (kernels.o) with test logic (tester.o)
$(TARGET): $(STUDENT_OBJ) $(TEST_OBJ)
@echo "=== Linking executable (student code + test logic) ==="
$(CC) $(CFLAGS) $(PLATFORM_DEFINE) -o $@ $^ $(EXTRA_LIBS)
# Generate src object: Compile kernels.cu (triggers template instantiation)
$(STUDENT_OBJ): $(STUDENT_SRC)
@echo "=== Compiling student code ($(STUDENT_SRC)) ==="
$(CC) $(CFLAGS) $(PLATFORM_DEFINE) -c $< -o $@