Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tflite x64
  • Loading branch information
chayim committed Apr 18, 2021
commit e80fe1084d4e9545939022232360fed8a87ef313
22 changes: 16 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -321,4 +331,4 @@ if(PACKAGE_UNIT_TESTS)
enable_testing()
include(GoogleTest)
add_subdirectory(tests/unit)
endif()
endif()
18 changes: 9 additions & 9 deletions get_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand All @@ -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"
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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."
Expand Down
15 changes: 8 additions & 7 deletions opt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand All @@ -97,7 +97,7 @@ DEPS_FLAGS += CPU=1
DEVICE=cpu
endif

#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------

SRCDIR=..
BINDIR=$(BINROOT)/src
Expand All @@ -110,7 +110,7 @@ INSTALLED_TARGET=$(INSTALL_DIR)/redisai.so

BACKENDS_PATH ?= $(INSTALL_DIR)/backends

#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------

CMAKE_FILES += \
$(SRCDIR)/CMakeLists.txt \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -190,7 +191,7 @@ else
-$(SHOW)$(MAKE) -C $(BINDIR) clean
endif

#----------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------

setup:
@echo Setting up system...
Expand Down
48 changes: 25 additions & 23 deletions opt/build/tflite/Dockerfile.x64
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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}
10 changes: 5 additions & 5 deletions opt/build/tflite/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

ROOT=../../..

export VERSION ?= 2.0.0
export VERSION ?= 2.4.0
OSNICK ?= buster

#----------------------------------------------------------------------------------------------
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions opt/build/tflite/build

This file was deleted.

12 changes: 0 additions & 12 deletions opt/build/tflite/build.macos

This file was deleted.

20 changes: 14 additions & 6 deletions opt/build/tflite/new_build.sh → opt/build/tflite/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 .
tar -cvzf libtensorflowlite-linux-$ARCH-$VERSION.tar.gz include lib
Loading