Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rust tests to ci #1

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5bf1cbd
Fix saveload json bug (#1831)
reminisce Oct 6, 2018
3d62cf7
[Relay] More type alpha equality test coverage (#1823)
slyubomirsky Oct 6, 2018
b90620e
[LANG] Generalize compute to tensor region (#1476)
ZihengJiang Oct 6, 2018
eec3648
[RELAY] Add sigmoid relay operator (#1836)
Oct 6, 2018
c286c13
[RELAY][OP] Left shift operator (#1839)
tmoreau89 Oct 6, 2018
0788611
maximum relay op V2 (#1838)
Luo-Liang Oct 6, 2018
3aaafc3
Fix lint error missed during CI outrage (#1846)
tqchen Oct 6, 2018
1bfda4d
[Relay] [Op] zeros_like and ones_like (#1835)
MarisaKirisame Oct 6, 2018
168d4d1
[RELAY][OP] Add relay minimum op (#1840)
Mutinifni Oct 6, 2018
6330797
[DOCKER][GOLANG] Fix golang compiler version to 0.10 (#1848)
srkreddy1238 Oct 6, 2018
5563b72
Add rust runtime (#1597)
nhynes Oct 6, 2018
d8394e8
Update SGX example (#1825)
nhynes Oct 6, 2018
3e52766
[RELAY][PASS] Dead Code Elimination (#1776)
MarisaKirisame Oct 6, 2018
15d67c1
[RELAY] reorg testcase, make checked_type property, fix constructor e…
tqchen Oct 6, 2018
a12b2b1
[SGX] Add ignored files to sgx example (#1852)
nhynes Oct 6, 2018
b313c02
[Rust] Update rust install in dockerfile (#1855)
nhynes Oct 6, 2018
cb2a599
[RELAY] Add softmax (#1841)
merrymercy Oct 7, 2018
710af08
[Relay][Op] concatenate, reshape, transpose, copy (#1847)
junrushao Oct 7, 2018
ea07f74
Update test_op_level1.py
tqchen Oct 7, 2018
f1d815c
Enable bool type as storage type (#1853)
tqchen Oct 7, 2018
9015902
Install rust for all users (#1856)
nhynes Oct 7, 2018
7bafca4
[RELAY][OP] Operators. pool2d, global_pool2d, batch_flatten, tanh,…
srkreddy1238 Oct 7, 2018
4d05fd9
[RELAY][OP]log_softmax op (#1857)
siju-samuel Oct 8, 2018
0f053c8
[Relay][Op] Clip (#1844)
joshpoll Oct 8, 2018
64d3393
add relu (#1849)
MarisaKirisame Oct 9, 2018
b68d9dc
[RELAY][OP] take (#1863)
srkreddy1238 Oct 9, 2018
4e309e6
Allow override gtest library search path (#1867)
wweic Oct 9, 2018
6616355
[Relay] GetItem (#1861)
MarisaKirisame Oct 10, 2018
d7b88f4
Add instructions to run tests locally (#1868)
wweic Oct 11, 2018
6f420e0
[RELAY][OPS]LRN and L2_Normalize (#1860)
siju-samuel Oct 11, 2018
c4ebe6b
[Relay][Op] Add operators full and full_like (#1845)
slyubomirsky Oct 11, 2018
11050fd
Use new onnx API to load model from file (#1874)
apivovarov Oct 11, 2018
3ff8600
Update SGX example (#1879)
nhynes Oct 11, 2018
020b639
[RELAY][OP] conv2d_transpose (#1862)
srkreddy1238 Oct 11, 2018
1eedc94
Update frontend.rst (#1881)
PariksheetPinjari909 Oct 11, 2018
65016b6
[Relay] Alpha equality tests for Relay exprs (#1871)
slyubomirsky Oct 11, 2018
991fb8f
Make rust builds faster
nhynes Oct 7, 2018
b449b94
Add rust to ci
nhynes Oct 6, 2018
0dd8cdf
Make rust test task executable
nhynes Oct 7, 2018
0a3ef8e
Fix pythonpath in rust ci
nhynes Oct 7, 2018
d82f96e
Make /opt/rust world writable for real
nhynes Oct 11, 2018
d425686
Update Jenkinsfile
nhynes Oct 12, 2018
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
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ ENV/
*~
*.pyc
*~
build
config.mk
config.cmake
build_*
Win32
*.dir
perf
Expand Down Expand Up @@ -187,7 +185,6 @@ tvm_u.*
tvm_t.*
# Mac OS X
.DS_Store
build*

# Jetbrain
.idea
Expand All @@ -201,3 +198,11 @@ build*

# tmp file
.nfs*

# keys
*.pem
*.p12
*.pfx
*.cer
*.crt
*.der
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ target_include_directories(
# Tests
set(TEST_EXECS "")
file(GLOB TEST_SRCS tests/cpp/*.cc)
find_library(GTEST_LIB gtest)
find_library(GTEST_LIB gtest "$ENV{GTEST_LIB}")

if(GTEST_LIB)
foreach(__srcpath ${TEST_SRCS})
Expand Down
107 changes: 54 additions & 53 deletions apps/sgx/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Makefile for example to deploy TVM modules in SGX.

TVM_ROOT := $(shell cd ../..; pwd)
NNVM_PATH := nnvm
DMLC_CORE := ${TVM_ROOT}/dmlc-core

SGX_SDK ?= /opt/sgxsdk
RUST_SGX_SDK ?= /opt/rust-sgx-sdk
SGX_MODE ?= SIM
SGX_ARCH ?= x64
SGX_DEBUG ?= 1
DEBUG ?= true
NUM_THREADS ?= 4

TVM_DIR ?= $(shell git rev-parse --show-toplevel)

export

sgx_edger8r := $(SGX_SDK)/bin/x64/sgx_edger8r
sgx_enclave_signer := $(SGX_SDK)/bin/x64/sgx_sign
Expand All @@ -20,69 +19,71 @@ trts_library_name := sgx_trts$(sgx_sim)
tservice_library_name := sgx_tservice$(sgx_sim)
uservice_library_name := sgx_uae_service$(sgx_sim)

pkg_cflags := -std=c++11 -O2 -fPIC\
-I${TVM_ROOT}/include\
-I${DMLC_CORE}/include\
-I${TVM_ROOT}/3rdparty/dlpack/include\
-I.\
-DDMLC_LOG_STACK_TRACE=0\
-fmax-errors=4

pkg_ldflags := -L${TVM_ROOT}/lib

enclave_include_paths := -I$(SGX_SDK)/include\
-I$(SGX_SDK)/include/tlibc\
-I$(SGX_SDK)/include/libcxx\
-I$(SGX_SDK)/include/stdc++\
pkg_cflags := -std=c++11 -fPIC \
-I$(SGX_SDK)/include \
-I$(TVM_DIR)/include \
-I$(TVM_DIR)/dlpack/include \
-I$(TVM_DIR)/dmlc-core/include

pkg_ldflags := -L$(TVM_DIR)/build -ltvm_runtime

ifneq ($(DEBUG), false)
debug := debug
enclave_cflags += -Og -g
pkg_cflags += -Og -g
else
debug := release
enclave_cflags += -O2
pkg_cflags += -O2
endif

enclave_cflags := -static -nostdinc\
-fvisibility=hidden -fpie -fstack-protector-strong\
-ffunction-sections -fdata-sections\
-DDMLC_CXX11_THREAD_LOCAL=0\
-include "lib/tvm_t.h"\
$(enclave_include_paths)\
build_dir := build

enclave_cxxflags := -nostdinc++ $(enclave_cflags) -DTVM_SGX_MAX_CONCURRENCY=4
enclave_cflags := \
-I$(SGX_SDK)/include \
-I$(SGX_SDK)/include/tlibc \
-I$(SGX_SDK)/include/stdport \
-I$(SGX_SDK)/include/epid \
-I$(TVM_DIR)/include \
-I$(TVM_DIR)/dlpack/include \
-I$(TVM_DIR)/dmlc-core/include

enclave_ldflags :=\
-L$(build_dir) -L$(TVM_DIR)/build \
-Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_SDK)/lib64\
-Wl,--whole-archive -l$(trts_library_name) -Wl,--no-whole-archive\
-Wl,--start-group\
-lsgx_tstdc -lsgx_tstdcxx -lsgx_tcxx -lsgx_tcrypto -lsgx_tkey_exchange -l$(tservice_library_name)\
-lenclave -ltvm_t\
-Wl,--end-group\
-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined\
-Wl,-pie,-eenclave_entry -Wl,--export-dynamic\
-Wl,--defsym,__ImageBase=0 -Wl,--gc-sections

.PHONY: clean all
-Wl,--defsym,__ImageBase=0 -Wl,--gc-sections\
-Wl,--version-script=enclave/enclave.lds

all: lib/test_addone.signed.so
.PHONY: enclave clean

# The code library built by TVM
lib/test_addone_sys.o: prepare_test_libs.py
python prepare_test_libs.py
enclave: $(build_dir)/enclave.signed.so

lib/tvm_t.h: ../../src/runtime/sgx/tvm.edl
$(sgx_edger8r) --trusted $< --trusted-dir lib --search-path $(SGX_SDK)/include
mv $@ [email protected]
awk 'NR==4{print "#include <tvm/runtime/c_runtime_api.h>"}1' [email protected] > $@
$(build_dir)/enclave.signed.so: $(build_dir)/enclave.so build/enclave_config.xml enclave/enclave.pem
$(sgx_enclave_signer) sign -key enclave/enclave.pem -enclave $< -out $@ -config build/enclave_config.xml

lib/tvm_t.c: lib/tvm_t.h
enclave/enclave.pem:
curl -sSo $@ 'https://gist.githubusercontent.com/nhynes/8a2d80068a92e672f8b0b7d710ceb404/raw/2d5ae5fbe83198ede49465fdc6535065e093543b/tvm_sgx_demo.pem'

lib/tvm_t.o: lib/tvm_t.c
$(CC) $(enclave_cflags) $(pkg_cflags) -c $< -o $@ -include $(TVM_ROOT)/include/tvm/runtime/c_runtime_api.h
build/enclave_config.xml: enclave/enclave_config.xml.in
cpp $^ -P -o $@ -DNUM_THREADS=$$(( $(NUM_THREADS) + 1 ))

# The enclave library
lib/test_addone.so: $(TVM_ROOT)/src/runtime/sgx/trusted/runtime.cc lib/tvm_t.o lib/test_addone_sys.o
$(CXX) $^ -o $@ $(pkg_cflags) $(pkg_ldflags) $(enclave_cxxflags) $(enclave_ldflags) -g
$(build_dir)/enclave.so: $(build_dir)/libenclave.a $(TVM_DIR)/build/libtvm_t.a
$(CXX) $< -o $@ $(enclave_ldflags) $(enclave_cflags) -ltvm_t

# The demo enclave signing key
lib/enclave.pem:
curl -Lso $@ https://gist.githubusercontent.com/nhynes/8a2d80068a92e672f8b0b7d710ceb404/raw/2d5ae5fbe83198ede49465fdc6535065e093543b/tvm_sgx_demo.pem
$(build_dir)/libenclave.a: enclave/target/x86_64-unknown-linux-sgx/$(debug)/libmodel_enclave.a
@mkdir -p $(@D)
@cp $< $@

# The signed enclave
lib/test_addone.signed.so: lib/test_addone.so enclave_config.xml lib/enclave.pem
$(sgx_enclave_signer) sign -key lib/enclave.pem -enclave $< -out $@ -config enclave_config.xml
enclave/target/x86_64-unknown-linux-sgx/$(debug)/libmodel_enclave.a: enclave/**/*
$(MAKE) -C enclave

clean:
rm -rf lib
$(MAKE) -s -C enclave clean
rm -rf build
37 changes: 32 additions & 5 deletions apps/sgx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,41 @@ This application demonstrates the use of a simple TVM model in the [Intel SGX](h

## Prerequisites

1. The TVM premade Docker image

or

1. A GNU/Linux environment
2. TVM compiled with LLVM and SGX; and the `tvm` Python module
3. The [Linux SGX SDK](https://github.com/intel/linux-sgx) [link to pre-built libraries](https://01.org/intel-software-guard-extensions/downloads)
4. [Rust](https://rustup.sh)
5. The [rust-sgx-sdk](https://github.com/baidu/rust-sgx-sdk)
6. [xargo](https://github.com/japaric/xargo)

Check out the `/tvm/install/ubuntu_install_sgx.sh` for the commands to get these dependencies.

## Running the example

`SGX_SDK=/path/to/sgxsdk bash run_example.sh`
If using Docker, start by running

```
git clone --recursive https://github.com/dmlc/tvm.git
docker run --rm -it -v $(pwd)/tvm:/mnt tvmai/ci-cpu /bin/bash
```
then, in the container
```
cd /mnt
mkdir build && cd build
cmake .. -DUSE_LLVM=ON -DUSE_SGX=/opt/sgxsdk -DRUST_SGX_SDK=/opt/rust-sgx-sdk
make -j4
cd ..
pip install -e python -e topi/python -e nnvm/python
cd apps/sgx
```

Once TVM is build and installed, just

`./run_example.sh`

If everything goes well, you should see a lot of build messages and below them
the text `It works!`.
Expand All @@ -24,10 +52,9 @@ In this library, one can use other libraries like TVM.
Building this example performs the following steps:

1. Creates a simple TVM module that computes `x + 1` and save it as a system library.
2. Builds a minimal TVM runtime pack that can load the module.
3. Links the TVM module into an SGX enclave along with some code that runs the module.
4. Compiles and runs an executable that loads the enclave and calls a function
which invokes the TVM module.
2. Builds a TVM runtime that links the module and allows running it using the TVM Python runtime.
3. Packages the bundle into an SGX enclave
4. Runs the enclave using the usual TVM Python `module` API

For more information on building, please refer to the `Makefile`.
For more information on the TVM module, please refer to `../howto_deploy`.
Expand Down
1 change: 1 addition & 0 deletions apps/sgx/enclave/.rustfmt.toml
15 changes: 15 additions & 0 deletions apps/sgx/enclave/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "model-enclave"
version = "0.1.0"
authors = ["Nick Hynes <[email protected]>"]

[lib]
crate-type = ["staticlib"]

[dependencies]
lazy_static = "1.1.0"
tvm = { path = "../../../rust", default-features = false, features = ["sgx"] }

[profile.release]
lto = true
opt-level = 3
42 changes: 42 additions & 0 deletions apps/sgx/enclave/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
MODEL ?= resnet
NUM_THREADS ?= 4
BATCH_SIZE ?= 64
TRAINING ?= true
DEBUG ?= false

build_dir := ../build

ifeq ($(DEBUG), false)
debug := release
xargo_args := --release
else
debug := debug
endif

target=target/x86_64-unknown-linux-sgx/$(debug)/libmodel-enclave.a

$(target): $(build_dir)/libmodel.a **/* $(TVM_DIR)/rust/patched.txt
RUST_TARGET_PATH=$(shell pwd) \
RUST_TARGET_DIR=$(shell pwd)/target \
RUSTFLAGS="-Z force-unstable-if-unmarked" \
TVM_NUM_THREADS=$(NUM_THREADS) \
BUILD_DIR=../build \
xargo build --target x86_64-unknown-linux-sgx $(xargo_args) -q

$(TVM_DIR)/rust/patched.txt: $(shell pwd)/sgx-deps.diff
echo $(TVM_DIR)
cd $(TVM_DIR) && git apply $<
touch $@

$(build_dir)/libmodel.a: $(build_dir)/model.o
$(AR) cr $@ $^

$(build_dir)/model.o: $(build_dir)/model.bc
$(CC) -c $< -o $@ -fPIC -O3
objcopy --globalize-symbol __tvm_module_startup $@

$(build_dir)/model.bc: src/build_model.py
python3 $< -o $(build_dir)

clean:
xargo clean
13 changes: 13 additions & 0 deletions apps/sgx/enclave/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[dependencies]
alloc = {}
panic_unwind = {}
panic_abort = {}

[dependencies.std]
path = "/opt/rust-sgx-sdk/xargo/sgx_tstd"
features = ["backtrace", "stdio", "untrusted_time"]
stage = 2

[dependencies.xargo_sgx_rand]
path = "/opt/rust-sgx-sdk/xargo/sgx_rand"
stage = 3
9 changes: 9 additions & 0 deletions apps/sgx/enclave/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::env;

fn main() {
println!(
"cargo:rustc-link-search=native={}",
env::var("BUILD_DIR").unwrap()
);
println!("cargo:rustc-link-lib=static=model");
}
9 changes: 9 additions & 0 deletions apps/sgx/enclave/enclave.lds
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enclave.so
{
global:
g_global_data_sim;
g_global_data;
enclave_entry;
local:
*;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<EnclaveConfiguration>
<ProdID>0</ProdID>
<ISVSVN>0</ISVSVN>
<StackMaxSize>0x2000</StackMaxSize>
<HeapMaxSize>0x2000</HeapMaxSize>
<TCSNum>5</TCSNum>
<TCSPolicy>1</TCSPolicy>
<StackMaxSize>0x20000</StackMaxSize>
<HeapMaxSize>0x5000000</HeapMaxSize>
<TCSNum>NUM_THREADS</TCSNum>
<TCSPolicy>0</TCSPolicy> <!-- must be "bound" to use thread_local -->
<DisableDebug>0</DisableDebug>
<MiscSelect>0</MiscSelect>
<MiscMask>0xFFFFFFFF</MiscMask>
Expand Down
13 changes: 13 additions & 0 deletions apps/sgx/enclave/sgx-deps.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 0819e0c7..e56f4ef2 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -14,7 +14,7 @@ default = ["nom/std"]
sgx = ["nom/alloc"]

[dependencies]
-bounded-spsc-queue = "0.4.0"
+bounded-spsc-queue = { git = "https://github.com/nhynes/bounded-spsc-queue", branch = "sgx" }
error-chain = { version = "0.12.0", default-features = false }
itertools = "0.7.8"
lazy_static = "1.1.0"
Loading