Skip to content

Commit f707a56

Browse files
authored
Nvidia Jetson support (phase 1) (#535)
1 parent 1584548 commit f707a56

File tree

17 files changed

+562
-45
lines changed

17 files changed

+562
-45
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/bin/
22
/deps/
3+
/docs/
34
/install*
45
/build/
56
.venv/

Dockerfile.jetson

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# BUILD redisfab/redisai:${VERSION}-jetson-${ARCH}-${OSNICK}
2+
3+
ARG REDIS_VER=6.0.9
4+
5+
# OSNICK=bionic|centos7|centos6
6+
ARG OSNICK=bionic
7+
8+
# OS=ubuntu18.04|ubuntu16.04|centos7
9+
ARG OS=ubuntu18.04
10+
11+
# ARCH=arm64v8|arm32v7
12+
ARG ARCH=arm64v8
13+
14+
ARG CUDA_VER=10.2-cudnn7
15+
16+
ARG L4T_VER=r32.4.4
17+
18+
ARG PACK=0
19+
ARG TEST=0
20+
21+
#----------------------------------------------------------------------------------------------
22+
FROM redisfab/redis:${REDIS_VER}-${ARCH}-${OSNICK} AS redis
23+
FROM redisfab/jetpack:4.4.1-arm64v8-l4t as builder
24+
25+
ARG OSNICK
26+
ARG OS
27+
ARG ARCH
28+
ARG REDIS_VER
29+
ARG CUDA_VER
30+
ARG L4T_VER
31+
32+
RUN echo "Building for ${OSNICK} (${OS}) for ${ARCH} [with Redis ${REDIS_VER}]"
33+
34+
ENV NVIDIA_VISIBLE_DEVICES all
35+
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
36+
37+
WORKDIR /build
38+
COPY --from=redis /usr/local/ /usr/local/
39+
40+
COPY ./opt/ opt/
41+
COPY ./tests/flow/test_requirements.txt tests/flow/
42+
43+
RUN PIP=1 FORCE=1 ./opt/readies/bin/getpy3
44+
RUN ./opt/system-setup.py
45+
46+
ARG DEPS_ARGS="GPU=1 JETSON=1 WITH_PT=1 WITH_TF=1 WITH_TFLITE=0 WITH_ORT=0"
47+
COPY ./get_deps.sh .
48+
# RUN if [ "$DEPS_ARGS" = "" ]; then ./get_deps.sh gpu; else env $DEPS_ARGS ./get_deps.sh gpu; fi
49+
RUN set -e ;\
50+
env $DEPS_ARGS ./get_deps.sh
51+
52+
ARG BUILD_ARGS="GPU=1 JETSON=1 WITH_TF=1 WITH_PT=1 WITH_TFLITE=0 WITH_ORT=0"
53+
54+
ADD ./ /build
55+
RUN bash -c "set -e ;\
56+
. ./opt/readies/bin/sourced ./profile.d ;\
57+
make -C opt build $BUILD_ARGS SHOW=1"
58+
59+
ARG PACK
60+
ARG TEST
61+
62+
RUN mkdir -p bin/artifacts
63+
RUN set -e ;\
64+
if [ "$PACK" = "1" ]; then make -C opt pack GPU=1; fi
65+
66+
RUN set -e ;\
67+
if [ "$TEST" = "1" ]; then \
68+
TEST= make -C opt test GPU=1 $BUILD_ARGS NO_LFS=1 ;\
69+
if [[ -d test/logs ]]; then \
70+
tar -C test/logs -czf bin/artifacts/test-logs-gpu.tgz . ;\
71+
fi ;\
72+
fi
73+
74+
#----------------------------------------------------------------------------------------------
75+
# FROM nvidia/cuda:${CUDA_VER}-runtime-${OS}
76+
# FROM nvidia/cuda-arm64:11.1-runtime-ubuntu18.04
77+
# FROM nvcr.io/nvidia/l4t-base:${L4T_VER}
78+
FROM redisfab/jetpack:4.4.1-arm64v8-l4t
79+
80+
ARG OS
81+
ARG L4T_VER
82+
83+
RUN if [ ! -z $(command -v apt-get) ]; then apt-get -qq update; apt-get -q install -y libgomp1; fi
84+
RUN if [ ! -z $(command -v yum) ]; then yum install -y libgomp; fi
85+
86+
ENV REDIS_MODULES /usr/lib/redis/modules
87+
RUN mkdir -p $REDIS_MODULES/
88+
89+
COPY --from=redis /usr/local/ /usr/local/
90+
COPY --from=builder /build/install-gpu/ $REDIS_MODULES/
91+
92+
COPY --from=builder /build/bin/artifacts/ /var/opt/redislabs/artifacts
93+
94+
# COPY --from=builder /usr/local/etc/redis/redis.conf /usr/local/etc/redis/
95+
96+
WORKDIR /data
97+
EXPOSE 6379
98+
# CMD ["/usr/local/bin/redis-server", "/usr/local/etc/redis/redis.conf", "--loadmodule", "/usr/lib/redis/modules/redisai.so"]
99+
CMD ["/usr/local/bin/redis-server", "--loadmodule", "/usr/lib/redis/modules/redisai.so"]

get_deps.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if [[ $1 == --help || $1 == help ]]; then
1616
Argument variables:
1717
CPU=1 Get CPU dependencies
1818
GPU=1 Get GPU dependencies
19+
JETSON=1 Get Jetson Nano dependencies
1920
VERBOSE=1 Print commands
2021
FORCE=1 Download even if present
2122
WITH_DLPACK=0 Skip dlpack
@@ -106,6 +107,9 @@ if [[ $WITH_TF != 0 ]]; then
106107
LIBTF_URL_BASE=https://storage.googleapis.com/tensorflow/libtensorflow
107108
elif [[ $ARCH == arm64v8 ]]; then
108109
TF_ARCH=arm64
110+
if [[ $JETSON == 1 ]]; then
111+
TF_BUILD="gpu-jetson"
112+
fi
109113
LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow
110114
elif [[ $ARCH == arm32v7 ]]; then
111115
TF_ARCH=arm
@@ -205,7 +209,11 @@ if [[ $WITH_PT != 0 ]]; then
205209
if [[ $GPU != 1 ]]; then
206210
PT_BUILD=cpu
207211
else
208-
PT_BUILD=cu101
212+
if [[ $JETSON == 1 ]]; then
213+
PT_BUILD=cu102-jetson
214+
else
215+
PT_BUILD=cu101
216+
fi
209217
fi
210218
if [[ $ARCH == x64 ]]; then
211219
PT_ARCH=x86_64

opt/Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ make flow_tests # run flow test
5353
COV=1 # perform coverage analysis
5454
VALGRIND|VGD=1 # test with Valgrind (implies DEBUG=1)
5555
CALLGRIND|CGD=1 # test with Callgrind (implies DEBUG=1)
56+
REDIS=addr # Address of Redis server for testing
5657

5758
make cov-upload # upload coverage data to codecov.io (requires CODECOV_TOKEN)
5859

@@ -75,6 +76,7 @@ device selection options (fetch, build, and test):
7576
CPU=1 # build for CPU
7677
GPU=1 # build for GPU
7778
CUDA=1 # build for GPU
79+
JETSON=1 # build for Nvidia Jetson
7880
endef
7981

8082
#----------------------------------------------------------------------------------------------
@@ -85,10 +87,13 @@ ifeq ($(GPU),1)
8587
ifeq ($(CPU),1)
8688
$(error CPU=1 and GPU=1 (or CUDA=1) are conflicting)
8789
endif
88-
DEPS_FLAGS=gpu
90+
DEPS_FLAGS += GPU=1
8991
DEVICE=gpu
92+
ifeq ($(JETSON),1)
93+
DEPS_FLAGS += JETSON=1
94+
endif
9095
else
91-
DEPS_FLAGS=cpu
96+
DEPS_FLAGS += CPU=1
9297
DEVICE=cpu
9398
endif
9499

@@ -194,7 +199,7 @@ setup:
194199

195200
fetch deps:
196201
@echo Fetching dependencies...
197-
$(SHOW)VERBOSE=$(_SHOW) $(ROOT)/get_deps.sh $(DEPS_FLAGS)
202+
$(SHOW)VERBOSE=$(_SHOW) $(DEPS_FLAGS) $(ROOT)/get_deps.sh
198203

199204
format:
200205
./clang-format-all.sh
@@ -243,6 +248,7 @@ flow_tests: build
243248
CLUSTER=$(CLUSTER) \
244249
GEN=$(GEN) AOF=$(AOF) SLAVES=$(SLAVES) \
245250
VALGRIND=$(VALGRIND) \
251+
REDIS=$(REDIS) \
246252
$(ROOT)/tests/flow/tests.sh
247253
$(COVERAGE_COLLECT_REPORT)
248254

@@ -257,6 +263,7 @@ test: build
257263
CLUSTER=$(CLUSTER) \
258264
GEN=$(GEN) AOF=$(AOF) SLAVES=$(SLAVES) \
259265
VALGRIND=$(VALGRIND) \
266+
REDIS=$(REDIS) \
260267
$(ROOT)/tests/flow/tests.sh
261268
$(COVERAGE_COLLECT_REPORT)
262269

opt/build/docker/Makefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ OSNICK ?= buster
99
REPO=redisfab
1010
STEM=$(REPO)/redisai
1111

12-
REDIS_VER:=6.0.5
12+
REDIS_VER:=6.0.9
1313

1414
ART_DIR=$(ROOT)/bin/artifacts
1515
ART_INT_DIR=/var/opt/redislabs/artifacts
@@ -23,6 +23,9 @@ BUILD_ARGS.arm32v7=WITH_ORT=0 WITH_PT=0
2323
ifeq ($(CPU),1)
2424
VAR=cpu
2525

26+
FETCH_ARGS=$(FETCH_ARGS.$(ARCH))
27+
BUILD_ARGS=$(BUILD_ARGS.$(ARCH))
28+
2629
else ifeq ($(GPU),1)
2730
VAR=gpu
2831
DOCKERFILE_STEM ?= $(ROOT)/Dockerfile.gpu
@@ -33,12 +36,20 @@ OS.centos7=centos7
3336
OS.bionic=ubuntu18.04
3437
OS.xenial=ubuntu16.04
3538

36-
else
37-
VAR=cpu
39+
FETCH_ARGS=$(FETCH_ARGS.$(ARCH))
40+
BUILD_ARGS=$(BUILD_ARGS.$(ARCH))
41+
42+
else ifeq ($(JETSON),1)
43+
VAR=jetson
44+
DOCKERFILE_STEM ?= $(ROOT)/Dockerfile.jetson
45+
46+
# FETCH_ARGS=WITH_TF=1 WITH_PT=1 WITH_TFLITE=0 WITH_ORT=0
47+
# BUILD_ARGS=WITH_TF=1 WITH_PT=1 WITH_TFLITE=0 WITH_ORT=0
48+
3849
endif
3950

40-
DOCKER_BUILD_ARGS += \
41-
DEPS_ARGS="$(FETCH_ARGS.$(ARCH))" \
42-
BUILD_ARGS="$(BUILD_ARGS.$(ARCH))"
51+
# DOCKER_BUILD_ARGS += \
52+
# DEPS_ARGS="$(FETCH_ARGS)" \
53+
# BUILD_ARGS="$(BUILD_ARGS)"
4354

4455
include $(MK)/docker

opt/build/libtorch/Makefile

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,120 @@
11

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

4-
VERSION ?= 1.5.0
5-
OSNICK ?= buster
4+
VERSION ?= 1.7.0
5+
OSNICK ?= bionic
6+
7+
REDIS_VER=6.0.9
68

79
#----------------------------------------------------------------------------------------------
810

911
S3_URL=redismodules/pytorch
1012

1113
OS:=$(shell $(ROOT)/opt/readies/bin/platform --os)
12-
ifeq ($(OS),macosx)
13-
OS:=macos
14-
endif
15-
STEM=libtorch-cpu-$(OS)
14+
OSNICK:=$(shell $(ROOT)/opt/readies/bin/platform --osnick)
15+
ARCH:=$(shell $(ROOT)/opt/readies/bin/platform --arch)
16+
DEVICE ?= cpu
17+
18+
STEM=libtorch
1619

1720
DOCKER_OS.bionic=ubuntu:bionic
1821
DOCKER_OS.stretch=debian:stretch-slim
1922
DOCKER_OS.buster=debian:buster-slim
2023
DOCKER_OS=$(DOCKER_OS.$(OSNICK))
2124

25+
TAR_ARCH.x64=x86_64
26+
TAR_ARCH.arm64v8=arm64
27+
TAR_ARCH.arm32v7=arm
28+
2229
#----------------------------------------------------------------------------------------------
2330

2431
define targets # (1=OP, 2=op)
2532
$(1)_TARGETS :=
26-
$(1)_TARGETS += $(if $(findstring $(X64),1),$(2)_x64)
33+
$(1)_TARGETS += $(if $(findstring $(X64),1),$(2)_native)
34+
ifeq ($$(CROSS),1)
2735
$(1)_TARGETS += $(if $(findstring $(ARM7),1),$(2)_arm32v7)
2836
$(1)_TARGETS += $(if $(findstring $(ARM8),1),$(2)_arm64v8)
37+
endif
2938

30-
$(1)_TARGETS += $$(if $$(strip $$($(1)_TARGETS)),,$(2)_x64 $(2)_arm32v7 $(2)_arm64v8)
39+
ifeq ($$(CROSS),1)
40+
$(1)_TARGETS += $$(if $$(strip $$($(1)_TARGETS)),,$(2)_native $(2)_arm32v7 $(2)_arm64v8)
41+
else
42+
$(1)_TARGETS += $$(if $$(strip $$($(1)_TARGETS)),,$(2)_native)
43+
endif
3144
endef
3245

3346
$(eval $(call targets,BUILD,build))
3447
$(eval $(call targets,PUBLISH,publish))
3548

3649
#----------------------------------------------------------------------------------------------
3750

38-
define build_x64 # (1=arch, 2=tar-arch)
51+
DOCKER_BUILD_ARGS += \
52+
PT_VER=$(VERSION) \
53+
OSNICK=$(OSNICK) \
54+
OS=$(DOCKER_OS) \
55+
ARCH=$(ARCH)
56+
57+
define build_native # (1=arch, 2=tar-arch)
3958
IID_$(1)=$(1)_$(VERSION).iid
4059
CID_$(1)=$(1)_$(VERSION).cid
4160

42-
build_x64:
43-
@docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.x64 \
44-
--build-arg OS=$(DOCKER_OS) $(ROOT)
61+
build_native:
62+
@docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM):$(VERSION)-$(DEVICE)-$(1) -f Dockerfile.$(VARIANT) \
63+
$(foreach A,$(DOCKER_BUILD_ARGS),--build-arg $(A)) .
4564
@docker create --cidfile $$(CID_$(1)) `cat $$(IID_$(1))`
46-
@docker cp `cat $$(CID_$(1))`:/build/dest/$(STEM)-$(2)-$(VERSION).tar.gz .
65+
@docker cp `cat $$(CID_$(1))`:/build/dest/$(STEM)-$(DEVICE)-$(OS)-$(2)-$(VERSION).tar.gz .
4766

48-
.PHONY: build_x64
67+
.PHONY: build_native
4968
endef
5069

70+
ifeq ($(CROSS),1)
71+
5172
define build_arm # (1=arch, 2=tar-arch)
5273
IID_$(1)=$(1)_$(VERSION).iid
5374
CID_$(1)=$(1)_$(VERSION).cid
5475

5576
build_$(1):
56-
@docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.arm \
57-
--build-arg ARCH=$(1) $(ROOT)
77+
@docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM):$(VERSION)-$(DEVICE)-$(1) -f Dockerfile.$(VARIANT) \
78+
$(foreach A,$(DOCKER_BUILD_ARGS),--build-arg $(A)) .
5879
@docker create --cidfile $$(CID_$(1)) `cat $$(IID_$(1))`
5980
@docker cp `cat $$(CID_$(1))`:/build/$(STEM)-$(2)-$(VERSION).tar.gz .
6081

6182
.PHONY: build_$(1)
6283
endef
6384

85+
endif # CROSS
86+
6487
#----------------------------------------------------------------------------------------------
6588

66-
define publish_x64 # (1=arch, 2=tar-arch)
67-
publish_x64:
89+
define publish_native # (1=arch, 2=tar-arch)
90+
publish_native:
6891
@aws s3 cp $(STEM)-$(2)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read
6992

70-
.PHONY: publish_x64
93+
.PHONY: publish_native
7194
endef
7295

96+
ifeq ($(CROSS),1)
97+
7398
define publish_arm # (1=arch, 2=tar-arch)
7499
publish_$(1):
75100
@aws s3 cp $(STEM)-$(2)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read
76101

77102
.PHONY: publish_$(1)
78103
endef
79104

105+
endif # CROSS
106+
80107
#----------------------------------------------------------------------------------------------
81108

82109
all: build publish
83110

84111
build: $(BUILD_TARGETS)
85112

86-
$(eval $(call build_x64,x64,x86_64))
113+
$(eval $(call build_native,$(ARCH),$(TAR_ARCH.$(ARCH))))
114+
ifeq ($(CROSS),1)
87115
$(eval $(call build_arm,arm64v8,arm64))
88116
$(eval $(call build_arm,arm32v7,arm))
117+
endif
89118

90119
ifneq ($(filter publish,$(MAKECMDGOALS)),)
91120
ifeq ($(wildcard $(HOME)/.aws/credentials),)
@@ -96,13 +125,16 @@ endif
96125
publish: $(PUBLISH_TARGETS)
97126

98127
$(eval $(call publish_x64,x64,x86_64))
128+
ifeq ($(CROSS),1)
99129
$(eval $(call publish_arm,arm64v8,arm64))
100130
$(eval $(call publish_arm,arm32v7,arm))
131+
endif
101132

102133
repack:
103134
@PT_VERSION=$(VERSION) GPU=$(GPU) ./repack.sh
104135

105136
help:
106-
@echo "make [build|repack|publish] [X64=1|ARM7=1|ARM8=1]"
137+
@echo "make [build|repack|publish] [X64=1|ARM7=1|ARM8=1] [CROSS=1]"
107138

108139
.PHONY: all build repack publish help
140+

0 commit comments

Comments
 (0)