Skip to content

Commit 01b9c9e

Browse files
nhynestqchen
authored andcommitted
[SGX] Add ignored files to sgx example (apache#1852)
1 parent f7b0693 commit 01b9c9e

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

Diff for: apps/sgx/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ Check out the `/tvm/install/ubuntu_install_sgx.sh` for the commands to get these
1919

2020
## Running the example
2121

22+
If using Docker, start by running
23+
24+
```
25+
git clone https://github.com/dmlc/tvm.git
26+
docker run --rm -it -v $(pwd)/tvm:/mnt tvmai/ci-cpu /bin/bash
27+
```
28+
then, in the container
29+
```
30+
cd /mnt
31+
mkdir build && cd build
32+
cmake .. -DUSE_LLVM=ON -DUSE_SGX=/opt/sgxsdk -DRUST_SGX_SDK=/opt/rust-sgx-sdk
33+
make -j4
34+
cd ../apps/sgx
35+
```
36+
2237
`bash run_example.sh`
2338

2439
If everything goes well, you should see a lot of build messages and below them

Diff for: apps/sgx/enclave/build.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::env;
2+
3+
fn main() {
4+
println!(
5+
"cargo:rustc-link-search=native={}",
6+
env::var("BUILD_DIR").unwrap()
7+
);
8+
println!("cargo:rustc-link-lib=static=model");
9+
}

Diff for: apps/sgx/enclave/src/build_model.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Creates a simple TVM modules."""
2+
3+
import argparse
4+
import os
5+
from os import path as osp
6+
7+
import nnvm.compiler
8+
import nnvm.testing
9+
import tvm
10+
11+
12+
def main():
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument('-o', '--out-dir', default='.')
15+
opts = parser.parse_args()
16+
17+
# from tutorials/nnvm_quick_start.py
18+
dshape = (1, 3, 224, 224)
19+
net, params = nnvm.testing.resnet.get_workload(
20+
layers=18, batch_size=dshape[0], image_shape=dshape[1:])
21+
22+
with nnvm.compiler.build_config(opt_level=3):
23+
graph, lib, params = nnvm.compiler.build(
24+
net, 'llvm --system-lib', shape={'data': dshape}, params=params)
25+
26+
build_dir = osp.abspath(opts.out_dir)
27+
if not osp.isdir(build_dir):
28+
os.makedirs(build_dir, exist_ok=True)
29+
30+
lib.save(osp.join(build_dir, 'model.bc'))
31+
with open(osp.join(build_dir, 'graph.json'), 'w') as f_graph_json:
32+
f_graph_json.write(graph.json())
33+
with open(osp.join(build_dir, 'params.bin'), 'wb') as f_params:
34+
f_params.write(nnvm.compiler.save_param_dict(params))
35+
36+
37+
if __name__ == '__main__':
38+
main()

0 commit comments

Comments
 (0)