Commit 3ff86009 by Nick Hynes Committed by Tianqi Chen

Update SGX example (#1879)

parent 11050fda
......@@ -4,7 +4,7 @@ SGX_MODE ?= SIM
DEBUG ?= true
NUM_THREADS ?= 4
TVM_DIR ?= ../..
TVM_DIR ?= $(shell git rev-parse --show-toplevel)
export
......
......@@ -22,7 +22,7 @@ Check out the `/tvm/install/ubuntu_install_sgx.sh` for the commands to get these
If using Docker, start by running
```
git clone https://github.com/dmlc/tvm.git
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
......@@ -31,10 +31,14 @@ cd /mnt
mkdir build && cd build
cmake .. -DUSE_LLVM=ON -DUSE_SGX=/opt/sgxsdk -DRUST_SGX_SDK=/opt/rust-sgx-sdk
make -j4
cd ../apps/sgx
cd ..
pip install -e python -e topi/python -e nnvm/python
cd apps/sgx
```
`bash run_example.sh`
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!`.
......
......@@ -8,8 +8,7 @@ crate-type = ["staticlib"]
[dependencies]
lazy_static = "1.1.0"
# tvm = { path = "../../../rust", default-features = false, features = ["sgx"] }
tvm = { path = "/home/nhynes/myelin/deps/tvm-rs", default-features = false, features = ["sgx"] }
tvm = { path = "../../../rust", default-features = false, features = ["sgx"] }
[profile.release]
lto = true
......
......@@ -13,7 +13,9 @@ else
debug := debug
endif
target/x86_64-unknown-linux-sgx/$(debug)/libmodel-enclave.a: $(build_dir)/libmodel.a **/*
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" \
......@@ -21,11 +23,16 @@ target/x86_64-unknown-linux-sgx/$(debug)/libmodel-enclave.a: $(build_dir)/libmod
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
llvm-ar cr $@ $^
$(AR) cr $@ $^
$(build_dir)/model.o: $(build_dir)/model.bc
clang -c $< -o $@ -fPIC -O3
$(CC) -c $< -o $@ -fPIC -O3
objcopy --globalize-symbol __tvm_module_startup $@
$(build_dir)/model.bc: src/build_model.py
......
......@@ -4,14 +4,10 @@ panic_unwind = {}
panic_abort = {}
[dependencies.std]
path = "/opt/rust-sgx-sdk/xargo/sgx_tstd"
features = ["backtrace", "stdio", "untrusted_time"]
path = "/home/nhynes/myelin/deps/rust-sgx-sdk/xargo/sgx_tstd"
# git = "https://github.com/oasislabs/rust-sgx-sdk"
# rev = "7334c30d85cb1752577998705110b7b27c69b570"
stage = 2
[dependencies.xargo_sgx_rand]
# git = "https://github.com/oasislabs/rust-sgx-sdk"
path = "/home/nhynes/myelin/deps/rust-sgx-sdk/xargo/sgx_rand"
# rev = "7334c30d85cb1752577998705110b7b27c69b570"
path = "/opt/rust-sgx-sdk/xargo/sgx_rand"
stage = 3
<EnclaveConfiguration>
<ProdID>0</ProdID>
<ISVSVN>0</ISVSVN>
<StackMaxSize>0x100000</StackMaxSize>
<HeapMaxSize>0xf0000000</HeapMaxSize>
<StackMaxSize>0x20000</StackMaxSize>
<HeapMaxSize>0x5000000</HeapMaxSize>
<TCSNum>NUM_THREADS</TCSNum>
<TCSPolicy>0</TCSPolicy> <!-- must be "bound" to use thread_local -->
<DisableDebug>0</DisableDebug>
......
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"
{
"arch": "x86_64",
"cpu": "x86-64",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"dynamic-linking": true,
"env": "sgx",
"exe-allocation-crate": "alloc_system",
"executables": true,
"has-elf-tls": true,
"has-rpath": true,
"linker-flavor": "gcc",
"linker-is-gnu": true,
"llvm-target": "x86_64-unknown-linux-gnu",
"max-atomic-width": 64,
"os": "linux",
"position-independent-executables": true,
"pre-link-args": {
"gcc": [
"-Wl,--as-needed",
"-Wl,-z,noexecstack",
"-m64"
]
},
"relro-level": "full",
"stack-probes": true,
"target-c-int-width": "32",
"target-endian": "little",
"target-family": "unix",
"target-pointer-width": "64",
"vendor": "unknown"
}
#!/bin/bash
sgx_sdk=${SGX_SDK:=/opt/sgxsdk}
LD_LIBRARY_PATH="$sgx_sdk/lib64":${LD_LIBRARY_PATH} make
printf "\n"
LD_LIBRARY_PATH="$sgx_sdk/lib64":${LD_LIBRARY_PATH} TVM_CACHE_DIR=/tmp python3 run_model.py
export LD_LIBRARY_PATH="$sgx_sdk/lib64":${LD_LIBRARY_PATH}
export CC=clang-6.0
export AR=llvm-ar-6.0
export TVM_CACHE_DIR=/tmp
make && printf "\n" && python3 run_model.py
......@@ -2,8 +2,8 @@ apt-get update && apt-get install -y --no-install-recommends --force-yes curl
export RUSTUP_HOME=/opt/rust
export CARGO_HOME=/opt/rust
# rustc nightly-2018-08-25 is the version supported by the rust-sgx-sdk
curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain nightly-2018-08-25
# this rustc is one supported by the installed version of rust-sgx-sdk
curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain nightly-2018-09-25
. $CARGO_HOME/env
rustup toolchain add nightly
rustup component add rust-src
......
......@@ -2,18 +2,20 @@ apt-get update && apt-get install -y --no-install-recommends --force-yes \
build-essential git cmake \
wget python pkg-config software-properties-common \
autoconf automake libtool ocaml \
protobuf-compiler libprotobuf-dev \
libssl-dev libcurl4-openssl-dev curl
git clone https://github.com/intel/linux-sgx.git
cd linux-sgx
git checkout sgx_2.2
curl 'https://gist.github.com/nhynes/c770b0e91610f8c020a8d1a803a1e7cb' | git am
curl 'https://gist.githubusercontent.com/nhynes/c770b0e91610f8c020a8d1a803a1e7cb/raw/8f5372d9cb88929b3cc49a384943bb363bc06827/intel-sgx.patch' | git apply
./download_prebuilt.sh
make -j sdk && make -j sdk_install_pkg
./linux/installer/bin/sgx_linux_x64_sdk_2.2.100.45311.bin --prefix /opt
make -j4 sdk && make -j4 sdk_install_pkg
./linux/installer/bin/sgx_linux_x64_sdk*.bin --prefix /opt
cd -
git clone https://github.com/baidu/rust-sgx-sdk.git /opt/rust-sgx-sdk
cd /opt/rust-sgx-sdk
git checkout bdd75ca05f66d1f5df637182ec335970f769b03a
git checkout v1.0.4
curl 'https://gist.githubusercontent.com/nhynes/37164039c5d3f33aa4f123e4ba720036/raw/5b7fc24d4faa0bd6efce19f8324f79d5562991e0/rust-sgx-sdk.diff' | git apply
cd -
......@@ -13,7 +13,6 @@
alloc,
allocator_api,
box_syntax,
extern_prelude,
fn_traits,
try_from,
unboxed_closures,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment