-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (70 loc) · 2.4 KB
/
Makefile
File metadata and controls
94 lines (70 loc) · 2.4 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
CXX := g++
CXXFLAGS := -std=c++17 -O2 -Wall -I./src -march=native -fopenmp
PYBIND11_INC := $(shell python3 -m pybind11 --includes)
PYEXT := $(shell python3-config --extension-suffix)
# ---- MKL toggle ----
ifeq ($(USE_MKL),1)
MKL_INC := /usr/include/mkl
MKL_LIBDIR := /usr/lib/x86_64-linux-gnu
CXXFLAGS += -DUSE_MKL -I$(MKL_INC)
LDLIBS += -Wl,--no-as-needed -L$(MKL_LIBDIR) -lmkl_rt -lpthread -lm -ldl
endif
# --------------------
# ---- OpenMP toggle ----
LDLIBS += -lgomp
# --------------------
SRC_DIR := src
TEST_DIR := tests
BUILD_DIR := build
# main test
TEST_SRC := $(TEST_DIR)/run_benchmark.cpp
TARGET_MAIN := $(BUILD_DIR)/run_benchmark
# correctness suite
CORR_SRC := $(TEST_DIR)/test_correctness.cpp
TARGET_CORR := $(BUILD_DIR)/test_correctness
# matrix ops test
MATRIX_OPS_SRC := $(TEST_DIR)/test_matrix_ops.cpp
TARGET_MATRIX_OPS := $(BUILD_DIR)/test_matrix_ops
HEADERS := \
$(SRC_DIR)/layout_policies.hpp \
$(SRC_DIR)/storage_policies.hpp \
$(SRC_DIR)/matrix.hpp \
$(SRC_DIR)/matrix_ops.hpp \
$(SRC_DIR)/lut_utils.hpp \
$(SRC_DIR)/post_processing.hpp
.PHONY: all run test clean pytest matrix_ops matrix_ops_float matrix_ops_lut
all: $(BUILD_DIR) $(TARGET_MAIN) $(TARGET_CORR) $(TARGET_MATRIX_OPS) mpgemm$(PYEXT)
# ensure build directory exists
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# build main
$(TARGET_MAIN): $(TEST_SRC) $(HEADERS)
$(CXX) $(CXXFLAGS) $(TEST_SRC) -o $(TARGET_MAIN) $(LDFLAGS) $(LDLIBS)
# build correctness suite
$(TARGET_CORR): $(CORR_SRC) $(HEADERS)
$(CXX) $(CXXFLAGS) $(CORR_SRC) -o $(TARGET_CORR) $(LDFLAGS) $(LDLIBS)
# build matrix ops test
$(TARGET_MATRIX_OPS): $(MATRIX_OPS_SRC) $(HEADERS)
$(CXX) $(CXXFLAGS) -pthread $(MATRIX_OPS_SRC) -o $(TARGET_MATRIX_OPS) $(LDFLAGS) $(LDLIBS)
# build pybind11 module
mpgemm$(PYEXT): src/bindings.cpp $(HEADERS)
$(CXX) $(CXXFLAGS) $(PYBIND11_INC) -fPIC -shared src/bindings.cpp -o $@ $(LDFLAGS) $(LDLIBS)
# run pytest
pytest: all
PYTHONPATH=. python3 -m pytest -q tests/test_api.py
run: all
./$(TARGET_MAIN)
test: $(TARGET_CORR)
./$(TARGET_CORR)
matrix_ops: $(TARGET_MATRIX_OPS)
@echo "Running float version..."
@./$(TARGET_MATRIX_OPS) float
@echo "\nRunning LUT version..."
@./$(TARGET_MATRIX_OPS) lut
matrix_ops_float: $(TARGET_MATRIX_OPS)
./$(TARGET_MATRIX_OPS) float
matrix_ops_lut: $(TARGET_MATRIX_OPS)
./$(TARGET_MATRIX_OPS) lut
clean:
rm -rf $(BUILD_DIR)
rm -f mpgemm$(PYEXT)