Skip to content

Commit a5194b5

Browse files
rafielantiga
authored andcommitted
Build scripts for TFLite (x64, Linux & macOS) (#251)
1 parent 89f09c5 commit a5194b5

File tree

7 files changed

+59
-19
lines changed

7 files changed

+59
-19
lines changed

get_deps.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
1111

1212
if [[ $1 == --help || $1 == help ]]; then
1313
cat <<-END
14-
get_deps.sh [cpu|gpu] [--help|help]
14+
[ARGVARS...] get_deps.sh [cpu|gpu] [--help|help]
1515
1616
Argument variables:
1717
VERBOSE=1 Print commands
@@ -145,6 +145,7 @@ if [[ $WITH_TFLITE != 0 ]]; then
145145
if [[ ! -d $LIBTFLITE ]]; then
146146
echo "Installing TensorFlow Lite ..."
147147

148+
LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow
148149
if [[ $OS == linux ]]; then
149150
TFLITE_OS="linux"
150151
# if [[ $GPU == no ]]; then
@@ -153,7 +154,6 @@ if [[ $WITH_TFLITE != 0 ]]; then
153154
# TFLITE_BUILD="gpu"
154155
# fi
155156

156-
LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow
157157
if [[ $ARCH == x64 ]]; then
158158
TFLITE_ARCH=x86_64
159159
elif [[ $ARCH == arm64v8 ]]; then

opt/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
ROOT:=..
33
include readies/mk/main
44

5-
# temporarily disabled
6-
# export WITH_TFLITE=0
7-
85
MK_CMAKE:=1
96
MK_CMAKE_INSTALL:=1
107

opt/build/tflite/Dockerfile.x64

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ ADD ./opt/build/tflite/build /build/
2121
ADD ./opt/readies/ /build/readies/
2222
ADD ./opt/build/tflite/collect.py /build/
2323

24-
RUN ./build
24+
RUN set -e ;\
25+
cd tensorflow/tensorflow/lite/tools/make ;\
26+
./download_dependencies.sh ;\
27+
./build_lib.sh
28+
2529
RUN ./collect.py --version ${FTLITE_VER} --dest /build/dest

opt/build/tflite/Makefile

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11

22
ROOT=../../..
33

4-
VERSION ?= 2.0.0
4+
export VERSION ?= 2.0.0
55
OSNICK ?= buster
66

77
#----------------------------------------------------------------------------------------------
88

99
S3_URL=redismodules/tensorflow
1010

1111
OS:=$(shell $(ROOT)/opt/readies/bin/platform --os)
12-
ifeq ($(OS),macosx)
13-
OS:=macos
12+
13+
ifeq ($(OS),linux)
14+
OS.publish:=$(OS)
15+
ARCH.publish:=$(ARCH)
16+
17+
else ifeq ($(OS),macosx)
18+
OS.publish:=darwin
19+
ARCH.publish:=x86_64
1420
endif
15-
STEM=libtensorflowlite-$(OS)
21+
22+
STEM=libtensorflowlite-$(OS.publish)
1623

1724
DOCKER_OS.bionic=ubuntu:bionic
1825
DOCKER_OS.stretch=debian:stretch-slim
@@ -21,6 +28,8 @@ DOCKER_OS=$(DOCKER_OS.$(OSNICK))
2128

2229
#----------------------------------------------------------------------------------------------
2330

31+
ifeq ($(OS),linux)
32+
2433
define targets # (1=OP, 2=op)
2534
$(1)_TARGETS :=
2635
$(1)_TARGETS += $(if $(findstring $(X64),1),$(2)_x64)
@@ -30,6 +39,14 @@ $(1)_TARGETS += $(if $(findstring $(ARM8),1),$(2)_arm64v8)
3039
$(1)_TARGETS += $$(if $$(strip $$($(1)_TARGETS)),,$(2)_x64 $(2)_arm32v7 $(2)_arm64v8)
3140
endef
3241

42+
else ifeq ($(OS),macosx)
43+
44+
define targets # (1=OP, 2=op)
45+
$(1)_TARGETS := $(2)_x64
46+
endef
47+
48+
endif
49+
3350
$(eval $(call targets,BUILD,build))
3451
$(eval $(call targets,PUBLISH,publish))
3552

@@ -95,12 +112,6 @@ $(error Please run 'aws configure' and provide it with access credentials)
95112
endif
96113
endif
97114

98-
else ifeq ($(OS),macosx)
99-
100-
build: ;
101-
102-
endif # macosx
103-
104115
publish: $(PUBLISH_TARGETS)
105116

106117
$(eval $(call publish_x64,x64,x86_64))
@@ -110,4 +121,19 @@ $(eval $(call publish_arm,arm32v7,arm))
110121
help:
111122
@echo "make [build|publish] [X64=1|ARM7=1|ARM8=1]"
112123

124+
else ifeq ($(OS),macosx)
125+
126+
build:
127+
@VERSION=$(VERSION) ./build.macos
128+
@mv macos/dest/$(STEM)-$(ARCH.publish)-$(VERSION).tar.gz .
129+
130+
publish: $(PUBLISH_TARGETS)
131+
132+
$(eval $(call publish_x64,x64,x86_64))
133+
134+
help:
135+
@echo "make [build|publish]"
136+
137+
endif # macosx
138+
113139
.PHONY: all build publish help

opt/build/tflite/build

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ if [[ $OS == linux ]]; then
1212
elif [[ $ARCH == arm64v8 ]]; then
1313
bash build_aarch64_lib.sh
1414
elif [[ $ARCH == arm32v7 ]]; then
15-
echo "Error: arm32 not supported by TFLite"
16-
exit 1
15+
bash build_rpi_lib.sh
1716
fi
1817
elif [[ $OS == macosx ]]; then
1918
TARGET=osx

opt/build/tflite/build.macos

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
4+
cd $HERE
5+
6+
set -e
7+
mkdir -p macos
8+
cd macos
9+
cp ../collect.py .
10+
ln -s ../../../readies/
11+
git clone --single-branch --branch v${VERSION} --depth 1 https://github.com/tensorflow/tensorflow.git
12+
./collect.py --version $VERSION --dest dest

opt/build/tflite/collect.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
platform = paella.Platform()
3333

3434
tf_os = platform.os
35+
tf_os_internal = tf_os
3536
if tf_os == 'macosx':
3637
tf_os = 'darwin'
38+
tf_os_internal = 'osx'
3739

3840
tf_arch = platform.arch
3941
if tf_arch == 'x64':
@@ -68,7 +70,7 @@ def collect_tflite():
6870
with cwd('downloads/flatbuffers/include'):
6971
for f in Path('.').glob('**/*.h'):
7072
copy_p(f, d_tensorflow/'include')
71-
with cwd(f'gen/linux_{tf_arch}/lib'):
73+
with cwd(f'gen/{tf_os_internal}_{tf_arch}/lib'):
7274
for f in Path('.').glob('*.a'):
7375
copy_p(f, d_tensorflow/'lib')
7476
create_tar(dest/f'libtensorflowlite-{tf_os}-{tf_arch}-{tf_ver}.tar.gz', dest)

0 commit comments

Comments
 (0)