Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
msricher committed Feb 6, 2024
1 parent 84f8fed commit 1fe2f70
Show file tree
Hide file tree
Showing 14 changed files with 1,099 additions and 802 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ tags

# Project files
compile_flags.txt
permanent/run_tuning
permanent/tuning.h
*.csv
permanent/*.csv
src/tuning
src/tuning.h
src/tuning.csv
91 changes: 47 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
CC ?= gcc
CXX ?= g++
AR ?= ar
PYTHON ?= python3

CFLAGS := -Wall -Wextra -g -fPIC -O2

CFLAGS += -lm

CFLAGS += -I$(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_paths()['include'])")
CFLAGS += -I$(shell $(PYTHON) -c "import numpy; print(numpy.get_include())")
CXXFLAGS := -std=c++17 -Wall -Wextra -g -fPIC -O3

ifeq ($(shell uname -s),Darwin)
CFLAGS += -undefined dynamic_lookup
CXXFLAGS += -undefined dynamic_lookup
endif

ifneq ($(RUN_TUNING),)
CXXFLAGS += -march=native -DRUN_TUNING=1
endif

ifeq ($(PREFIX),)
Expand All @@ -19,58 +18,62 @@ endif

# Build C and Python libraries
.PHONY: all
all: permanent/permanent.so libpermanent.a libpermanent.so
all: libpermanent.a libpermanent.so permanent/permanent.so

# Build C libraries
.PHONY: c
c: libpermanent.a libpermanent.so

# Build Python libraries
.PHONY: python
python: permanent/permanent.so

# Install C libraries
.PHONY: install
install: permanent/tuning.h libpermanent.a libpermanent.so
install: src/tuning.h libpermanent.a libpermanent.so
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 444 libpermanent.a $(DESTDIR)$(PREFIX)/lib/
install -m 555 libpermanent.so $(DESTDIR)$(PREFIX)/lib/
install -d $(DESTDIR)$(PREFIX)/include/permanent/
install -m 444 permanent/permanent.h $(DESTDIR)$(PREFIX)/include/permanent/
install -m 444 permanent/tuning.h $(DESTDIR)$(PREFIX)/include/permanent/
install -d $(DESTDIR)$(PREFIX)/include/src/
install -m 444 src/permanent.h $(DESTDIR)$(PREFIX)/include/src/
install -m 444 src/tuning.h $(DESTDIR)$(PREFIX)/include/src/

# Run tests
.PHONY: test
test: permanent/permanent.so
test: src/permanent.so
$(PYTHON) -m pytest -v .

# Clean directory
.PHONY: clean
clean:
rm -f permanent/run_tuning permanent/tuning.h
rm -f permanent/permanent.so libpermanent.o libpermanent.a libpermanent.so
rm -f fast_permanent.csv
rm -f src/tuning src/tuning.h src/tuning.csv
rm -f src/libpermanent.o permanent/permanent.so libpermanent.a libpermanent.so

# compile_flags.txt (clangd)
compile_flags.txt:
echo "$(CFLAGS)" | sed 's/ /\n/g' > $@

# Tuning utility
permanent/run_tuning:
$(CC) $(CFLAGS) -o $@ permanent/permanent.c permanent/run_tuning.c

# Tuning parameters
permanent/tuning.h: permanent/run_tuning
./$^
$(PYTHON) find_boundary.py -v .

# Python library
permanent/permanent.so: permanent/tuning.h
$(CC) $(CFLAGS) -DTUNING_FILE=1 -shared -o $@ permanent/permanent.c permanent/py_permanent.c

# C object code
libpermanent.o: permanent/tuning.h
$(CC) $(CFLAGS) -DTUNING_FILE=1 -c -o $@ permanent/permanent.c

# C static library
libpermanent.a: libpermanent.o
echo "$(CXXFLAGS)" | sed 's/ /\n/g' > $@

# Find tuning parameters
src/tuning.h: src/tuning.cc src/tuning.py
$(CXX) $(CXXFLAGS) -o src/tuning src/permanent.cc src/tuning.cc
src/tuning
[ -n "$(RUN_TUNING)" ] && $(PYTHON) src/tuning.py || true

# Compile Python library
permanent/permanent.so: src/tuning.h src/permanent.cc src/py_permanent.cc
$(CXX) $(CXXFLAGS) -DWITH_TUNING_FILE=1 \
-I$(shell $(PYTHON) -c "import sysconfig; print(sysconfig.get_paths()['include'])") \
-I$(shell $(PYTHON) -c "import numpy; print(numpy.get_include())") \
-shared -o $@ src/permanent.cc src/py_permanent.cc

# Compile object code
src/libpermanent.o: src/tuning.h src/permanent.cc
$(CXX) $(CXXFLAGS) -DWITH_TUNING_FILE=1 -c -o $@ src/permanent.cc

# Compile static library
libpermanent.a: src/libpermanent.o
$(AR) crs $@ $^

# C shared library
libpermanent.so: libpermanent.o
$(CC) $(CFLAGS) -shared -o $@ $^



# Compile shared library
libpermanent.so: src/libpermanent.o
$(CXX) $(CXXFLAGS) -shared -o $@ $^
Loading

0 comments on commit 1fe2f70

Please sign in to comment.