From 4fbbb760631ba34f9b4040bcf5de9af499af2285 Mon Sep 17 00:00:00 2001 From: DvirDukhan <dvir@redislabs.com> Date: Tue, 9 Mar 2021 23:01:23 +0200 Subject: [PATCH 01/17] added new build script --- opt/build/tflite/new_build.sh | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 opt/build/tflite/new_build.sh diff --git a/opt/build/tflite/new_build.sh b/opt/build/tflite/new_build.sh new file mode 100644 index 000000000..ccecfb7a0 --- /dev/null +++ b/opt/build/tflite/new_build.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -e +set -x +VERSION=$1 +wget https://github.com/tensorflow/tensorflow/archive/v$VERSION.tar.gz +tar -xzf v$VERSION.tar.gz +cd tensorflow-$VERSION +# build tensorflow lite library +bazel build --config=monolithic --config=cuda //tensorflow/lite:libtensorflowlite.so +./tensorflow/lite/tools/make/download_dependencies.sh +TMP_LIB="tmp" +# flatbuffer header files +mkdir -p $TMP_LIB/include +cp -r tensorflow/lite/tools/make/downloads/flatbuffers/include/flatbuffers $TMP_LIB/include/ +# tensorflow lite header files +TFLITE_DIR="tensorflow/lite" +declare -a tfLiteDirectories=( + "$TFLITE_DIR" + "$TFLITE_DIR/c" + "$TFLITE_DIR/core" + "$TFLITE_DIR/core/api" + "$TFLITE_DIR/delegates/nnapi" + "$TFLITE_DIR/delegates/xnnpack" + "$TFLITE_DIR/experimental/resource" + "$TFLITE_DIR/kernels" + "$TFLITE_DIR/nnapi" + "$TFLITE_DIR/schema" + "$TFLITE_DIR/tools/evaluation" +) +for dir in "${tfLiteDirectories[@]}" +do + mkdir -p $TMP_LIB/include/$dir + cp $dir/*h $TMP_LIB/include/$dir +done +mkdir -p $TMP_LIB/lib +cp bazel-bin/tensorflow/lite/libtensorflowlite.so $TMP_LIB/lib +# build tensorflow lite GPU delegate library +apt-get install libegl1-mesa-dev -y +apt-get install libgles2-mesa-dev -y +bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so +cp bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so $TMP_LIB/lib +# create .tar.gz file +cd $TMP_LIB +tar -cvzf libtensorflowlite-linux-arm64-$VERSION.tar.gz . \ No newline at end of file From 5321ae7f5137d0bae16c8c2c88636eef048e640b Mon Sep 17 00:00:00 2001 From: DvirDukhan <dvir@redislabs.com> Date: Tue, 9 Mar 2021 23:03:10 +0200 Subject: [PATCH 02/17] added arch variable --- opt/build/tflite/new_build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 opt/build/tflite/new_build.sh diff --git a/opt/build/tflite/new_build.sh b/opt/build/tflite/new_build.sh old mode 100644 new mode 100755 index ccecfb7a0..8f5b3db90 --- a/opt/build/tflite/new_build.sh +++ b/opt/build/tflite/new_build.sh @@ -2,6 +2,7 @@ set -e set -x VERSION=$1 +ARCH=$2 wget https://github.com/tensorflow/tensorflow/archive/v$VERSION.tar.gz tar -xzf v$VERSION.tar.gz cd tensorflow-$VERSION @@ -41,4 +42,4 @@ bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 tensorfl cp bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so $TMP_LIB/lib # create .tar.gz file cd $TMP_LIB -tar -cvzf libtensorflowlite-linux-arm64-$VERSION.tar.gz . \ No newline at end of file +tar -cvzf libtensorflowlite-linux-$ARCH-$VERSION.tar.gz . \ No newline at end of file From e80fe1084d4e9545939022232360fed8a87ef313 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Sun, 18 Apr 2021 16:27:04 +0300 Subject: [PATCH 03/17] tflite x64 --- CMakeLists.txt | 22 ++++-- get_deps.sh | 18 ++--- opt/Makefile | 15 ++-- opt/build/tflite/Dockerfile.x64 | 48 +++++++------ opt/build/tflite/Makefile | 10 +-- opt/build/tflite/build | 20 ------ opt/build/tflite/build.macos | 12 ---- opt/build/tflite/{new_build.sh => build.sh} | 20 ++++-- opt/build/tflite/collect.py | 80 --------------------- 9 files changed, 77 insertions(+), 168 deletions(-) mode change 100755 => 100644 opt/build/tflite/Dockerfile.x64 delete mode 100755 opt/build/tflite/build delete mode 100755 opt/build/tflite/build.macos rename opt/build/tflite/{new_build.sh => build.sh} (78%) delete mode 100755 opt/build/tflite/collect.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b57cab5d..b54828a7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,14 +137,25 @@ ENDIF() #---------------------------------------------------------------------------------------------- IF(BUILD_TFLITE) - FIND_LIBRARY(TFLITE_LIBRARIES_1 NAMES tensorflow-lite + FIND_LIBRARY(TFLITE_LIBRARIES_1 NAMES tensorflowlite PATHS ${depsAbs}/libtensorflow-lite/lib) - FIND_LIBRARY(TFLITE_LIBRARIES_2 NAMES benchmark-lib.a + IF (${DEVICE} STREQUAL "gpu") + FIND_LIBRARY(TFLITE_LIBRARIES_2 NAMES tensorflowlite_gpu_delegate PATHS ${depsAbs}/libtensorflow-lite/lib) - SET(TFLITE_LIBRARIES ${TFLITE_LIBRARIES_1} ${TFLITE_LIBRARIES_2}) - MESSAGE(STATUS "Found TensorFlow Lite Libraries: \"${TFLITE_LIBRARIES}\")") + IF (NOT APPLE) + FIND_LIBRARY(OPENGL_LIBRARIES NAMES GL + PATHS /usr/lib/${MACH}-linux-gnu) + FIND_LIBRARY(EGL_LIBRARIES NAMES EGL + PATHS /usr/lib/${MACH}-linux-gnu) + ELSE() + MESSAGE(FATAL_ERROR "Build for TensorFlow Lite GPU backend on Apple machines.") + ENDIF() + ENDIF() + SET(TFLITE_LIBRARIES ${TFLITE_LIBRARIES_1} ${TFLITE_LIBRARIES_2} ${OPENGL_LIBRARIES} ${EGL_LIBRARIES}) IF (NOT TFLITE_LIBRARIES) MESSAGE(FATAL_ERROR "Could not find TensorFlow Lite") + ELSE() + MESSAGE(STATUS "Found TensorFlow Lite Libraries: \"${TFLITE_LIBRARIES}\")") ENDIF() IF (${DEVICE} STREQUAL "gpu") ADD_DEFINITIONS(-DRAI_TFLITE_USE_CUDA) @@ -200,7 +211,6 @@ ENDIF() #---------------------------------------------------------------------------------------------- ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(tests/module) ADD_LIBRARY(redisai SHARED $<TARGET_OBJECTS:redisai_obj>) TARGET_LINK_LIBRARIES(redisai ${CMAKE_DL_LIBS}) @@ -321,4 +331,4 @@ if(PACKAGE_UNIT_TESTS) enable_testing() include(GoogleTest) add_subdirectory(tests/unit) -endif() \ No newline at end of file +endif() diff --git a/get_deps.sh b/get_deps.sh index 4a70f536e..4f66cbae1 100755 --- a/get_deps.sh +++ b/get_deps.sh @@ -12,7 +12,7 @@ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" if [[ $1 == --help || $1 == help ]]; then cat <<-END [ARGVARS...] get_deps.sh [cpu|gpu] [--help|help] - + Argument variables: CPU=1 Get CPU dependencies GPU=1 Get GPU dependencies @@ -103,7 +103,7 @@ if [[ $WITH_TF != 0 ]]; then fi if [[ $ARCH == x64 ]]; then TF_ARCH=x86_64 - + LIBTF_URL_BASE=https://storage.googleapis.com/tensorflow/libtensorflow elif [[ $ARCH == arm64v8 ]]; then TF_ARCH=arm64 @@ -134,7 +134,7 @@ if [[ $WITH_TF != 0 ]]; then mkdir $LIBTENSORFLOW.x tar xf $LIBTF_ARCHIVE --no-same-owner -C $LIBTENSORFLOW.x mv $LIBTENSORFLOW.x $LIBTENSORFLOW - + echo "Done." else echo "TensorFlow is in place." @@ -145,14 +145,14 @@ fi # WITH_TF ################################################################################# LIBTFLITE -TFLITE_VERSION="2.0.0" +TFLITE_VERSION="2.4.0" if [[ $WITH_TFLITE != 0 ]]; then [[ $FORCE == 1 ]] && rm -rf $LIBTFLITE if [[ ! -d $LIBTFLITE ]]; then echo "Installing TensorFlow Lite ..." - + LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow if [[ $OS == linux ]]; then TFLITE_OS="linux" @@ -183,7 +183,7 @@ if [[ $WITH_TFLITE != 0 ]]; then mkdir $LIBTFLITE.x tar xf $LIBTFLITE_ARCHIVE --no-same-owner -C $LIBTFLITE.x mv $LIBTFLITE.x $LIBTFLITE - + echo "Done." else echo "TensorFlow Lite is in place." @@ -241,14 +241,14 @@ if [[ $WITH_PT != 0 ]]; then [[ ! -f $LIBTORCH_ARCHIVE || $FORCE == 1 ]] && wget -q $LIBTORCH_URL fi - + rm -rf $LIBTORCH.x mkdir $LIBTORCH.x tar xf $LIBTORCH_ARCHIVE --no-same-owner -C $LIBTORCH.x mv $LIBTORCH.x/libtorch $LIBTORCH rmdir $LIBTORCH.x - + echo "Done." else echo "libtorch is in place." @@ -322,7 +322,7 @@ if [[ $WITH_ORT != 0 ]]; then mkdir $ONNXRUNTIME.x tar xzf ${ORT_ARCHIVE} --no-same-owner --strip-components=1 -C $ONNXRUNTIME.x mv $ONNXRUNTIME.x $ONNXRUNTIME - + echo "Done." else echo "ONNXRuntime is in place." diff --git a/opt/Makefile b/opt/Makefile index 5d5fcaa06..96fe62778 100755 --- a/opt/Makefile +++ b/opt/Makefile @@ -36,7 +36,7 @@ make build # compile and link PROFILE=1 # enable profiling compile flags (and debug symbols) for release type. # You can consider this as build type release with debug symbols and -fno-omit-frame-pointer VARIANT=name # build variant `name` - WHY=1 # explain CMake decisions (into /tmp/cmake.why) + WHY=1 # explain CMake decisions (into /tmp/cmake.why) make clean # remove build artifacts ALL=1 # remove entire artifacts directory make install # create ready-to-run scheme (module and engines) @@ -79,7 +79,7 @@ device selection options (fetch, build, and test): JETSON=1 # build for Nvidia Jetson endef -#---------------------------------------------------------------------------------------------- +#---------------------------------------------------------------------------------------------- override GPU:=$(or $(findstring $(CUDA),1),$(findstring $(GPU),1)) @@ -97,7 +97,7 @@ DEPS_FLAGS += CPU=1 DEVICE=cpu endif -#---------------------------------------------------------------------------------------------- +#---------------------------------------------------------------------------------------------- SRCDIR=.. BINDIR=$(BINROOT)/src @@ -110,7 +110,7 @@ INSTALLED_TARGET=$(INSTALL_DIR)/redisai.so BACKENDS_PATH ?= $(INSTALL_DIR)/backends -#---------------------------------------------------------------------------------------------- +#---------------------------------------------------------------------------------------------- CMAKE_FILES += \ $(SRCDIR)/CMakeLists.txt \ @@ -135,7 +135,8 @@ CMAKE_FLAGS += \ -DUSE_COVERAGE=$(USE_COVERAGE) \ -DUSE_PROFILE=$(USE_PROFILE) \ -DREDISAI_GIT_SHA=\"$(GIT_SHA)\" \ - -DDEVICE=$(DEVICE) + -DDEVICE=$(DEVICE) \ + -DMACH=$(shell uname -m) ifeq ($(WITH_TF),0) CMAKE_FLAGS += -DBUILD_TF=off @@ -165,7 +166,7 @@ include $(MK)/defs include $(MK)/rules -#---------------------------------------------------------------------------------------------- +#---------------------------------------------------------------------------------------------- #prebuild: # $(SHOW)if [ ! -d $(DEPS_DIR) ]; then echo $$'Dependencies are not in place.\nPlease run \'make fetch\'.'; exit 1; fi @@ -190,7 +191,7 @@ else -$(SHOW)$(MAKE) -C $(BINDIR) clean endif -#---------------------------------------------------------------------------------------------- +#---------------------------------------------------------------------------------------------- setup: @echo Setting up system... diff --git a/opt/build/tflite/Dockerfile.x64 b/opt/build/tflite/Dockerfile.x64 old mode 100755 new mode 100644 index 53a474c69..8de453084 --- a/opt/build/tflite/Dockerfile.x64 +++ b/opt/build/tflite/Dockerfile.x64 @@ -1,29 +1,31 @@ +ARG OS=nvidia/cuda:11.0.3-cudnn8-devel-ubuntu18.04 -ARG OS=debian:buster - -ARG FTLITE_VER=2.0.0 +ARG TFLITE_VERSION=2.4.0 +ARG TFLITE_ARCH=x86_64 #---------------------------------------------------------------------------------------------- FROM ${OS} +ARG BAZEL_VERSION=3.1.0 ARG FTLITE_VER - -WORKDIR /build - -RUN set -e ;\ - apt-get -qq update ;\ - apt-get -q install -y git ca-certificates curl wget unzip python3 ;\ - apt-get -q install -y git build-essential zlib1g-dev - -RUN git clone --single-branch --branch v${FTLITE_VER} --depth 1 https://github.com/tensorflow/tensorflow.git - -ADD ./opt/build/tflite/build /build/ -ADD ./opt/readies/ /build/readies/ -ADD ./opt/build/tflite/collect.py /build/ - -RUN set -e ;\ - cd tensorflow/tensorflow/lite/tools/make ;\ - ./download_dependencies.sh ;\ - ./build_lib.sh - -RUN ./collect.py --version ${FTLITE_VER} --dest /build/dest +ARG TFLITE_VERSION +ARG TFLITE_ARCH + +ADD ./opt/build/tflite /tflite + +RUN apt-get -qq update && apt-get install -yqq python3 +RUN apt-get install -qqy git \ + unzip \ + wget \ + curl \ + build-essential \ + zlib1g-dev \ + libegl1-mesa-dev \ + libgles2-mesa-dev \ + python3-distutils \ + python3-numpy +RUN ln -s /usr/bin/python3 /usr/bin/python +RUN wget -q https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel_3.1.0-linux-x86_64.deb -O /tmp/bazel.deb +RUN dpkg -i /tmp/bazel.deb +WORKDIR /tflite +RUN bash build.sh ${TFLITE_VERSION} ${TFLITE_ARCH} diff --git a/opt/build/tflite/Makefile b/opt/build/tflite/Makefile index 8962177b7..4f88bac6d 100755 --- a/opt/build/tflite/Makefile +++ b/opt/build/tflite/Makefile @@ -1,7 +1,7 @@ ROOT=../../.. -export VERSION ?= 2.0.0 +export VERSION ?= 2.4.0 OSNICK ?= buster #---------------------------------------------------------------------------------------------- @@ -25,7 +25,7 @@ DOCKER_OS.bionic=ubuntu:bionic DOCKER_OS.stretch=debian:stretch-slim DOCKER_OS.buster=debian:buster-slim DOCKER_OS=$(DOCKER_OS.$(OSNICK)) - + #---------------------------------------------------------------------------------------------- ifeq ($(OS),linux) @@ -57,10 +57,10 @@ IID_$(1)=$(1)_$(VERSION).iid CID_$(1)=$(1)_$(VERSION).cid build_x64: - @docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.x64 \ - --build-arg OS=$(DOCKER_OS) $(ROOT) + -@rm *.iid *.cid + @docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.x64 $(ROOT) @docker create --cidfile $$(CID_$(1)) `cat $$(IID_$(1))` - @docker cp `cat $$(CID_$(1))`:/build/dest/$(STEM)-$(2)-$(VERSION).tar.gz . + @docker cp `cat $$(CID_$(1))`:/tflite/tensorflow-$(VERSION)/tmp/libtensorflowlite-linux-x64-$(VERSION).tar.gz . .PHONY: build_x64 endef diff --git a/opt/build/tflite/build b/opt/build/tflite/build deleted file mode 100755 index ba9a8cb71..000000000 --- a/opt/build/tflite/build +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -OS=$(python3 readies/bin/platform --os) -ARCH=$(python3 readies/bin/platform --arch) - -cd tensorflow/tensorflow/lite/tools/make -bash download_dependencies.sh -if [[ $OS == linux ]]; then - TARGET=linux - if [[ $ARCH == x64 ]]; then - bash build_lib.sh - elif [[ $ARCH == arm64v8 ]]; then - bash build_aarch64_lib.sh - elif [[ $ARCH == arm32v7 ]]; then - bash build_rpi_lib.sh - fi -elif [[ $OS == macos ]]; then - TARGET=osx - bash build_lib.sh -fi diff --git a/opt/build/tflite/build.macos b/opt/build/tflite/build.macos deleted file mode 100755 index 316d38e0f..000000000 --- a/opt/build/tflite/build.macos +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -cd $HERE - -set -e -mkdir -p macos -cd macos -cp ../collect.py . -ln -s ../../../readies/ -git clone --single-branch --branch v${VERSION} --depth 1 https://github.com/tensorflow/tensorflow.git -./collect.py --version $VERSION --dest dest diff --git a/opt/build/tflite/new_build.sh b/opt/build/tflite/build.sh similarity index 78% rename from opt/build/tflite/new_build.sh rename to opt/build/tflite/build.sh index 8f5b3db90..6e7c837ee 100755 --- a/opt/build/tflite/new_build.sh +++ b/opt/build/tflite/build.sh @@ -2,9 +2,20 @@ set -e set -x VERSION=$1 +if [ "X$VERSION" == "X" ]; then + VERSION=2.4.0 +fi ARCH=$2 -wget https://github.com/tensorflow/tensorflow/archive/v$VERSION.tar.gz -tar -xzf v$VERSION.tar.gz + +BAZEL_VERSION=$3 +if [ "X$BAZEL_VERSION" == "X" ]; then + BAZEL_VERSION=3.5.1 +fi + +if [ ! -f v$VERSION.tar.gz ]; then + wget -q https://github.com/tensorflow/tensorflow/archive/v$VERSION.tar.gz + tar -xzf v$VERSION.tar.gz +fi cd tensorflow-$VERSION # build tensorflow lite library bazel build --config=monolithic --config=cuda //tensorflow/lite:libtensorflowlite.so @@ -35,11 +46,8 @@ do done mkdir -p $TMP_LIB/lib cp bazel-bin/tensorflow/lite/libtensorflowlite.so $TMP_LIB/lib -# build tensorflow lite GPU delegate library -apt-get install libegl1-mesa-dev -y -apt-get install libgles2-mesa-dev -y bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so cp bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so $TMP_LIB/lib # create .tar.gz file cd $TMP_LIB -tar -cvzf libtensorflowlite-linux-$ARCH-$VERSION.tar.gz . \ No newline at end of file +tar -cvzf libtensorflowlite-linux-$ARCH-$VERSION.tar.gz include lib diff --git a/opt/build/tflite/collect.py b/opt/build/tflite/collect.py deleted file mode 100755 index 4d4e4b347..000000000 --- a/opt/build/tflite/collect.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys -import argparse -from pathlib import Path -import shutil -import tarfile - -# this refers to deps directory inside a container -sys.path.insert(0, os.path.join(os.path.dirname(__file__), "readies")) -import paella - -#---------------------------------------------------------------------------------------------- - -TFLITE_VERSION = '2.0.0' - -parser = argparse.ArgumentParser(description='Prepare RedisAI dependant distribution packages.') -parser.add_argument('--tensorflow', default='tensorflow', help='root of tensorflow repository') -parser.add_argument('--version', default=TFLITE_VERSION, help='tensorflow version') -parser.add_argument('--dest', default='dest', help='destination directory') -parser.add_argument('-n', '--nop', action="store_true", help='no operation') -args = parser.parse_args() - -#---------------------------------------------------------------------------------------------- - -tensorflow = Path(args.tensorflow).resolve() -dest = Path(args.dest).resolve() - -#---------------------------------------------------------------------------------------------- - -platform = paella.Platform() - -tf_os = platform.os -tf_os_internal = tf_os -if tf_os == 'macos': - tf_os = 'darwin' - tf_os_internal = 'osx' - -tf_arch = platform.arch -if tf_arch == 'x64': - tf_arch = 'x86_64' -elif tf_arch == 'arm64v8': - tf_arch = 'arm64' - -tf_ver = args.version - -#---------------------------------------------------------------------------------------------- - -def copy_p(src, dest): - f = dest/src - paella.mkdir_p(os.path.dirname(f)) - shutil.copy(src, f, follow_symlinks=False) - -def create_tar(name, basedir, dir='.'): - def reset_uid(tarinfo): - tarinfo.uid = tarinfo.gid = 0 - tarinfo.uname = tarinfo.gname = "root" - return tarinfo - with cwd(basedir): - with tarfile.open(name, 'w:gz') as tar: - tar.add(dir, filter=reset_uid) - -def collect_tflite(): - d_tensorflow = dest - with cwd(tensorflow): - for f in Path('tensorflow/lite').glob('**/*.h'): - copy_p(f, d_tensorflow/'include') - with cwd('tensorflow/lite/tools/make'): - with cwd('downloads/flatbuffers/include'): - for f in Path('.').glob('**/*.h'): - copy_p(f, d_tensorflow/'include') - with cwd(f'gen/{tf_os_internal}_{tf_arch}/lib'): - for f in Path('.').glob('*.a'): - copy_p(f, d_tensorflow/'lib') - create_tar(dest/f'libtensorflowlite-{tf_os}-{tf_arch}-{tf_ver}.tar.gz', dest) - -#---------------------------------------------------------------------------------------------- - -collect_tflite() From 2afba49fba49e6e15c09a82610a4fc3ff4759c09 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Sun, 18 Apr 2021 17:33:24 +0300 Subject: [PATCH 04/17] package path update --- .gitignore | 8 ++++++-- opt/build/tflite/Makefile | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 882c8c6cd..1791006fd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ venv*/ *.tar.gz /VARIANT -# Docs API reference +# Docs API reference docs/api_reference.md ### Cmake auto tools @@ -137,4 +137,8 @@ dkms.conf .idea_modules/ # docs site -site/ \ No newline at end of file +site/ + +# docker remnants +*.iid +*.cid diff --git a/opt/build/tflite/Makefile b/opt/build/tflite/Makefile index 4f88bac6d..1c1f1577f 100755 --- a/opt/build/tflite/Makefile +++ b/opt/build/tflite/Makefile @@ -60,7 +60,7 @@ build_x64: -@rm *.iid *.cid @docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.x64 $(ROOT) @docker create --cidfile $$(CID_$(1)) `cat $$(IID_$(1))` - @docker cp `cat $$(CID_$(1))`:/tflite/tensorflow-$(VERSION)/tmp/libtensorflowlite-linux-x64-$(VERSION).tar.gz . + @docker cp `cat $$(CID_$(1))`:/tflite/tensorflow-$(VERSION)/tmp/libtensorflowlite-linux-x86_x64-$(VERSION).tar.gz . .PHONY: build_x64 endef From 77e90326f570a794fcae7b80163ab1acc4a5e25f Mon Sep 17 00:00:00 2001 From: Chayim Kirshen <c@kirshen.com> Date: Sun, 18 Apr 2021 17:35:21 +0300 Subject: [PATCH 05/17] jetson dockerfile and make change to call it --- opt/build/tflite/Dockerfile.jetson | 31 ++++++++++++++++++++++++++++++ opt/build/tflite/Makefile | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 opt/build/tflite/Dockerfile.jetson diff --git a/opt/build/tflite/Dockerfile.jetson b/opt/build/tflite/Dockerfile.jetson new file mode 100644 index 000000000..abd036b77 --- /dev/null +++ b/opt/build/tflite/Dockerfile.jetson @@ -0,0 +1,31 @@ +ARG OS=nvcr.io/nvidia/l4t-ml:r32.5.0-py3 + +ARG TFLITE_VERSION=2.4.0 +ARG TFLITE_ARCH=aarch64 + +#---------------------------------------------------------------------------------------------- +FROM ${OS} + +ARG BAZEL_VERSION=3.1.0 +ARG FTLITE_VER +ARG TFLITE_VERSION +ARG TFLITE_ARCH + +ADD ./opt/build/tflite /tflite +ADD ./opt/readies /build + +RUN apt-get -qq update && apt-get install -yqq python3 +RUN apt-get install -qqy git \ + unzip \ + wget \ + curl \ + build-essential \ + zlib1g-dev \ + libegl1-mesa-dev \ + libgles2-mesa-dev \ + python3-distutils \ + python3-numpy +RUN /build/bin/getbazel +#RUN ln -s /usr/bin/python3 /usr/bin/python +WORKDIR /tflite +RUN bash build.sh ${TFLITE_VERSION} ${TFLITE_ARCH} diff --git a/opt/build/tflite/Makefile b/opt/build/tflite/Makefile index 1c1f1577f..6137e0b4e 100755 --- a/opt/build/tflite/Makefile +++ b/opt/build/tflite/Makefile @@ -70,7 +70,7 @@ IID_$(1)=$(1)_$(VERSION).iid CID_$(1)=$(1)_$(VERSION).cid build_$(1): - @docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.arm \ + @docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.jetson \ --build-arg ARCH=$(1) $(ROOT) @docker create --cidfile $$(CID_$(1)) `cat $$(IID_$(1))` @docker cp `cat $$(CID_$(1))`:/build/$(STEM)-$(2)-$(VERSION).tar.gz . From 415127576e52571ddf8b200d3c9e0ff88c6f569f Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Tue, 20 Apr 2021 19:13:04 +0300 Subject: [PATCH 06/17] tflite, in docker, x64 --- opt/build/tflite/Dockerfile.jetson | 31 ------------------------------ opt/build/tflite/Dockerfile.x64 | 11 +++++------ opt/build/tflite/build.sh | 18 ++++++++++------- 3 files changed, 16 insertions(+), 44 deletions(-) delete mode 100644 opt/build/tflite/Dockerfile.jetson diff --git a/opt/build/tflite/Dockerfile.jetson b/opt/build/tflite/Dockerfile.jetson deleted file mode 100644 index abd036b77..000000000 --- a/opt/build/tflite/Dockerfile.jetson +++ /dev/null @@ -1,31 +0,0 @@ -ARG OS=nvcr.io/nvidia/l4t-ml:r32.5.0-py3 - -ARG TFLITE_VERSION=2.4.0 -ARG TFLITE_ARCH=aarch64 - -#---------------------------------------------------------------------------------------------- -FROM ${OS} - -ARG BAZEL_VERSION=3.1.0 -ARG FTLITE_VER -ARG TFLITE_VERSION -ARG TFLITE_ARCH - -ADD ./opt/build/tflite /tflite -ADD ./opt/readies /build - -RUN apt-get -qq update && apt-get install -yqq python3 -RUN apt-get install -qqy git \ - unzip \ - wget \ - curl \ - build-essential \ - zlib1g-dev \ - libegl1-mesa-dev \ - libgles2-mesa-dev \ - python3-distutils \ - python3-numpy -RUN /build/bin/getbazel -#RUN ln -s /usr/bin/python3 /usr/bin/python -WORKDIR /tflite -RUN bash build.sh ${TFLITE_VERSION} ${TFLITE_ARCH} diff --git a/opt/build/tflite/Dockerfile.x64 b/opt/build/tflite/Dockerfile.x64 index 8de453084..a0868782e 100644 --- a/opt/build/tflite/Dockerfile.x64 +++ b/opt/build/tflite/Dockerfile.x64 @@ -1,12 +1,13 @@ -ARG OS=nvidia/cuda:11.0.3-cudnn8-devel-ubuntu18.04 +ARG BAZEL_VERSION=3.1.0 +ARG TFLITE_ARCH=x86_64 + +ARG OS=redisfab/ubuntu1804-${TFLITE_ARCH}-bazel${BAZEL_VERSION} ARG TFLITE_VERSION=2.4.0 -ARG TFLITE_ARCH=x86_64 #---------------------------------------------------------------------------------------------- FROM ${OS} -ARG BAZEL_VERSION=3.1.0 ARG FTLITE_VER ARG TFLITE_VERSION ARG TFLITE_ARCH @@ -25,7 +26,5 @@ RUN apt-get install -qqy git \ python3-distutils \ python3-numpy RUN ln -s /usr/bin/python3 /usr/bin/python -RUN wget -q https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel_3.1.0-linux-x86_64.deb -O /tmp/bazel.deb -RUN dpkg -i /tmp/bazel.deb WORKDIR /tflite -RUN bash build.sh ${TFLITE_VERSION} ${TFLITE_ARCH} +RUN bash build.sh ${TFLITE_ARCH} ${TFLITE_VERSION} diff --git a/opt/build/tflite/build.sh b/opt/build/tflite/build.sh index 6e7c837ee..25b67da2e 100755 --- a/opt/build/tflite/build.sh +++ b/opt/build/tflite/build.sh @@ -1,15 +1,16 @@ #!/bin/bash set -e set -x -VERSION=$1 +ARCH=$1 + +VERSION=$2 if [ "X$VERSION" == "X" ]; then VERSION=2.4.0 fi -ARCH=$2 -BAZEL_VERSION=$3 -if [ "X$BAZEL_VERSION" == "X" ]; then - BAZEL_VERSION=3.5.1 +BASEOS=$3 +if [ "X$BASEOS" == "X" ]; then + BASEOS=linux fi if [ ! -f v$VERSION.tar.gz ]; then @@ -17,9 +18,12 @@ if [ ! -f v$VERSION.tar.gz ]; then tar -xzf v$VERSION.tar.gz fi cd tensorflow-$VERSION + +# fetch dependencies +./tensorflow/lite/tools/make/download_dependencies.sh + # build tensorflow lite library bazel build --config=monolithic --config=cuda //tensorflow/lite:libtensorflowlite.so -./tensorflow/lite/tools/make/download_dependencies.sh TMP_LIB="tmp" # flatbuffer header files mkdir -p $TMP_LIB/include @@ -50,4 +54,4 @@ bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 tensorfl cp bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so $TMP_LIB/lib # create .tar.gz file cd $TMP_LIB -tar -cvzf libtensorflowlite-linux-$ARCH-$VERSION.tar.gz include lib +tar -cvzf libtensorflowlite-$BASEOS-$ARCH-$VERSION.tar.gz include lib From dab47f6f35abc9adbd875a98903b694e2917f40c Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Tue, 20 Apr 2021 21:23:13 +0300 Subject: [PATCH 07/17] shell script fix to inherit directory --- opt/build/tflite/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opt/build/tflite/build.sh b/opt/build/tflite/build.sh index 25b67da2e..6a9a4a7ea 100755 --- a/opt/build/tflite/build.sh +++ b/opt/build/tflite/build.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e set -x + +cd `dirname ${BASH_SOURCE[0]}` ARCH=$1 VERSION=$2 From cec98278ef4a88e0a8ac7afe783ac12a9d4c1241 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Tue, 20 Apr 2021 22:14:17 +0300 Subject: [PATCH 08/17] Makefile to add bulid and publish targets --- opt/build/tflite/Makefile | 126 +++++++++++--------------------------- 1 file changed, 36 insertions(+), 90 deletions(-) diff --git a/opt/build/tflite/Makefile b/opt/build/tflite/Makefile index 6137e0b4e..cc88be2d4 100755 --- a/opt/build/tflite/Makefile +++ b/opt/build/tflite/Makefile @@ -1,19 +1,31 @@ - ROOT=../../.. export VERSION ?= 2.4.0 -OSNICK ?= buster #---------------------------------------------------------------------------------------------- S3_URL=redismodules/tensorflow OS:=$(shell $(ROOT)/opt/readies/bin/platform --os) +ARCH:=$(shell $(ROOT)/opt/readies/bin/platform --arch) +# non-arm linux ifeq ($(OS),linux) +ifeq ($(ARCH),x64) OS.publish:=$(OS) -ARCH.publish:=$(ARCH) +ARCH.publish:=x86_64 + +BUILD_TARGETS:=build_x64 +PUBLISH_TARGETS:=publish_x64 +else ifeq ($(ARCH),arm64v8) +BUILD_TARGETS:=build_arm +PUBLISH_TARGETS:=publish_arm +else ifeq ($(ARCH),) +BUILD_TARGETS:= +PUBLISH_TARGETS:= +endif +# mac else ifeq ($(OS),macos) OS.publish:=darwin ARCH.publish:=x86_64 @@ -21,90 +33,42 @@ endif STEM=libtensorflowlite-$(OS.publish) -DOCKER_OS.bionic=ubuntu:bionic -DOCKER_OS.stretch=debian:stretch-slim -DOCKER_OS.buster=debian:buster-slim -DOCKER_OS=$(DOCKER_OS.$(OSNICK)) - -#---------------------------------------------------------------------------------------------- - -ifeq ($(OS),linux) - -define targets # (1=OP, 2=op) -$(1)_TARGETS := -$(1)_TARGETS += $(if $(findstring $(X64),1),$(2)_x64) -$(1)_TARGETS += $(if $(findstring $(ARM7),1),$(2)_arm32v7) -$(1)_TARGETS += $(if $(findstring $(ARM8),1),$(2)_arm64v8) - -$(1)_TARGETS += $$(if $$(strip $$($(1)_TARGETS)),,$(2)_x64 $(2)_arm32v7 $(2)_arm64v8) -endef - -else ifeq ($(OS),macos) - -define targets # (1=OP, 2=op) -$(1)_TARGETS := $(2)_x64 -endef - -endif - -$(eval $(call targets,BUILD,build)) -$(eval $(call targets,PUBLISH,publish)) - -#---------------------------------------------------------------------------------------------- +# x86 linux ------------------------------------------------------------------------------------------ -define build_x64 # (1=arch, 2=tar-arch) -IID_$(1)=$(1)_$(VERSION).iid -CID_$(1)=$(1)_$(VERSION).cid +IID_X64=$(1)_$(VERSION).iid +CID_X64=$(1)_$(VERSION).cid build_x64: -@rm *.iid *.cid - @docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.x64 $(ROOT) - @docker create --cidfile $$(CID_$(1)) `cat $$(IID_$(1))` + @docker build --iidfile $$(IID_X64) -t redisfab/$(STEM)-x86_64:$(VERSION) -f Dockerfile.x64 --build-arg TFLITE_VERSION=$(VERSION) $(ROOT) + @docker create --cidfile $$(CID_X64) `cat $$(IID_X64)` @docker cp `cat $$(CID_$(1))`:/tflite/tensorflow-$(VERSION)/tmp/libtensorflowlite-linux-x86_x64-$(VERSION).tar.gz . - .PHONY: build_x64 -endef - -define build_arm # (1=arch, 2=tar-arch) -IID_$(1)=$(1)_$(VERSION).iid -CID_$(1)=$(1)_$(VERSION).cid - -build_$(1): - @docker build --iidfile $$(IID_$(1)) -t redisfab/$(STEM)-$(1):$(VERSION) -f Dockerfile.jetson \ - --build-arg ARCH=$(1) $(ROOT) - @docker create --cidfile $$(CID_$(1)) `cat $$(IID_$(1))` - @docker cp `cat $$(CID_$(1))`:/build/$(STEM)-$(2)-$(VERSION).tar.gz . - -.PHONY: build_$(1) -endef - -#---------------------------------------------------------------------------------------------- -define publish_x64 # (1=arch, 2=tar-arch) publish_x64: @aws s3 cp $(STEM)-$(2)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read - .PHONY: publish_x64 -endef -define publish_arm # (1=arch, 2=tar-arch) -publish_$(1): - @aws s3 cp $(STEM)-$(2)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read +# arm linux ------------------------------------------------------------------------------------------ -.PHONY: publish_$(1) -endef +ifeq ($(ARCH),arm64v8) +ARCH.publish:=arm64 +DOCKERBASE=redisfab/ubuntu1804-$(ARCH.publish)-bazel3.1.0-jetson:latest +endif -#---------------------------------------------------------------------------------------------- +build_arm: + @docker run -v `pwd`/opt/build/tflite:/tflite -v /etc/alternatives:/etc/alternatives -v /usr/lib:/usr/lib -v /usr/local:/usr/local -v /usr/include:/usr/include ${DOCKERBASE} /tflite/build.sh $(ARCH.publish) -all: build publish +.PHONY: build_arm -ifeq ($(OS),linux) +publish_arm: + @aws s3 cp tensorflow-$(VERSION)/tmp/$(STEM)-$(ARCH.publish)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read -build: $(BUILD_TARGETS) +.PHONY: publish_arm + +#---------------------------------------------------------------------------------------------- -$(eval $(call build_x64,x64,x86_64)) -$(eval $(call build_arm,arm64v8,arm64)) -$(eval $(call build_arm,arm32v7,arm)) +all: build publish ifneq ($(filter publish,$(MAKECMDGOALS)),) ifeq ($(wildcard $(HOME)/.aws/credentials),) @@ -112,28 +76,10 @@ $(error Please run 'aws configure' and provide it with access credentials) endif endif -publish: $(PUBLISH_TARGETS) - -$(eval $(call publish_x64,x64,x86_64)) -$(eval $(call publish_arm,arm64v8,arm64)) -$(eval $(call publish_arm,arm32v7,arm)) - -help: - @echo "make [build|publish] [X64=1|ARM7=1|ARM8=1]" - -else ifeq ($(OS),macos) - -build: - @VERSION=$(VERSION) ./build.macos - @mv macos/dest/$(STEM)-$(ARCH.publish)-$(VERSION).tar.gz . - -publish: $(PUBLISH_TARGETS) - -$(eval $(call publish_x64,x64,x86_64)) - help: @echo "make [build|publish]" -endif # macos +build: $(BUILD_TARGETS) +publish: $(PUBLISH_TARGETS) .PHONY: all build publish help From c014e7570fa401940241d121f9e2653564c60bbd Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Wed, 21 Apr 2021 14:59:49 +0300 Subject: [PATCH 09/17] adding deps, and docs for backend explanations --- README.md | 4 +++- docs/developer-backends.md | 19 +++++++++++++++++++ docs/developer.md | 2 +- opt/system-setup.py | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 docs/developer-backends.md diff --git a/README.md b/README.md index be448289d..90e2886a2 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ redis-cli ## Building -You should obtain the module's source code and submodule using git like so: +You should obtain the module's source code and submodule using git like so: ```sh git clone --recursive https://github.com/RedisAI/RedisAI @@ -96,6 +96,8 @@ ALL=1 make -C opt clean build Note: in order to use the PyTorch backend on Linux, at least `gcc 4.9.2` is required. +[See this document](docs/developer-backends.md) for building AI backends. + ### Running the server You will need a redis-server version 5.0.7 or greater. This should be diff --git a/docs/developer-backends.md b/docs/developer-backends.md new file mode 100644 index 000000000..7388b9f5d --- /dev/null +++ b/docs/developer-backends.md @@ -0,0 +1,19 @@ +# RedisAI dependency builds + +Platform dependency build systems are located in this folder. Dependencies are to be pre-built, and published to S3. To do so, they rely *(ultimately)* on running **make build publish** in a given directory. The goal is for this to be true on all target platforms (x86_64, arm64), though at this time it's only true for: tensorflowlite. + +## Background + +Items are built in docker images, for the target platform whenever possible. If needed (i.e a future planned MacOS build) items are built on the dedicated hardware. There are design wrinkles to each build. Though the ideal is to build a base docker (see the [automata repository](https://github.com/redislabsmodules/automata). That base docker is then used as the base build system injector for the dependency itself. A docker image is built from the base docker, accepting externalized variables such as the dependency version. Compilation of external requirements takes place in a build file, mounted inside the docker image. + +Ideally a per-platform Docker file (i.e Dockerfile.x64, Dockerfile.arm) will exist in the underlying folder, assuming building within a docker is tenable. + +-------------- + +## tensorflowlite (tflite) + +### arm64 + +The arm build of tflite currently occurs on **jetson arm devices** only, as portions of the root filesystem of the Jetson device are mounted during the build. Given the symlinks that exist on the device between things in /usr/lib to /etc/alternatives, and in turn to /usr/local/cuda, which is itself a symlink to /usr/local/cuda-10.2, this is the current philosophy. + +WThe *build_arm* target in the [Makefile](Makefile) describes the process in detail. The code to build the base docker build image can be found in the [automata repository](https://github.com/RedisLabsModules/automata/tree/master/dockers/buildsystem/bazelbuilder). The *bazelbuilder* image is published to the [redisfab dockerhub repositories](https://hub.docker.com/r/redisfab/). diff --git a/docs/developer.md b/docs/developer.md index feb85e753..aff8e2e9b 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -106,7 +106,7 @@ Within the `backends` folder you will find the implementations code required to * **ONNX**: `onnxruntime.h` and `onnxruntime.c` exporting the functions to to register the ONNXRuntime backend ## Building and Testing -You can compile and build the module from its source code - refer to the [Building and Running section](quickstart.md#building-and-running) of the Quickstart page for instructions on how to do that. +You can compile and build the module from its source code - refer to the [Building and Running section](quickstart.md#building-and-running) of the Quickstart page for instructions on how to do that, or view the detailed instructions on [building backends](developer-backends.md). **Running Tests** diff --git a/opt/system-setup.py b/opt/system-setup.py index a0437a0bb..649768b03 100755 --- a/opt/system-setup.py +++ b/opt/system-setup.py @@ -29,6 +29,7 @@ def debian_compat(self): self.install("libssl-dev") self.install("python3-regex") self.install("python3-psutil python3-networkx python3-numpy") + self.install("libegl1-mesa-dev libgles2-mesa-dev") if self.platform.is_arm(): self.install("python3-dev") # python3-skimage self.install("libmpich-dev libopenblas-dev") # for libtorch From a4e80d2347f5e012f1a422248f82bf4dee5b5437 Mon Sep 17 00:00:00 2001 From: DvirDukhan <dvir@redislabs.com> Date: Wed, 21 Apr 2021 16:29:13 +0300 Subject: [PATCH 10/17] wip --- src/libtflite_c/tflite_c.cpp | 51 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/libtflite_c/tflite_c.cpp b/src/libtflite_c/tflite_c.cpp index ee0e6ffb4..5bd951613 100644 --- a/src/libtflite_c/tflite_c.cpp +++ b/src/libtflite_c/tflite_c.cpp @@ -4,7 +4,7 @@ #include "tensorflow/lite/interpreter.h" #include "tensorflow/lite/kernels/register.h" #include "tensorflow/lite/model.h" -#include "tensorflow/lite/tools/evaluation/utils.h" +#include "tensorflow/lite/delegates/gpu/delegate.h" #include "../redismodule.h" namespace { @@ -204,6 +204,9 @@ struct ModelContext { std::string buffer; DLDeviceType device; int64_t device_id; +#if RAI_TFLITE_USE_CUDA + TfLiteDelegate *delegate; +#endif }; } // namespace @@ -230,16 +233,16 @@ extern "C" void *tfliteLoadModel(const char *graph, size_t graphlen, DLDeviceTyp return NULL; } -#if RAI_TFLITE_USE_CUDA - if (device == DLDeviceType::kDLGPU) { - tflite::Interpreter::TfLiteDelegatePtr delegate = - tflite::evaluation::CreateGPUDelegate(model.get()); - if (interpreter_->ModifyGraphWithDelegate(std::move(delegate)) != kTfLiteOk) { - _setError("Failed to set GPU delegate", error); - return NULL; - } - } -#endif +// #if RAI_TFLITE_USE_CUDA +// if (device == DLDeviceType::kDLGPU) { +// tflite::Interpreter::TfLiteDelegatePtr delegate = +// tflite::evaluation::CreateGPUDelegate(model.get()); +// if (interpreter_->ModifyGraphWithDelegate(std::move(delegate)) != kTfLiteOk) { +// _setError("Failed to set GPU delegate", error); +// return NULL; +// } +// } +// #endif if (interpreter_->AllocateTensors() != kTfLiteOk) { _setError("Failed to allocate tensors", error); @@ -254,7 +257,9 @@ extern "C" void *tfliteLoadModel(const char *graph, size_t graphlen, DLDeviceTyp ctx->model = std::move(model); ctx->interpreter = std::move(interpreter); ctx->buffer = std::move(graphstr); - +#if RAI_TFLITE_USE_CUDA + ctx->delegate = nullptr; +#endif return ctx; } @@ -342,6 +347,19 @@ extern "C" void tfliteRunModel(void *ctx, long n_inputs, DLManagedTensor **input return; } +#if RAI_TFLITE_USE_CUDA + if (ctx_->device == DLDeviceType::kDLGPU) { + if (!ctx_->delegate) { + auto* delegate = TfLiteGpuDelegateV2Create(/*default options=*/nullptr); + if (interpreter->ModifyGraphWithDelegate(delegate) != kTfLiteOk) { + _setError("Failed to set GPU delegate", error); + return; + } + ctx_->delegate = delegate; + } + } +#endif + try { for (size_t i = 0; i < tflite_outputs.size(); i++) { outputs[i] = toManagedDLPack(interpreter, tflite_outputs[i]); @@ -358,7 +376,14 @@ extern "C" void tfliteSerializeModel(void *ctx, char **buffer, size_t *len, char extern "C" void tfliteDeallocContext(void *ctx) { ModelContext *ctx_ = (ModelContext *)ctx; +#if RAI_TFLITE_USE_CUDA + if (ctx_->device == DLDeviceType::kDLGPU) { + if (ctx_->delegate) { + TfLiteGpuDelegateV2Delete(ctx_->delegate); + } + } +#endif if (ctx_) { - delete ctx_; + //delete ctx_; } } From 0f2b9cdd7aa6b25428d2e4cc6103039ccc4feb6a Mon Sep 17 00:00:00 2001 From: Chayim Kirshen <c@kirshen.com> Date: Wed, 21 Apr 2021 17:49:08 +0300 Subject: [PATCH 11/17] [ci skip] --- opt/build/tflite/Makefile | 12 ++++++------ opt/build/tflite/build.sh | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/opt/build/tflite/Makefile b/opt/build/tflite/Makefile index cc88be2d4..998f59605 100755 --- a/opt/build/tflite/Makefile +++ b/opt/build/tflite/Makefile @@ -35,18 +35,18 @@ STEM=libtensorflowlite-$(OS.publish) # x86 linux ------------------------------------------------------------------------------------------ -IID_X64=$(1)_$(VERSION).iid -CID_X64=$(1)_$(VERSION).cid +IID_X64=x86_64_$(VERSION).iid +CID_X64=x86_64_$(VERSION).cid build_x64: -@rm *.iid *.cid - @docker build --iidfile $$(IID_X64) -t redisfab/$(STEM)-x86_64:$(VERSION) -f Dockerfile.x64 --build-arg TFLITE_VERSION=$(VERSION) $(ROOT) - @docker create --cidfile $$(CID_X64) `cat $$(IID_X64)` + @docker build --iidfile $(IID_X64) -t redisfab/$(STEM)-x86_64:$(VERSION) -f Dockerfile.x64 --build-arg TFLITE_VERSION=$(VERSION) $(ROOT) + @docker create --cidfile $(CID_X64) `cat $$(IID_X64)` @docker cp `cat $$(CID_$(1))`:/tflite/tensorflow-$(VERSION)/tmp/libtensorflowlite-linux-x86_x64-$(VERSION).tar.gz . .PHONY: build_x64 publish_x64: - @aws s3 cp $(STEM)-$(2)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read + @aws s3 cp $(STEM)-x86_64-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read .PHONY: publish_x64 # arm linux ------------------------------------------------------------------------------------------ @@ -57,7 +57,7 @@ DOCKERBASE=redisfab/ubuntu1804-$(ARCH.publish)-bazel3.1.0-jetson:latest endif build_arm: - @docker run -v `pwd`/opt/build/tflite:/tflite -v /etc/alternatives:/etc/alternatives -v /usr/lib:/usr/lib -v /usr/local:/usr/local -v /usr/include:/usr/include ${DOCKERBASE} /tflite/build.sh $(ARCH.publish) + @cd ../../../ ; docker run -v `pwd`/opt/build/tflite:/tflite -v /etc/alternatives:/etc/alternatives -v /usr/lib:/usr/lib -v /usr/local:/usr/local -v /usr/include:/usr/include ${DOCKERBASE} /tflite/build.sh $(ARCH.publish) $(VERSION) .PHONY: build_arm diff --git a/opt/build/tflite/build.sh b/opt/build/tflite/build.sh index 6a9a4a7ea..194638808 100755 --- a/opt/build/tflite/build.sh +++ b/opt/build/tflite/build.sh @@ -37,6 +37,7 @@ declare -a tfLiteDirectories=( "$TFLITE_DIR/c" "$TFLITE_DIR/core" "$TFLITE_DIR/core/api" + "$TFLITE_DIR/delegates/gpu" "$TFLITE_DIR/delegates/nnapi" "$TFLITE_DIR/delegates/xnnpack" "$TFLITE_DIR/experimental/resource" @@ -52,8 +53,10 @@ do done mkdir -p $TMP_LIB/lib cp bazel-bin/tensorflow/lite/libtensorflowlite.so $TMP_LIB/lib -bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so +bazel build -c opt --copt -DMESA_EGL_NO_X10_HEADERS --copt -DEGL_NO_X11 tensorflow/lite/delegates/gpu:libtensorflowlite_gpu_delegate.so cp bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so $TMP_LIB/lib + +bazel build --config=monolithic //tensorflow/lite:libtensorflowlite.so # create .tar.gz file cd $TMP_LIB tar -cvzf libtensorflowlite-$BASEOS-$ARCH-$VERSION.tar.gz include lib From 45c3afbd76c86af65c93c492bae3df517faaa6d7 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Wed, 21 Apr 2021 20:16:12 +0300 Subject: [PATCH 12/17] validated final changes, pushed 2.4.1 [ci skip] --- opt/build/tflite/Makefile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/opt/build/tflite/Makefile b/opt/build/tflite/Makefile index 998f59605..4a4ef703a 100755 --- a/opt/build/tflite/Makefile +++ b/opt/build/tflite/Makefile @@ -35,14 +35,11 @@ STEM=libtensorflowlite-$(OS.publish) # x86 linux ------------------------------------------------------------------------------------------ -IID_X64=x86_64_$(VERSION).iid -CID_X64=x86_64_$(VERSION).cid - build_x64: -@rm *.iid *.cid - @docker build --iidfile $(IID_X64) -t redisfab/$(STEM)-x86_64:$(VERSION) -f Dockerfile.x64 --build-arg TFLITE_VERSION=$(VERSION) $(ROOT) - @docker create --cidfile $(CID_X64) `cat $$(IID_X64)` - @docker cp `cat $$(CID_$(1))`:/tflite/tensorflow-$(VERSION)/tmp/libtensorflowlite-linux-x86_x64-$(VERSION).tar.gz . + docker build --iidfile x64.iid -t redisfab/$(STEM)-x86_64:$(VERSION) -f Dockerfile.x64 --build-arg TFLITE_VERSION=$(VERSION) $(ROOT) + docker create --cidfile x64.cid `cat x64.iid` + docker cp `cat x64.cid`:/tflite/tensorflow-$(VERSION)/tmp/$(STEM)-$(ARCH.publish)-$(VERSION).tar.gz . .PHONY: build_x64 publish_x64: @@ -62,7 +59,7 @@ build_arm: .PHONY: build_arm publish_arm: - @aws s3 cp tensorflow-$(VERSION)/tmp/$(STEM)-$(ARCH.publish)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read + @aws s3 cp `pwd`/tensorflow-$(VERSION)/tmp/$(STEM)$(OS)-$(ARCH.publish)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read .PHONY: publish_arm From e47a33dcc8708cb69ee474c02e32a3649086c3ee Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Thu, 22 Apr 2021 10:14:13 +0300 Subject: [PATCH 13/17] [skip ci] cpu and cuda artifacts on both arm64 (jetson) and x64 added an updated and untested get_deps change --- get_deps.sh | 14 ++++++-------- opt/build/tflite/Dockerfile.x64 | 6 +++++- opt/build/tflite/Makefile | 20 ++++++++++++++------ opt/build/tflite/build.sh | 18 +++++++++++++++--- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/get_deps.sh b/get_deps.sh index 4f66cbae1..8e16ec1f6 100755 --- a/get_deps.sh +++ b/get_deps.sh @@ -156,18 +156,16 @@ if [[ $WITH_TFLITE != 0 ]]; then LIBTF_URL_BASE=https://s3.amazonaws.com/redismodules/tensorflow if [[ $OS == linux ]]; then TFLITE_OS="linux" - # if [[ $GPU != 1 ]]; then - # TFLITE_BUILD="cpu" - # else - # TFLITE_BUILD="gpu" - # fi + if [[ $GPU != 1 ]]; then + TFLITE_PLATFORM="cpu" + else + TFLITE_PLATFORM="cuda" + fi if [[ $ARCH == x64 ]]; then TFLITE_ARCH=x86_64 elif [[ $ARCH == arm64v8 ]]; then TFLITE_ARCH=arm64 - elif [[ $ARCH == arm32v7 ]]; then - TFLITE_ARCH=arm fi elif [[ $OS == macos ]]; then TFLITE_OS=darwin @@ -175,7 +173,7 @@ if [[ $WITH_TFLITE != 0 ]]; then TFLITE_ARCH=x86_64 fi - LIBTFLITE_ARCHIVE=libtensorflowlite-${TFLITE_OS}-${TFLITE_ARCH}-${TFLITE_VERSION}.tar.gz + LIBTFLITE_ARCHIVE=libtensorflowlite-${TFLITE_OS}-${TFLITE_PLATFORM}-${TFLITE_ARCH}-${TFLITE_VERSION}.tar.gz [[ ! -f $LIBTFLITE_ARCHIVE || $FORCE == 1 ]] && wget -q $LIBTF_URL_BASE/$LIBTFLITE_ARCHIVE diff --git a/opt/build/tflite/Dockerfile.x64 b/opt/build/tflite/Dockerfile.x64 index a0868782e..89ff73a10 100644 --- a/opt/build/tflite/Dockerfile.x64 +++ b/opt/build/tflite/Dockerfile.x64 @@ -3,6 +3,9 @@ ARG TFLITE_ARCH=x86_64 ARG OS=redisfab/ubuntu1804-${TFLITE_ARCH}-bazel${BAZEL_VERSION} +# cuda | cpu +ARG REDISAI_PLATFORM=cuda + ARG TFLITE_VERSION=2.4.0 #---------------------------------------------------------------------------------------------- @@ -11,6 +14,7 @@ FROM ${OS} ARG FTLITE_VER ARG TFLITE_VERSION ARG TFLITE_ARCH +ARG REDISAI_PLATFORM ADD ./opt/build/tflite /tflite @@ -27,4 +31,4 @@ RUN apt-get install -qqy git \ python3-numpy RUN ln -s /usr/bin/python3 /usr/bin/python WORKDIR /tflite -RUN bash build.sh ${TFLITE_ARCH} ${TFLITE_VERSION} +RUN bash build.sh ${TFLITE_ARCH} ${TFLITE_VERSION} ${REDISAI_PLATFORM} diff --git a/opt/build/tflite/Makefile b/opt/build/tflite/Makefile index 4a4ef703a..704906916 100755 --- a/opt/build/tflite/Makefile +++ b/opt/build/tflite/Makefile @@ -9,6 +9,9 @@ S3_URL=redismodules/tensorflow OS:=$(shell $(ROOT)/opt/readies/bin/platform --os) ARCH:=$(shell $(ROOT)/opt/readies/bin/platform --arch) +# cuda | cpu +REDISAI_PLATFORM=cuda + # non-arm linux ifeq ($(OS),linux) ifeq ($(ARCH),x64) @@ -35,15 +38,19 @@ STEM=libtensorflowlite-$(OS.publish) # x86 linux ------------------------------------------------------------------------------------------ +#IID_X64=x86_64_$(VERSION).iid +#CID_X64=x86_64_$(VERSION).cid +# build_x64: -@rm *.iid *.cid - docker build --iidfile x64.iid -t redisfab/$(STEM)-x86_64:$(VERSION) -f Dockerfile.x64 --build-arg TFLITE_VERSION=$(VERSION) $(ROOT) - docker create --cidfile x64.cid `cat x64.iid` - docker cp `cat x64.cid`:/tflite/tensorflow-$(VERSION)/tmp/$(STEM)-$(ARCH.publish)-$(VERSION).tar.gz . + @docker build --iidfile x64.iid -t redisfab/$(STEM)-x86_64:$(VERSION) -f Dockerfile.x64 \ + --build-arg TFLITE_VERSION=$(VERSION) --build-arg REDISAI_PLATFORM=$(REDISAI_PLATFORM) $(ROOT) + @docker create --cidfile x64.cid `cat x64.iid` + @docker cp `cat x64.cid`:/tflite/tensorflow-$(VERSION)/tmp/libtensorflowlite-linux-$(REDISAI_PLATFORM)-x86_64-$(VERSION).tar.gz . .PHONY: build_x64 publish_x64: - @aws s3 cp $(STEM)-x86_64-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read + @aws s3 cp $(STEM)-$(REDISAI_PLATFORM)-x86_64-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read .PHONY: publish_x64 # arm linux ------------------------------------------------------------------------------------------ @@ -54,12 +61,12 @@ DOCKERBASE=redisfab/ubuntu1804-$(ARCH.publish)-bazel3.1.0-jetson:latest endif build_arm: - @cd ../../../ ; docker run -v `pwd`/opt/build/tflite:/tflite -v /etc/alternatives:/etc/alternatives -v /usr/lib:/usr/lib -v /usr/local:/usr/local -v /usr/include:/usr/include ${DOCKERBASE} /tflite/build.sh $(ARCH.publish) $(VERSION) + @cd ../../../ ; docker run -v `pwd`/opt/build/tflite:/tflite -v /etc/alternatives:/etc/alternatives -v /usr/lib:/usr/lib -v /usr/local:/usr/local -v /usr/include:/usr/include ${DOCKERBASE} /tflite/build.sh $(ARCH.publish) $(VERSION) $(REDISAI_PLATFORM) .PHONY: build_arm publish_arm: - @aws s3 cp `pwd`/tensorflow-$(VERSION)/tmp/$(STEM)$(OS)-$(ARCH.publish)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read + @aws s3 cp `pwd`/tensorflow-$(VERSION)/tmp/$(STEM)$(OS)-$(REDISAI_PLATFORM)-$(ARCH.publish)-$(VERSION).tar.gz s3://$(S3_URL)/ --acl public-read .PHONY: publish_arm @@ -80,3 +87,4 @@ build: $(BUILD_TARGETS) publish: $(PUBLISH_TARGETS) .PHONY: all build publish help + diff --git a/opt/build/tflite/build.sh b/opt/build/tflite/build.sh index 194638808..e55c44178 100755 --- a/opt/build/tflite/build.sh +++ b/opt/build/tflite/build.sh @@ -10,7 +10,13 @@ if [ "X$VERSION" == "X" ]; then VERSION=2.4.0 fi -BASEOS=$3 +# cuda | cpu +REDISAI_TARGET=$3 +if [ "X$REDISAI_TARGET" == "X" ]; then + REDISAI_TARGET="cuda" +fi + +BASEOS=$4 if [ "X$BASEOS" == "X" ]; then BASEOS=linux fi @@ -25,7 +31,12 @@ cd tensorflow-$VERSION ./tensorflow/lite/tools/make/download_dependencies.sh # build tensorflow lite library -bazel build --config=monolithic --config=cuda //tensorflow/lite:libtensorflowlite.so +if [ "X$REDISAI_TARGET" == "cuda" ]; then + BAZEL_VARIANT="--config=cuda" +fi +bazel build --jobs $(nproc) --config=monolithic ${BAZEL_VARIANT} //tensorflow/lite:libtensorflowlite.so +# bazel build --jobs ${nproc} --config=monolithic --config=cuda //tensorflow/lite:libtensorflowlite.so + TMP_LIB="tmp" # flatbuffer header files mkdir -p $TMP_LIB/include @@ -59,4 +70,5 @@ cp bazel-bin/tensorflow/lite/delegates/gpu/libtensorflowlite_gpu_delegate.so $TM bazel build --config=monolithic //tensorflow/lite:libtensorflowlite.so # create .tar.gz file cd $TMP_LIB -tar -cvzf libtensorflowlite-$BASEOS-$ARCH-$VERSION.tar.gz include lib +tar -cvzf libtensorflowlite-${BASEOS}-${REDISAI_TARGET}-${ARCH}-${VERSION}.tar.gz include lib + From 8e8457888725531764ffce8e22b15ecc04567934 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Sun, 25 Apr 2021 12:52:48 +0300 Subject: [PATCH 14/17] [skip ci] deps update for tflite --- get_deps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_deps.sh b/get_deps.sh index 8e16ec1f6..29f56620b 100755 --- a/get_deps.sh +++ b/get_deps.sh @@ -145,7 +145,7 @@ fi # WITH_TF ################################################################################# LIBTFLITE -TFLITE_VERSION="2.4.0" +TFLITE_VERSION="2.4.1" if [[ $WITH_TFLITE != 0 ]]; then [[ $FORCE == 1 ]] && rm -rf $LIBTFLITE From 08610f3870e0f4aa5f77075db2aaaeb0cc878ba3 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Mon, 26 Apr 2021 10:58:53 +0300 Subject: [PATCH 15/17] removing the merge dupe --- src/backends/libtflite_c/tflite_c.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backends/libtflite_c/tflite_c.cpp b/src/backends/libtflite_c/tflite_c.cpp index 01202880e..eb26fb2f9 100644 --- a/src/backends/libtflite_c/tflite_c.cpp +++ b/src/backends/libtflite_c/tflite_c.cpp @@ -7,7 +7,6 @@ #include "tensorflow/lite/kernels/register.h" #include "tensorflow/lite/model.h" #include "tensorflow/lite/delegates/gpu/delegate.h" -#include "../redismodule.h" #include "tensorflow/lite/tools/evaluation/utils.h" namespace { From f4086977e7bc5d0cbebb10607ebf6d416047ff96 Mon Sep 17 00:00:00 2001 From: "Chayim I. Kirshen" <c@kirshen.com> Date: Mon, 26 Apr 2021 15:48:30 +0300 Subject: [PATCH 16/17] restoring bad merge --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 27d63ceef..9bb420537 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,6 +212,8 @@ ENDIF() #---------------------------------------------------------------------------------------------- ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(tests/module) + ADD_LIBRARY(redisai SHARED $<TARGET_OBJECTS:redisai_obj>) TARGET_LINK_LIBRARIES(redisai ${CMAKE_DL_LIBS}) From de5285e40254426da3b6ea53faae4234a6c553fb Mon Sep 17 00:00:00 2001 From: DvirDukhan <dvir@redislabs.com> Date: Mon, 10 May 2021 00:28:23 +0300 Subject: [PATCH 17/17] changed TFLITE device to be env DEVICE. GPU delegate fails to load --- tests/flow/tests_tflite.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/flow/tests_tflite.py b/tests/flow/tests_tflite.py index a10eda36c..49c008630 100644 --- a/tests/flow/tests_tflite.py +++ b/tests/flow/tests_tflite.py @@ -16,14 +16,14 @@ def test_run_tflite_model(env): model_pb = load_file_content('mnist_model_quant.tflite') sample_raw = load_file_content('one.raw') - ret = con.execute_command('AI.MODELSTORE', 'm{1}', 'TFLITE', 'CPU', 'BLOB', model_pb) + ret = con.execute_command('AI.MODELSTORE', 'm{1}', 'TFLITE', DEVICE, 'BLOB', model_pb) env.assertEqual(ret, b'OK') ret = con.execute_command('AI.MODELGET', 'm{1}', 'META') env.assertEqual(len(ret), 14) env.assertEqual(ret[5], b'') - ret = con.execute_command('AI.MODELSTORE', 'm{1}', 'TFLITE', 'CPU', 'TAG', 'asdf', 'BLOB', model_pb) + ret = con.execute_command('AI.MODELSTORE', 'm{1}', 'TFLITE', DEVICE, 'TAG', 'asdf', 'BLOB', model_pb) env.assertEqual(ret, b'OK') ret = con.execute_command('AI.MODELGET', 'm{1}', 'META') @@ -40,7 +40,7 @@ def test_run_tflite_model(env): # TODO: enable me. CI is having issues on GPU asserts of TFLITE and CPU if DEVICE == "CPU": env.assertEqual(ret[1], b'TFLITE') - env.assertEqual(ret[3], b'CPU') + env.assertEqual(ret[3], bDEVICE) con.execute_command('AI.MODELEXECUTE', 'm{1}', 'INPUTS', 1, 'a{1}', 'OUTPUTS', 2, 'b{1}', 'c{1}') values = con.execute_command('AI.TENSORGET', 'b{1}', 'VALUES') @@ -58,17 +58,17 @@ def test_run_tflite_model_errors(env): sample_raw = load_file_content('one.raw') wrong_model_pb = load_file_content('graph.pb') - ret = con.execute_command('AI.MODELSTORE', 'm_2{1}', 'TFLITE', 'CPU', 'BLOB', model_pb) + ret = con.execute_command('AI.MODELSTORE', 'm_2{1}', 'TFLITE', DEVICE, 'BLOB', model_pb) env.assertEqual(ret, b'OK') check_error_message(env, con, "Failed to load model from buffer", - 'AI.MODELSTORE', 'm{1}', 'TFLITE', 'CPU', 'TAG', 'asdf', 'BLOB', wrong_model_pb) + 'AI.MODELSTORE', 'm{1}', 'TFLITE', DEVICE, 'TAG', 'asdf', 'BLOB', wrong_model_pb) # TODO: Autobatch is tricky with TFLITE because TFLITE expects a fixed batch # size. At least we should constrain MINBATCHSIZE according to the # hard-coded dims in the tflite model. check_error_message(env, con, "Auto-batching not supported by the TFLITE backend", - 'AI.MODELSTORE', 'm{1}', 'TFLITE', 'CPU', + 'AI.MODELSTORE', 'm{1}', 'TFLITE', DEVICE, 'BATCHSIZE', 2, 'MINBATCHSIZE', 2, 'BLOB', model_pb) ret = con.execute_command('AI.TENSORSET', 'a{1}', 'FLOAT', 1, 1, 28, 28, 'BLOB', sample_raw) @@ -96,7 +96,7 @@ def test_tflite_modelinfo(env): model_pb = load_file_content('mnist_model_quant.tflite') sample_raw = load_file_content('one.raw') - ret = con.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', 'CPU', 'BLOB', model_pb) + ret = con.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', DEVICE, 'BLOB', model_pb) env.assertEqual(ret, b'OK') ret = con.execute_command('AI.TENSORSET', 'a{1}', 'FLOAT', 1, 1, 28, 28, 'BLOB', sample_raw) @@ -143,7 +143,7 @@ def test_tflite_modelrun_disconnect(env): model_pb = load_file_content('mnist_model_quant.tflite') sample_raw = load_file_content('one.raw') - ret = red.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', 'CPU', 'BLOB', model_pb) + ret = red.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', DEVICE, 'BLOB', model_pb) env.assertEqual(ret, b'OK') ret = red.execute_command('AI.TENSORSET', 'a{1}', 'FLOAT', 1, 1, 28, 28, 'BLOB', sample_raw) @@ -164,7 +164,7 @@ def test_tflite_model_rdb_save_load(env): con = env.getConnection() model_pb = load_file_content('mnist_model_quant.tflite') - ret = con.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', 'CPU', 'BLOB', model_pb) + ret = con.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', DEVICE, 'BLOB', model_pb) env.assertEqual(ret, b'OK') model_serialized_memory = con.execute_command('AI.MODELGET', 'mnist{1}', 'BLOB') @@ -196,7 +196,7 @@ def test_tflite_info(env): model_pb = load_file_content('mnist_model_quant.tflite') - con.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', 'CPU', 'BLOB', model_pb) + con.execute_command('AI.MODELSTORE', 'mnist{1}', 'TFLITE', DEVICE, 'BLOB', model_pb) ret = con.execute_command('AI.INFO') env.assertEqual(8, len(ret))