-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
76 lines (60 loc) · 3.23 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
69
70
71
72
73
74
75
76
BAZEL_BIN_DIR := extra-deps/tensorflow-haskell/third_party/tensorflow/bazel-bin
TF_LIB_SO_BASE := $(BAZEL_BIN_DIR)/tensorflow/libtensorflow.so
TF_LIB_LINKS := $(TF_LIB_SO_BASE) $(TF_LIB_SO_BASE).2 $(TF_LIB_SO_BASE).2.10
.PHONY: all help setup submodules tflitebuild tf-lib-links libedgetpu libedgetpu-lib-links cabal.project
all: help
help:
@echo "This Makefile defines the following targets:"
@echo " 'setup': all of the following:"
@echo " 'submodules': Sets up the Git submodules"
@echo " 'tflitebuild': Builds tensorflow lite inside build/"
@echo " 'tfbuild': Builds full tensorflow with bazel"
@echo " 'tf-lib-links': Additional .so symlinks in bazel bin dir"
@echo " 'libedgetpu': Build libedgetpu.so"
@echo " 'libedgetpu-lib-links': Additional .so symlinks in libedgetpu bin dir"
@echo " 'cabal.project': Creates cabal.project from cabal.project.in (with envsubst)"
@echo "Note: DO NOT USE -j with this Makefile. Parallelism is exploited already, and you can only break things."
# Don't list these targets as dependencies here so that things don't go _quite_ as horribly wrong when someone misguidedly uses -j with this Makefile
setup:
$(MAKE) submodules
$(MAKE) tflitebuild tfbuild
$(MAKE) tf-lib-links
$(MAKE) libedgetpu
$(MAKE) libedgetpu-lib-links
$(MAKE) cabal.project
submodules:
@if git status --porcelain | grep extra-deps >/dev/null; then \
echo "'git status' detects changes in the extra-deps directory, refusing to init submodules"; \
exit 1; \
fi
git submodule update --init --recursive
tflitebuild:
mkdir -p build
cd build && cmake ../extra-deps/tensorflow-haskell/third_party/tensorflow/tensorflow/lite -DBUILD_SHARED_LIBS=1
cd build && cmake --build . -j
tfbuild: bazel511
cd extra-deps/tensorflow-haskell/third_party/tensorflow && ../../../../bazel511 build //tensorflow:all //tensorflow/tools/pip_package:build_pip_package
cd extra-deps/tensorflow-haskell/third_party/tensorflow && ../../../../run-with-PATH-dir.sh python=python3 -- bazel-bin/tensorflow/tools/pip_package/build_pip_package ../../../../accelerate-tensorflow-lite/tf-python-venv
virtualenv accelerate-tensorflow-lite/tf-python-venv
accelerate-tensorflow-lite/tf-python-venv/bin/pip3 install --force-reinstall accelerate-tensorflow-lite/tf-python-venv/tensorflow-2.10.1-*.whl
bazel511:
curl -L https://github.com/bazelbuild/bazel/releases/download/5.1.1/bazel-5.1.1-linux-x86_64 >$@
chmod +x $@
tf-lib-links: $(TF_LIB_LINKS)
$(TF_LIB_LINKS):
ln -s libtensorflow.so.2.10.1 $@
ABSL_LD_FLAGS := $(addprefix -L$(PWD)/build/_deps/abseil-cpp-build/absl/,flags hash container strings)
libedgetpu:
cd extra-deps/libedgetpu && \
env TFROOT=$(PWD)/extra-deps/tensorflow-haskell/third_party/tensorflow \
make -f makefile_build/Makefile \
CXXFLAGS='-I$(PWD)/build/flatbuffers/include -I$(PWD)/build/abseil-cpp' \
LDFLAGS='-L$(PWD)/build/_deps/flatbuffers-build $(ABSL_LD_FLAGS)' \
FLATC=$(PWD)/extra-deps/tensorflow-haskell/third_party/tensorflow/bazel-bin/external/flatbuffers/flatc \
libedgetpu-throttled \
-j$(shell nproc)
libedgetpu-lib-links: extra-deps/libedgetpu/out/throttled/k8/libedgetpu.so
extra-deps/libedgetpu/out/throttled/k8/libedgetpu.so:
ln -s libedgetpu.so.1.0 $@
cabal.project: cabal.project.in
envsubst '$$PWD' <$< >$@