-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (53 loc) · 1.86 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
# Compiler and flags
CXX = g++
PYTHON = $(shell which python3)
PYBIND11_INCLUDE = $(shell $(PYTHON) -m pybind11 --includes)
CXXFLAGS = -O3 -Wall $(PYBIND11_INCLUDE) -fPIC -Wall -Wextra -std=c++17 -fPIC -I include
PYTHON_EXTENSION_SUFFIX = $(shell $(PYTHON) -c 'import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX"))')
# Target output
TARGET = libmnist$(PYTHON_EXTENSION_SUFFIX)
BUILD_DIR = build
# Source files
SRC = bindings.cpp \
src/activations.cpp \
src/cross_entropy.cpp \
src/dataloader.cpp \
src/functionals.cpp \
src/linear.cpp
# Object files
OBJ = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(SRC))
# Default target
all: $(TARGET)
# Create output directories if they don't exist
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/src:
mkdir -p $(BUILD_DIR)/src
# Compile the shared library
$(TARGET): $(OBJ)
$(CXX) -shared -o $@ $(OBJ)
# Compile object files for root-level source files
$(BUILD_DIR)/%.o: %.cpp | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -c $< -o $@
# Compile object files for src/ source files
$(BUILD_DIR)/src/%.o: src/%.cpp | $(BUILD_DIR)/src
$(CXX) $(CXXFLAGS) -c $< -o $@
# Show Python interpreter and include paths
python:
@echo $(PYTHON)
@echo $(PYBIND11_INCLUDE)
@echo $(PYTHON_EXTENSION_SUFFIX)
# Clean up build files
clean:
rm -f $(BUILD_DIR)/src/*.o $(BUILD_DIR)/*.o $(TARGET)
rm -rf $(BUILD_DIR)
@if [ -d results/ ]; then rm -rf results/; fi
@mkdir results/
download_mnist:
@if [ -d data/ ]; then rm -rf data/; fi
@mkdir data/
@wget -P data/ https://raw.githubusercontent.com/fgnt/mnist/master/train-images-idx3-ubyte.gz
@wget -P data/ https://raw.githubusercontent.com/fgnt/mnist/master/train-labels-idx1-ubyte.gz
@wget -P data/ https://raw.githubusercontent.com/fgnt/mnist/master/t10k-images-idx3-ubyte.gz
@wget -P data/ https://raw.githubusercontent.com/fgnt/mnist/master/t10k-labels-idx1-ubyte.gz
@gunzip data/*.gz