Skip to content

Commit 731339f

Browse files
committed
ARM support #14
1 parent cd30b59 commit 731339f

File tree

11 files changed

+167
-72
lines changed

11 files changed

+167
-72
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GET_FILENAME_COMPONENT(depsAbs
1212

1313
LIST(APPEND CMAKE_PREFIX_PATH ${depsAbs}/libtorch)
1414

15-
INCLUDE_DIRECTORIES(${depsAbs}/tensorflow/include ${depsAbs}/dlpack/include)
15+
INCLUDE_DIRECTORIES(${depsAbs}/tensorflow/include ${depsAbs}/onnxruntime/include ${depsAbs}/dlpack/include)
1616

1717
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
1818
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
@@ -25,7 +25,8 @@ IF (NOT TF_LIBRARIES)
2525
MESSAGE(FATAL_ERROR "Could not find tensorflow")
2626
ENDIF()
2727

28-
FIND_LIBRARY(ORT_LIBRARIES NAMES onnxruntime)
28+
FIND_LIBRARY(ORT_LIBRARIES NAMES onnxruntime
29+
PATHS ${depsAbs}/onnxruntime/lib)
2930
IF (NOT ORT_LIBRARIES)
3031
MESSAGE(FATAL_ERROR "Could not find ONNXRuntime")
3132
ENDIF()

build/libtorch-arm/Dockerfile

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# BUILD redisfab/libtorch-${ARCH}:$(PT_VER)
1+
# BUILD redisfab/libtorch-cpu-${ARCH}:$(PT_VER)
22

33
# stretch|bionic|buster
44
ARG OSNICK=buster
@@ -18,28 +18,30 @@ WORKDIR /build
1818
RUN set -e ;\
1919
apt-get -qq update ;\
2020
apt-get -qq install -y git build-essential ninja-build cmake python3-pip python3-cffi
21-
RUN pip3 install setuptools pyyaml typing numpy
22-
# mkl mkl-include
21+
RUN pip3 install setuptools pyyaml typing
22+
RUN pip3 install numpy
23+
# RUN pip3 install mkl mkl-include
2324

2425
RUN set -e ;\
2526
git clone https://github.com/pytorch/pytorch.git ;\
2627
cd pytorch ;\
27-
git checkout v${PT_VER} ;\
28+
git checkout "v${PT_VER}" ;\
2829
git submodule update --init --recursive
2930

31+
ENV BUILD_PYTHON=0
32+
ENV USE_GLOO=1
33+
ENV USE_OPENCV=0
34+
ENV BUILD_TORCH=ON
35+
ENV BUILD_BINARY=ON
36+
ENV BUILD_CAFFE2_OPS=ON
37+
ENV NO_CUDA=1
38+
ENV NO_DISTRIBUTED=1
39+
ENV NO_MKLDNN=1
40+
ENV NO_NNPACK=1
41+
ENV NO_QNNPACK=1
42+
3043
RUN set -e ;\
3144
cd pytorch ;\
32-
BUILD_PYTHON=0 \
33-
USE_GLOO=1 \
34-
USE_OPENCV=0 \
35-
BUILD_TORCH=ON \
36-
BUILD_BINARY=ON \
37-
BUILD_CAFFE2_OPS=ON \
38-
NO_CUDA=1 \
39-
NO_DISTRIBUTED=1 \
40-
NO_MKLDNN=1 \
41-
NO_NNPACK=1 \
42-
NO_QNNPACK=1 \
4345
python3 setup.py install
4446

4547
ADD ./deps/readies/ /build/deps/readies/

build/libtorch-arm/Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ VERSION=1.1.0
55

66
S3_URL=redismodules/pytorch
77

8+
IID_FILE=libtorch-cpu-linux-arm64v8:$(VERSION).iid
9+
810
build:
9-
@docker build -t redisfab/libtorch-arm64v8:$(VERSION) -f Dockerfile ../..
11+
@docker build --iidfile $(IID_FILE) -t redisfab/libtorch-cpu-linux-arm32v7:$(VERSION) -f Dockerfile --build-arg ARCH=arm32v7 ../..
12+
@docker build --iidfile $(IID_FILE) -t redisfab/libtorch-cpu-linux-arm64v8:$(VERSION) -f Dockerfile --build-arg ARCH=arm64v8 ../..
1013

1114
pack:
12-
@PT_VERSION=$(VERSION) ./repack.sh
15+
@docker cp `cat $(IID_FILE)`:/build/libtorch-cpu-linux-arm-$(VERSION).tar.gz .
16+
@docker cp `cat $(IID_FILE)`:/build/libtorch-cpu-linux-arm64-$(VERSION).tar.gz .
1317

1418
publish:
15-
@aws s3 cp libtorch-cpu-linux-arm64v8-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read
16-
@aws s3 cp libtorch-cpu-linux-arm32v7-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read
19+
@aws s3 cp libtorch-cpu-linux-arm-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read
20+
@aws s3 cp libtorch-cpu-linux-arm64-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read

build/libtorch-x64/Dockerfile

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
ARG OS=debian:buster
2+
ARG PT_VER=1.1.0
23

34
#----------------------------------------------------------------------------------------------
45
FROM ${OS}
56

6-
ARG PT_VER=1.1.0
7-
8-
RUN set -ex; apt-get -qq update; apt-get -q install -y git
9-
107
WORKDIR /build
118

12-
RUN apt-get install -y build-essential
13-
RUN apt-get install -y python3-pip python3-cffi
14-
RUN apt-get install -y ninja-build cmake
9+
RUN set -e ;\
10+
apt-get -qq update ;\
11+
apt-get -qq install -y git build-essential ninja-build cmake python3-pip python3-cffi
1512
RUN pip3 install setuptools pyyaml typing
16-
RUN pip3 install numpy mkl mkl-include
17-
18-
RUN git clone https://github.com/pytorch/pytorch.git ;\
19-
cd pytorch ;\
20-
git checkout v${PT_VER}
21-
22-
RUN cd pytorch ;\
23-
BUILD_PYTHON=0 \
24-
USE_GLOO=1 \
25-
USE_OPENCV=0 \
26-
BUILD_TORCH=ON \
27-
BUILD_BINARY=ON \
28-
BUILD_CAFFE2_OPS=ON \
29-
NO_CUDA=1 \
30-
NO_DISTRIBUTED=1 \
31-
NO_MKLDNN=1 \
32-
NO_NNPACK=1 \
33-
NO_QNNPACK=1 \
34-
python3 setup.py install
13+
RUN pip3 install numpy
14+
RUN pip3 install mkl mkl-include
15+
16+
RUN set -e ;\
17+
git clone https://github.com/pytorch/pytorch.git ;\
18+
cd pytorch ;\
19+
git checkout "v${PT_VER}" ;\
20+
git submodule update --init --recursive
21+
22+
ENV BUILD_PYTHON=0
23+
ENV USE_GLOO=1
24+
ENV USE_OPENCV=0
25+
ENV BUILD_TORCH=ON
26+
ENV BUILD_BINARY=ON
27+
ENV BUILD_CAFFE2_OPS=ON
28+
ENV NO_CUDA=1
29+
ENV NO_DISTRIBUTED=1
30+
ENV NO_MKLDNN=1
31+
ENV NO_NNPACK=1
32+
ENV NO_QNNPACK=1
33+
34+
RUN set -e ;\
35+
cd pytorch ;\
36+
python3 setup.py install
37+
38+
ADD ./deps/readies/ /build/deps/readies/
39+
ADD ./build/libtorch-arm/collect.py /build/
40+
41+
RUN ./collect.py

build/libtorch-x64/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11

2-
.PHONY: pack publish
2+
.PHONY: build pack repack publish
33

44
VERSION=1.1.0
55

6+
STEM=libtorch-cpu-linux-x86_64-$(VERSION)
7+
68
S3_URL=redismodules/pytorch
79

10+
IID_FILE=libtorch-cpu-linux-x64:$(VERSION).iid
11+
12+
build:
13+
@docker build --iidfile $(IID_FILE) -t redisfab/libtorch-cpu-linux-x64:$(VERSION) -f Dockerfile ../..
14+
815
pack:
16+
@docker cp `cat $(IID_FILE)`:/build/libtorch-cpu-linux-x64-$(VERSION).tar.gz .
17+
18+
repack:
919
@PT_VERSION=$(VERSION) ./repack.sh
1020

1121
publish:

build/onnxruntime/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# BUILD redisfab/libtorch-${ARCH}:$(ONNXRUNTIME_VER)
2+
3+
# stretch|bionic|buster
4+
ARG OSNICK=buster
5+
6+
# arm32v7|arm64v8
7+
ARG ARCH=arm32v7
8+
9+
#----------------------------------------------------------------------------------------------
10+
FROM redisfab/${ARCH}-xbuild:${OSNICK} as builder
11+
12+
ARG ONNXRUNTIME_REPO=https://github.com/Microsoft/onnxruntime
13+
ARG ONNXRUNTIME_BRANCH=master
14+
ARG ONNXRUNTIME_VER=0.4.0
15+
16+
RUN [ "cross-build-start" ]
17+
18+
RUN apt-get -qq update
19+
RUN apt-get -qq install -y curl wget tar git
20+
RUN apt-get -qq install -y build-essential
21+
RUN apt-get -qq install -y libcurl4-openssl-dev libssl-dev libatlas-base-dev zlib1g-dev
22+
23+
RUN apt-get -qq install -y python3 python3-pip python3-dev
24+
RUN pip3 install --upgrade pip setuptools wheel
25+
RUN pip3 install numpy
26+
27+
WORKDIR /code
28+
29+
RUN set -e ;\
30+
wget -q https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz ;\
31+
tar zxf cmake-3.14.3.tar.gz ;\
32+
cd cmake-3.14.3 ;\
33+
./configure --system-curl ;\
34+
make -j $(nproc);\
35+
make install
36+
37+
# Set up build args
38+
ARG BUILDTYPE=MinSizeRel
39+
ARG BUILDARGS="--config ${BUILDTYPE} --arm"
40+
41+
# Prepare onnxruntime Repo
42+
RUN set -e ;\
43+
git clone --single-branch --branch ${ONNXRUNTIME_BRANCH} --recursive ${ONNXRUNTIME_REPO} onnxruntime ;\
44+
git checkout "rel-${ONNXRUNTIME_VER}" ;\
45+
cd onnxruntime ;\
46+
./build.sh ${BUILDARGS} --update --build ;\
47+
./build.sh ${BUILDARGS} --build_shared_lib ;\
48+
./build.sh ${BUILDARGS} --enable_pybind --build_wheel
49+
50+
# Build Output
51+
RUN ls -l /code/onnxruntime/build/Linux/${BUILDTYPE}/*.so
52+
RUN ls -l /code/onnxruntime/build/Linux/${BUILDTYPE}/dist/*.whl
53+
54+
RUN [ "cross-build-end" ]

build/tensorflow-arm/Dockerfile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
ARG ARCH=x64
1+
# BUILD redisfab/tensorflow-${ARCH}:$(TF_VER)
2+
3+
# stretch|bionic|buster
4+
ARG OSNICK=buster
5+
6+
# arm32v7|arm64v8
7+
ARG ARCH=arm64v8
8+
9+
ARG TF_VER=1.13.1
210

311
#----------------------------------------------------------------------------------------------
412
FROM insready/bazel:latest as bazel
5-
FROM ${OS}
613

7-
ARG OS=debian:buster
8-
ARG TF_VER=1.13.1
14+
#----------------------------------------------------------------------------------------------
15+
FROM redisfab/${ARCH}-xbuild:${OSNICK} as builder
16+
17+
RUN [ "cross-build-start" ]
918

1019
ENV X_NPROC "cat /proc/cpuinfo|grep processor|wc -l"
1120

@@ -24,9 +33,16 @@ RUN pip install keras_preprocessing==1.0.5 --no-deps
2433
RUN set -e; \
2534
git clone https://github.com/tensorflow/tensorflow.git ;\
2635
cd tensorflow ;\
27-
git checkout v${TF_VER}
36+
git checkout v1.13.1
2837

2938
RUN set -e; \
3039
cd tensorflow ;\
3140
./configure ;\
3241
bazel build --jobs $(eval "$X_NPROC") --config=opt //tensorflow:libtensorflow.so
42+
43+
ADD ./deps/readies/ /build/deps/readies/
44+
ADD ./build/tensorflow-arm/collect.py /build/
45+
46+
RUN ./collect.py
47+
48+
RUN [ "cross-build-end" ]

deps/collect-bin.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
import paella
1111

1212
parser = argparse.ArgumentParser(description='Report platform characteristics.')
13-
parser.add_argument('--into', action="store", help='Install into ')
13+
parser.add_argument('--into', action="store", default='install', help='Install into ')
1414
args = parser.parse_args()
1515

16-
17-
paella.mkdir_p('install')
18-
for f in itertools.chain(Path('tensorflow').glob('**/*.so*'), Path('libtorch').glob('**/*.so*')):
19-
link = Path('install')/os.path.basename(f)
16+
paella.mkdir_p(args.into)
17+
for f in itertools.chain(Path('tensorflow').glob('**/*.so*'), Path('libtorch').glob('**/*.so*'), Path('onnxruntime').glob('**/*.so*')):
18+
link = Path(args.into)/os.path.basename(f)
2019
if link.exists():
2120
os.unlink(link)
22-
os.symlink(Path('..')/f, link)
21+
os.symlink(f.resolve(), link)

get_deps.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,23 @@ fi
158158

159159
ORT_ARCHIVE=onnxruntime-${ORT_OS}-${ORT_VERSION}.tgz
160160

161-
if [[ ! -d onnx ]]; then
162-
echo "Installing onnx..."
161+
if [[ ! -d onnxruntime ]]; then
162+
echo "Installing onnxruntime..."
163163

164164
if [[ ! -e ${ORT_ARCHIVE} ]]; then
165165
echo "Downloading ONNXRuntime ${ORT_VERSION} ${ORT_BUILD} ..."
166166
wget -q https://github.com/Microsoft/onnxruntime/releases/download/v${ORT_VERSION}/${ORT_ARCHIVE}
167167
echo "Done."
168168
fi
169169

170-
rm -rf onnx.x
171-
mkdir onnx.x
172-
tar xzf ${ORT_ARCHIVE} --no-same-owner --strip-components=1 -C onnx.x
173-
mv onnx.x onnx
170+
rm -rf onnxruntime.x
171+
mkdir onnxruntime.x
172+
tar xzf ${ORT_ARCHIVE} --no-same-owner --strip-components=1 -C onnxruntime.x
173+
mv onnxruntime.x onnxruntime
174174

175175
echo "Done."
176176
else
177-
echo "onnx is in place."
177+
echo "onnxruntime is in place."
178178
fi
179179

180180
### Collect libraries
@@ -183,11 +183,12 @@ if [[ ! -d install ]]; then
183183
echo "Collecting binaries..."
184184

185185
rm -rf install.x
186-
mkdir install.x
187186
python3 collect-bin.py --into install.x
188187
mv install.x install
189188

190189
echo "Done."
190+
else
191+
echo "Binaries in place."
191192
fi
192193

193194
# echo "Done"

pack.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OSX=""
2727
BIND=""
2828
REDIS_ENT_LIB_PATH=/opt/redislabs/lib
2929

30-
if (( $(./deps/readies/bin/platform --os) == macosx )); then
30+
if [[ $(./deps/readies/bin/platform --os) == macosx ]]; then
3131
OSX=1
3232

3333
export PATH=$PATH:$HOME/Library/Python/2.7/bin
@@ -44,11 +44,11 @@ fi
4444

4545
[[ -z $OSX || -e $REDIS_ENT_LIB_PATH ]] || { echo "$REDIS_ENT_LIB_PATH exists - aborting."; exit 1; }
4646

47-
if [[ -e $REDIS_ENT_LIB_PATH ]]; then
48-
ln -fs $ROOT/deps/install/lib/ $REDIS_ENT_LIB_PATH
47+
if [[ ! -e $REDIS_ENT_LIB_PATH ]]; then
48+
ln -fs $ROOT/deps/install/ $REDIS_ENT_LIB_PATH
4949
else
5050
BIND=1
51-
mount --bind $ROOT/deps/install/lib/ $REDIS_ENT_LIB_PATH
51+
mount --bind $ROOT/deps/install/ $REDIS_ENT_LIB_PATH
5252
fi
5353

5454
export LD_LIBRARY_PATH=$ROOT/deps/install:$LD_LIBRARY_PATH
@@ -69,7 +69,7 @@ ARCHOSVER=$(echo "$PACK_FNAME" | sed -e "s/^$PACKAGE_NAME\.\([^.]*\..*\)\.zip/\1
6969
ARCHOS=$(echo "$ARCHOSVER" | cut -f1 -d.)
7070

7171
echo "Building dependencies ..."
72-
cd $ROOT/deps/install/lib
72+
cd $ROOT/deps/install
7373
tar pczf $BINDIR/$PRODUCT-dependencies.${ARCHOSVER}.tgz *.so*
7474
DEPS_FNAME=$PRODUCT-dependencies.${ARCHOSVER}.tgz
7575

system-setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def redhat_compat(self):
3434
# uninstall and install psutil (order is important), otherwise RLTest fails
3535
self.run("pip uninstall -y psutil")
3636
self.install("python2-psutil")
37+
3738
def fedora(self):
3839
self.group_install("'Development Tools'")
3940

0 commit comments

Comments
 (0)