Skip to content

Commit 7118bdf

Browse files
committed
Allow building SGX modules
1 parent 2c7117c commit 7118bdf

15 files changed

+1124
-200
lines changed

rust/.rustfmt.toml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
max_width = 100
22
hard_tabs = false
33
tab_spaces = 2
4-
newline_style = "Unix"
5-
use_small_heuristics = true
4+
newline_style = "Auto"
5+
use_small_heuristics = "Default"
66
indent_style = "Block"
77
wrap_comments = false
88
comment_width = 80
99
normalize_comments = false
10-
format_strings = true
10+
format_strings = false
11+
format_macro_matchers = false
12+
format_macro_bodies = true
1113
empty_item_single_line = true
1214
struct_lit_single_line = true
1315
fn_single_line = false
@@ -22,9 +24,8 @@ type_punctuation_density = "Wide"
2224
space_before_colon = false
2325
space_after_colon = true
2426
spaces_around_ranges = false
25-
spaces_within_parens_and_brackets = false
2627
binop_separator = "Front"
27-
remove_blank_lines_at_start_or_end_of_block = true
28+
remove_nested_parens = true
2829
combine_control_expr = true
2930
struct_field_align_threshold = 0
3031
match_arm_blocks = true
@@ -37,21 +38,22 @@ trailing_comma = "Vertical"
3738
match_block_trailing_comma = false
3839
blank_lines_upper_bound = 1
3940
blank_lines_lower_bound = 0
41+
edition = "Edition2015"
4042
merge_derives = true
4143
use_try_shorthand = true
42-
condense_wildcard_suffixes = true
43-
force_explicit_abi = true
4444
use_field_init_shorthand = false
45-
write_mode = "Overwrite"
45+
force_explicit_abi = true
46+
condense_wildcard_suffixes = false
4647
color = "Auto"
47-
required_version = "0.6.1"
48+
required_version = "0.99.4"
4849
unstable_features = false
4950
disable_all_formatting = false
5051
skip_children = false
5152
hide_parse_errors = false
52-
error_on_line_overflow = true
53-
error_on_unformatted = true
53+
error_on_line_overflow = false
54+
error_on_unformatted = false
5455
report_todo = "Never"
5556
report_fixme = "Never"
5657
ignore = []
57-
verbose_diff = false
58+
emit_mode = "Files"
59+
make_backup = false

rust/Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@ name = "tvm"
33
version = "0.1.0"
44
license = "Apache-2.0"
55
description = "TVM Rust runtime"
6-
repository = "https://github.com/nhynes/tvm-rs"
6+
repository = "https://github.com/dmlc/tvm"
77
readme = "README.md"
88
keywords = ["tvm", "nnvm"]
99
categories = ["api-bindings", "science"]
1010
authors = ["Nick Hynes <[email protected]>"]
1111

1212
[features]
13-
par-launch-alloc = []
13+
default = ["nom/std"]
14+
sgx = ["nom/alloc"]
1415

1516
[dependencies]
1617
bounded-spsc-queue = "0.4.0"
1718
error-chain = { version = "0.12.0", default-features = false }
1819
itertools = "0.7.8"
19-
lazy_static = "1.0.0"
20+
lazy_static = "1.1.0"
2021
ndarray = "0.11.2"
21-
nom = "4.0.0"
22+
nom = {version = "4.0.0", default-features = false }
2223
serde = "1.0.59"
23-
serde_derive = "1.0.59"
24+
serde_derive = "1.0.79"
2425
serde_json = "1.0.17"
2526

2627
[target.'cfg(not(target_env = "sgx"))'.dependencies]
2728
num_cpus = "1.8.0"
28-
29-
[build-dependencies]
30-
bindgen = "0.37"

rust/build.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.

rust/src/errors.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use std::{alloc, num};
1+
#[cfg(target_env = "sgx")]
2+
use alloc::alloc;
3+
#[cfg(not(target_env = "sgx"))]
4+
use std::alloc;
5+
use std::num;
26

37
use ndarray;
48
use serde_json;
@@ -22,9 +26,14 @@ error_chain! {
2226
}
2327
foreign_links {
2428
Alloc(alloc::AllocErr);
25-
Layout(alloc::LayoutErr);
2629
GraphDeserialize(serde_json::Error);
2730
ParseInt(num::ParseIntError);
2831
ShapeError(ndarray::ShapeError);
2932
}
3033
}
34+
35+
impl From<alloc::LayoutErr> for Error {
36+
fn from(_err: alloc::LayoutErr) -> Error {
37+
Error::from_kind(ErrorKind::Msg("Layout error".to_string()))
38+
}
39+
}

rust/src/lib.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
#![feature(allocator_api, box_syntax, fn_traits, try_from, unboxed_closures)]
1+
#![feature(
2+
alloc,
3+
allocator_api,
4+
box_syntax,
5+
extern_prelude,
6+
fn_traits,
7+
try_from,
8+
unboxed_closures,
9+
vec_remove_item
10+
)]
211

12+
#[cfg(target_env = "sgx")]
13+
extern crate alloc;
314
extern crate bounded_spsc_queue;
15+
#[cfg(target_env = "sgx")]
16+
extern crate core;
417
#[macro_use]
518
extern crate error_chain;
619
#[macro_use]
@@ -18,12 +31,20 @@ extern crate serde_derive;
1831
extern crate serde_json;
1932

2033
pub mod ffi {
21-
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals, unused)]
34+
#![allow(
35+
non_camel_case_types,
36+
non_snake_case,
37+
non_upper_case_globals,
38+
unused
39+
)]
2240

2341
pub mod runtime {
2442
use std::os::raw::{c_char, c_int, c_void};
2543

26-
include!(concat!(env!("OUT_DIR"), "/c_runtime_api.rs"));
44+
include!(concat!(
45+
env!("CARGO_MANIFEST_DIR"),
46+
"/src/runtime/c_runtime_api.rs"
47+
));
2748

2849
pub type BackendPackedCFunc =
2950
extern "C" fn(args: *const TVMValue, type_codes: *const c_int, num_args: c_int) -> c_int;

rust/src/runtime/allocator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(target_env = "sgx")]
2+
use alloc::alloc::{self, Layout};
3+
#[cfg(not(target_env = "sgx"))]
14
use std::alloc::{self, Layout};
25

36
use errors::*;

rust/src/runtime/array.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::{
33
convert::TryFrom,
44
mem,
55
os::raw::{c_int, c_void},
6-
ptr,
7-
slice,
6+
ptr, slice,
87
};
98

109
use ndarray;
@@ -172,8 +171,7 @@ impl<'a> Tensor<'a> {
172171
expected_stride * (*shape as usize),
173172
)
174173
},
175-
)
176-
.0
174+
).0
177175
}
178176
}
179177
}
@@ -254,7 +252,11 @@ macro_rules! impl_ndarray_try_from_tensor {
254252
tensor.dtype
255253
);
256254
Ok(ndarray::Array::from_shape_vec(
257-
tensor.shape.iter().map(|s| *s as usize).collect::<Vec<usize>>(),
255+
tensor
256+
.shape
257+
.iter()
258+
.map(|s| *s as usize)
259+
.collect::<Vec<usize>>(),
258260
tensor.to_vec::<$type>(),
259261
)?)
260262
}
@@ -347,12 +349,12 @@ macro_rules! make_dtype_const {
347349
bits: $bits,
348350
lanes: $lanes,
349351
};
350-
}
352+
};
351353
}
352354

353355
make_dtype_const!(DTYPE_INT32, DLDataTypeCode_kDLInt, 32, 1);
354356
make_dtype_const!(DTYPE_UINT32, DLDataTypeCode_kDLUInt, 32, 1);
355-
make_dtype_const!(DTYPE_FLOAT16, DLDataTypeCode_kDLFloat, 16, 1);
357+
// make_dtype_const!(DTYPE_FLOAT16, DLDataTypeCode_kDLFloat, 16, 1);
356358
make_dtype_const!(DTYPE_FLOAT32, DLDataTypeCode_kDLFloat, 32, 1);
357359
make_dtype_const!(DTYPE_FLOAT64, DLDataTypeCode_kDLFloat, 64, 1);
358360

0 commit comments

Comments
 (0)