Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6c2ff5f
Makefile: added pack and test targets
rafie Jul 30, 2019
70736cc
Added deps/readies and system-setup.py
rafie Jul 31, 2019
b5c47be
Fixed docker functionality, fixed tests, setup changes
rafie Jul 31, 2019
dc3c06d
CircleCI: refactoring
rafie Jul 31, 2019
01fa83f
CircleCI: refactoring #2
rafie Jul 31, 2019
f019e7c
CircleCI: github ssh keys for git lfs
rafie Jul 31, 2019
d8a3f04
CircleCI: revert to old image
rafie Jul 31, 2019
9d8e775
CircleCI: disabled cache restore
rafie Jul 31, 2019
aa3f03a
CircleCI: added sudo
rafie Jul 31, 2019
602d990
CircleCI: fixed git lfs handling
rafie Aug 1, 2019
7b36716
CircleCI: try redis:5.0.5-buster image once again
rafie Aug 1, 2019
bd95c70
CircleCI: so maybe python:3.7.4-buster
rafie Aug 1, 2019
1ad534c
Moved Paella to Python 3, bumped version to 0.3.2
rafie Aug 5, 2019
94db1a8
Merge branch 'rafi-pack2' of ssh://github.com/RedisAI/RedisAI into ra…
rafie Aug 5, 2019
34e788a
Added getpy to readies/paella
rafie Aug 5, 2019
34713c9
Build fix #1
rafie Aug 5, 2019
2bdc9d9
Merge remote-tracking branch 'origin/master' into rafi-pack2
rafie Aug 5, 2019
9022159
Build fix #2
rafie Aug 5, 2019
70afcd6
Dockerfile sh syntax, DEBUG flag in Makefile
rafie Aug 5, 2019
ea8d2bc
system-setup: added popen.communicate()
rafie Aug 7, 2019
1be1bfb
Merge remote-tracking branch 'origin/master' into rafi-pack2
rafie Aug 7, 2019
04e6cff
Build: better cpu/gpu separation
rafie Aug 11, 2019
521bcd2
Docker fixes
rafie Aug 11, 2019
3e1f757
Build fix #3
rafie Aug 11, 2019
0f8d2ee
Build fix #4
rafie Aug 11, 2019
923bb76
Fixes from review, updated README
rafie Aug 15, 2019
a2fc02d
Fixes from review #2
rafie Aug 16, 2019
0250daa
Fixes from review #3
rafie Aug 16, 2019
4b1f91f
Fixes from review #4
rafie Aug 16, 2019
ff16afa
Fixes from review #5
rafie Aug 16, 2019
4b03775
Fixes from review #6
rafie Aug 16, 2019
ba62dfd
Fixes from review #7
rafie Aug 16, 2019
50e6770
CircleCI cache hacking
rafie Aug 16, 2019
5a99f14
Merge remote-tracking branch 'origin/master' into rafi-pack2
rafie Aug 16, 2019
d24b7d3
CircleCI cache: cancelled fallback
rafie Aug 16, 2019
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
40 changes: 10 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2
version: 2.1
jobs:
build:
docker:
- image: circleci/python:3.6.8
- image: circleci/python:3.7.4-buster

steps:
- checkout
Expand All @@ -17,16 +17,9 @@ jobs:
- run:
name: install dependencies
command: |
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install -y git-lfs patchelf
git lfs install
curl -o cmake-3.12.4-Linux-x86_64.sh https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh
mkdir /home/circleci/project/cmake-bin
sh cmake-3.12.4-Linux-x86_64.sh --prefix=/home/circleci/project/cmake-bin --skip-license
sudo ln -s /home/circleci/project/cmake-bin/bin/cmake /usr/local/bin/cmake
echo `cmake --version`
rm -rf /home/circleci/project/deps
bash get_deps.sh cpu
sudo ./deps/readies/bin/getpy
sudo ./system-setup.py
make deps
git clone git://github.com/antirez/redis.git --branch 5.0.3
(cd redis && make malloc=libc -j4 && sudo make install)

Expand All @@ -38,32 +31,19 @@ jobs:
- run:
name: Build
command: |
rm -rf build
mkdir build
cd build
cmake -DDEPS_PATH=../deps/install ..
make && make install
cd ..
make rlec_runpath_fix
make all
make pack

- run:
name: Test
command: |
python3 -m venv venv
. venv/bin/activate
pip -q uninstall -y RLTest || true
pip -q install git+https://github.com/RedisLabsModules/RLTest@py3
pip -q install -r test/test_requirements.txt
git lfs pull
python3 -m RLTest --test test/basic_tests.py --module install/redisai.so
command: make test

- run:
name: Persist Artifacts
command: |
mkdir -p ~/workspace/build
cp install/ramp/$MODULE_ARTIFACT ~/workspace/
# cp deps/install/lib/*.so* ~/workspace/
cp -r install/backends ~/workspace/
cp install-cpu/$MODULE_ARTIFACT ~/workspace/
cp -r install-cpu/backends ~/workspace/
cp ramp.yml ~/workspace/
- persist_to_workspace:
root: ~/workspace
Expand Down
11 changes: 8 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
deps/*
install/*
/deps/*
!/deps/readies/
!/deps/*.py
/build/
/install/
**/*.o
**/*.so
**/*.so
/.venv/
/venv/
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ __pycache__
*.pyc

# Dirs
install/
deps/
build/
/install/
/deps/*
!/deps/readies/
!/deps/*.py
/build/
examples/js/node_modules/
examples/js/package-lock.json
/test/venv/
/test/logs/
/1/
/venv/
/.venv/

# Eclipse (if that's your jam...)
.project
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ GET_FILENAME_COMPONENT(depsAbs
"${DEPS_PATH}" REALPATH
BASE_DIR "${CMAKE_BINARY_DIR}")

# SET(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda-9.0)

INCLUDE_DIRECTORIES(${depsAbs}/dlpack/include)
INCLUDE_DIRECTORIES(${depsAbs}/libtensorflow/include)
INCLUDE_DIRECTORIES(${depsAbs}/libtorch/include)
Expand Down Expand Up @@ -68,7 +70,7 @@ IF (APPLE)
LINK_FLAGS "-undefined dynamic_lookup")
ENDIF()

SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install-${ENGINE})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with having separate install-cpu and install-gpu. The redisai.so module is independent on the device, only the backends depend on devices. We must make it possible to have multiple backends at the same time (I know this isn't the case for Enterprise, but we need to make this possible for OSS), we need to differentiate devices at the backends level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right.
Actually, I was planning of having the "install" dir live inside bin/arch-os-variant, with "variant" reflecting the device as well.
Another issue: it appears cmake insists on installing every last device dependency for each and every build, which is pretty time consuming (and will be even worse with gpu devices). We probably need to do something about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rafie, thanks for the replies. I'll get to the others asap (working on updating to ONNXRuntime 0.5 atm).
However, I'd like to comment on this:

Actually, I was planning of having the "install" dir live inside bin/arch-os-variant, with "variant" reflecting the device as well.

What I meant is that redisai.so must not be tied to a device, because it does not depend on devices. Only backends have a concept of devices. So redisai.so should not be contained in a directory with variant in it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now realize I should have given a better description of the variant concept.
A variant is part of the os-arch-variant triplet, and it describes an arbitrary attribute (actually, a set of attributes) of a build environment. The most natural variant is release/debug. So in practice, a variant should reflect a configuration of the build environment that reflects the actual build of source files, so their corresponding object files will be properly grouped and will not mix.
More examples of variants are some sort of code instrumentation, or a set of C macros that are turned on in a specific build.
Another thing to notice in that a certain variant may apply for one source module and not apply for another (in order not to create superfluous build process).
In our case, CPU/GPU may or may not be part of a build variant. This is determined solely by their projection on different modules: projection on main redisai may be none, while projection on backend adapters may exist.
Anyways, those projections are to be reflected in the build system, so location of each product (.so) is determined according to their dependencies. All we need to do is to expose those dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification, I didn't get it at first.


INSTALL(TARGETS redisai LIBRARY DESTINATION .)

Expand Down
62 changes: 29 additions & 33 deletions Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
FROM redis AS builder
ARG OS=debian:buster

ENV DEPS "build-essential git ca-certificates curl unzip wget libgomp1 patchelf"
#----------------------------------------------------------------------------------------------
FROM redis AS redis
FROM ${OS} AS builder

# install latest cmake
ADD https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.sh /cmake-3.12.4-Linux-x86_64.sh
RUN mkdir /opt/cmake
RUN sh /cmake-3.12.4-Linux-x86_64.sh --prefix=/opt/cmake --skip-license
RUN ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
RUN cmake --version
ARG PACK=0
ARG TEST=0

# Set up a build environment
RUN set -ex;\
deps="$DEPS";\
apt-get update;\
apt-get install -y --no-install-recommends $deps

# Get the dependencies
WORKDIR /redisai
COPY --from=redis /usr/local/ /usr/local/

COPY ./deps/readies/ deps/readies/
COPY ./system-setup.py .
COPY ./test/test_requirements.txt test/

RUN ./deps/readies/bin/getpy
RUN ./system-setup.py

COPY ./get_deps.sh .
RUN ./get_deps.sh cpu

ADD ./ /redisai
RUN set -ex;\
mkdir -p deps;\
DEPS_DIRECTORY=deps bash ./get_deps.sh cpu

# Build the source
RUN set -ex;\
rm -rf build;\
mkdir -p build;\
cd build;\
cmake -DDEPS_PATH=../deps/install ..;\
make && make install;\
cd ..

# Package the runner
RUN make all
RUN if [ "$PACK" = "1" ]; then make pack; fi
RUN if [ "$TEST" = "1" ]; then make test; fi

#----------------------------------------------------------------------------------------------
FROM redis

RUN set -e; apt-get -qq update; apt-get install -y libgomp1

RUN set -ex;\
mkdir -p /usr/lib/redis/modules/;
RUN mkdir -p /usr/lib/redis/modules/

COPY --from=builder /redisai/install/ /usr/lib/redis/modules/
COPY --from=builder /redisai/install-cpu/ /usr/lib/redis/modules/

WORKDIR /data
EXPOSE 6379
CMD ["--loadmodule", "/usr/lib/redis/modules/redisai.so"]
CMD ["--loadmodule", "/usr/lib/redis/modules/redisai.so", \
"TF", "/usr/lib/redis/modules//backends/redisai_tensorflow/redisai_tensorflow.so", \
"TORCH", "/usr/lib/redis/modules//backends/redisai_torch/redisai_torch.so", \
"ONNX", "/usr/lib/redis/modules//backends/redisai_onnxruntime/redisai_onnxruntime.so"]
88 changes: 56 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
override GPU:=$(or $(findstring $(CUDA),1),$(findstring $(GPU),1))

ifeq ($(CUDA),1)
DEPS_FLAGS=
ifeq ($(GPU),1)
ifeq ($(CPU),1)
$(error CPU=1 and GPU=1 (or CUDA=1) are conflicting)
endif
DEPS_FLAGS=gpu
ENGINE=gpu
else
DEPS_FLAGS=cpu
ENGINE=cpu
endif

export REDIS_ENT_LIB_PATH=/opt/redislabs/lib
Expand All @@ -16,52 +22,70 @@ else
PACK_VER:=$(VERSION)
endif

BINDIR=$(PWD)/install
BINDIR=$(PWD)/install-$(ENGINE)

BACKENDS_PATH ?= $(BINDIR)/backends

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

setup:
@echo Setting up system...
$(SHOW)./deps/readies/bin/getpy
$(SHOW)./system-setup.py

.PHONY: all setup build clean deps pack pack_ramp pack_deps test

all: build

.PHONY: all clean deps pack rlec_runpath_fix
ifeq ($(DEBUG),1)
CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug
endif

all:
ifeq ($(wildcard build/.),)
build:
ifeq ($(wildcard build/Makefile),)
mkdir -p build
cd build; \
cmake -DDEPS_PATH=../deps/install ..
cmake -DENGINE=$(ENGINE) -DDEPS_PATH=../deps/install-$(ENGINE) $(CMAKE_FLAGS) ..
endif
$(MAKE) -C build && $(MAKE) -C build install
$(MAKE) -C build
$(MAKE) -C build install

clean:
ifeq ($(ALL),1)
rm -rf build deps
rm -rf build install deps/dlpack deps/install-$(ENGINE) deps/*.tar.gz deps/*.zip deps/*.tgz
else
$(MAKE) -C build clean
endif

deps:
deps fetch:
@echo Fetching dependencies...
@./get_deps.sh $(DEPS_FLAGS)

# in pack: create ramp/redisai.so with RUNPATH set to /opt/redislabs/lib for RLEC compliance
rlec_runpath_fix:
@echo Fixing RLEC RUNPATH...
@mkdir -p $(BINDIR)/ramp
@cp -f $(BINDIR)/redisai.so $(BINDIR)/ramp/
# @patchelf --set-rpath $(REDIS_ENT_LIB_PATH) $(BINDIR)/ramp/redisai.so
pack: pack_ramp pack_deps

pack: rlec_runpath_fix
pack_ramp:
@[ ! -z `command -v redis-server` ] || { echo "Cannot find redis-server - aborting."; exit 1; }
@[ ! -e $(REDIS_ENT_LIB_PATH) ] || { echo "$(REDIS_ENT_LIB_PATH) exists - aborting."; exit 1; }
ifeq ($(wildcard build/pyenv/.),)
@virtualenv build/pyenv ;\
. ./build/pyenv/bin/activate ;\
pip install git+https://github.com/RedisLabs/RAMP
endif
@echo "Building RAMP file ..."
@set -e ;\
. ./build/pyenv/bin/activate ;\
ln -fs $(PWD)/deps/install/lib/ $(REDIS_ENT_LIB_PATH) ;\
ramp pack -m $(PWD)/ramp.yml -o "build/redisai.{os}-{architecture}.${PACK_VER}.zip" $(BINDIR)/ramp/redisai.so 2>&1 > /dev/null ;\
rm $(REDIS_ENT_LIB_PATH)
@echo Done.
@echo "Building dependencies file redisai-dependencies.${PACK_VER}.tgz ..."
@cd deps/install/lib; \
tar pczf ../../../build/redisai-dependencies.${PACK_VER}.tgz *.so*
@echo Done.
RAMPOUT=$$(mktemp /tmp/ramp.XXXXXX) ;\
LD_LIBRARY_PATH=$(PWD)/deps/install-$(ENGINE)/lib \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this anymore with the RUNPATH changes.

ramp pack -m $(PWD)/ramp.yml -o "build/redisai.{os}-{architecture}.{semantic_version}.zip" $(BINDIR)/redisai.so 2> /dev/null | grep '.zip' > $$RAMPOUT ;\
tail -1 $$RAMPOUT > $(BINDIR)/PACKAGE ;\
rm -f $RAMPOUT ;\
echo "Done."

pack_deps: pack_ramp
@echo "Building dependencies file ..."
@set -e ;\
PACK_FNAME=$$(basename `cat $(BINDIR)/PACKAGE`) ;\
ARCHOSVER=$$(echo "$$PACK_FNAME" | sed -e "s/^redisai\.\([^.]*\..*\)\.zip/\1/") ;\
cd install-$(ENGINE) ;\
find backends -name "*.so*" | xargs tar pczf redisai-dependencies.$$ARCHOSVER-$(ENGINE).tgz ;\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct that we are going to have a redisai-dependencies...tgz that is specific for the ENGINE?

Just to make sure: only backends (redisai_torch.so, etc) need an ENGINE specified, not redisai.so.

Does the above mean that we'll have two tgz, one in which all backends are cpu and one in which all backends are gpu?

echo "Done."

test:
@git lfs install
@git lfs pull
@set -e ;\
cd test ;\
python3 -m RLTest $(TEST_ARGS) --test basic_tests.py --module $(BINDIR)/redisai.so
36 changes: 36 additions & 0 deletions deps/readies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Object files
*.o
*.ko
*.obj
*.elf
*.lib
*.a
*.la
*.lo
*.dll
*.so
*.so.*
*.dylib
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# C/C++
*.gch
*.pch
*.d

# Python
*.pyc

# CMake
CMakeFiles/
*.cmake
CMakeCache.txt

# Eclipse
.cproject
.project
29 changes: 29 additions & 0 deletions deps/readies/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2019, Redis Labs Modules
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 changes: 9 additions & 0 deletions deps/readies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Library cluster of common Redis Modules code

Cetara: C/C++

Paella: Python

Shibumi: Bash

mk: GNU Make
Loading