Makefile 2.32 KB
Newer Older
Julien Jerphanion's avatar
Julien Jerphanion committed
1 2 3 4 5 6 7 8 9
SHELL = /bin/bash
PROJECT = cython+

VENV_PATH=`conda info --base`/envs/${PROJECT}
PIP_EXECUTABLE=${VENV_PATH}/bin/pip
PYTHON_EXECUTABLE=${VENV_PATH}/bin/python
PYTEST_EXECUTABLE=${VENV_PATH}/bin/pytest

# Used when not using the python runtime
Julien Jerphanion's avatar
Julien Jerphanion committed
10
INCLUDE_DIRS = -I/usr/include/python3.9
Julien Jerphanion's avatar
Julien Jerphanion committed
11
EXE = kdtree
12
CXX = g++
13
CPPFLAGS = -O2 -g -Wno-unused-result -Wsign-compare -pthread $(INCLUDE_DIRS) -fopenmp
14
LDFLAGS += -Wl,--unresolved-symbols=ignore-all
Julien Jerphanion's avatar
Julien Jerphanion committed
15
MACROS = -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
Julien Jerphanion's avatar
Julien Jerphanion committed
16
EXT_SUFFIX := $(shell python -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
17 18
EXT = $(EXE)$(EXT_SUFFIX)

Julien Jerphanion's avatar
Julien Jerphanion committed
19
.DEFAULT_GOAL := all
20

Julien Jerphanion's avatar
Julien Jerphanion committed
21 22 23 24 25 26 27
## help: Display list of commands
.PHONY: help
help: Makefile
	@sed -n 's|^##||p' $< | column -t -s ':' | sed -e 's|^| |'

## all: Run the main targets
.PHONY: all
Julien Jerphanion's avatar
Julien Jerphanion committed
28
all: setup benchmark
29

Julien Jerphanion's avatar
Julien Jerphanion committed
30 31 32
## setup: Setup the conda environment
.PHONY: setup
setup: clean
Julien Jerphanion's avatar
Julien Jerphanion committed
33 34 35
	conda env create --force -f environment.yml
	${PIP_EXECUTABLE} install -e . -v

Julien Jerphanion's avatar
Julien Jerphanion committed
36 37 38 39 40
## install: install the project in the env
.PHONY: install
install:
	${PIP_EXECUTABLE} install -e . -v

Julien Jerphanion's avatar
Julien Jerphanion committed
41 42
# nopython: Build without the Python runtime
.PHONY: nopython
43 44 45 46
nopython: $(EXE)

%.cpp: %.pyx
	@echo "[Cython Compiling $^ -> $@]"
Julien Jerphanion's avatar
Julien Jerphanion committed
47
	${PYTEST_EXECUTABLE} -c "from Cython.Compiler.Main import main; main(command_line=1)" $^ --cplus -3
48 49 50 51
	@rm -f $(subst .cpp,.h,$@)

%: %.cpp
	@echo "[C++ Compiling $^ -> $@]"
Julien Jerphanion's avatar
Julien Jerphanion committed
52
	$(LINK.cpp) $^ $(MACROS) -o $@
53

Julien Jerphanion's avatar
Julien Jerphanion committed
54 55
## runnopython: Run without Python runtime
.PHONY: runnopython
56
runnopython: $(EXE)
Julien Jerphanion's avatar
Julien Jerphanion committed
57 58
	# Information of the runtime are currently redirected to stderr.
	# This is just a simple way to mute them.
59 60
	./$(EXE) 2>/dev/null

Julien Jerphanion's avatar
Julien Jerphanion committed
61 62
## clean: Remove generated files from Cython and C/C++ compilation
.PHONY: clean
63 64 65 66 67 68 69 70 71 72
clean:
	-rm -f *.c *.cpp *.html
	-rm -f *.h
	-rm -f *.so
	-rm -f $(EXE)
	-rm -f *.o
	-rm -f -r build
	-rm -f *.json

.PRECIOUS: %.cpp
Julien Jerphanion's avatar
Julien Jerphanion committed
73

Julien Jerphanion's avatar
Julien Jerphanion committed
74
## benchmark: Run benchmarks
Julien Jerphanion's avatar
Julien Jerphanion committed
75
# Uses taskset to cap to a cpu solely
Julien Jerphanion's avatar
Julien Jerphanion committed
76 77
.PHONY: benchmark
benchmark:
78
	for i in {0..5}; do \
79
		taskset -c 0-$$((2**i-1)) ${PYTHON_EXECUTABLE} benchmarks/benchmark.py `git rev-parse --short HEAD`_$$((2**i))_threads ;\
Julien Jerphanion's avatar
Julien Jerphanion committed
80
	done
81 82 83 84 85 86
	${PYTHON_EXECUTABLE} benchmarks/report.py `git rev-parse --short HEAD`

## report: Report benchmark results
.PHONY: report
report:
	${PYTHON_EXECUTABLE} benchmarks/report.py `git rev-parse --short HEAD`
Julien Jerphanion's avatar
Julien Jerphanion committed
87 88 89 90 91

## test: Launch all the test.
.PHONY: test
test:
	${PYTEST_EXECUTABLE} tests