Skip to content

Commit 53e3120

Browse files
nhynestqchen
authored andcommitted
Update SGX cmake (#1763)
1 parent 046a3ed commit 53e3120

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ cat.jpg
182182
docs.tgz
183183
cat.png
184184
*.mlmodel
185+
tvm_u.*
185186
# Mac OS X
186187
.DS_Store
187188
build*

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tvm_option(USE_LLVM "Build with LLVM, can be set to specific llvm-config path" O
3232
tvm_option(USE_STACKVM_RUNTIME "Include stackvm into the runtime" OFF)
3333
tvm_option(USE_GRAPH_RUNTIME "Build with tiny graph runtime" ON)
3434
tvm_option(USE_GRAPH_RUNTIME_DEBUG "Build with tiny graph runtime debug mode" OFF)
35+
tvm_option(USE_SGX "Build with SGX" OFF)
3536
tvm_option(USE_RTTI "Build with RTTI" ON)
3637
tvm_option(USE_MSVC_MT "Build with MT" OFF)
3738
tvm_option(INSTALL_DEV "Install compiler infrastructure" OFF)
@@ -170,6 +171,7 @@ include(cmake/modules/OpenGL.cmake)
170171
include(cmake/modules/Vulkan.cmake)
171172
include(cmake/modules/Metal.cmake)
172173
include(cmake/modules/ROCM.cmake)
174+
include(cmake/modules/SGX.cmake)
173175
include(cmake/modules/LLVM.cmake)
174176
include(cmake/modules/contrib/BLAS.cmake)
175177
include(cmake/modules/contrib/Random.cmake)
@@ -179,6 +181,9 @@ include(cmake/modules/contrib/NNPack.cmake)
179181
add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS})
180182
add_library(tvm_topi SHARED ${TOPI_SRCS})
181183
add_library(tvm_runtime SHARED ${RUNTIME_SRCS})
184+
if(NOT USE_SGX STREQUAL "OFF")
185+
add_dependencies(tvm_runtime sgx_edl)
186+
endif()
182187
add_library(nnvm_compiler SHARED ${NNVM_COMPILER_SRCS})
183188

184189
target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})

cmake/config.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ set(USE_VULKAN OFF)
6262
# Whether enable OpenGL runtime
6363
set(USE_OPENGL OFF)
6464

65+
# Whether to enable SGX runtime
66+
#
67+
# Possible values for USE_SGX:
68+
# - /path/to/sgxsdk: path to Intel SGX SDK
69+
# - OFF: disable SGX
70+
#
71+
# SGX_MODE := HW|SIM
72+
set(USE_SGX OFF)
73+
set(SGX_MODE "SIM")
74+
set(RUST_SGX_SDK "/path/to/rust-sgx-sdk")
75+
6576
# Whether enable RPC runtime
6677
set(USE_RPC ON)
6778

cmake/modules/SGX.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
if(NOT USE_SGX STREQUAL "OFF")
2+
message(STATUS "Build with SGX support")
3+
4+
set(_sgx_src ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/sgx)
5+
set(_tvm_u_h ${_sgx_src}/untrusted/tvm_u.h)
6+
set(_tvm_edl ${_sgx_src}/tvm.edl)
7+
set(_sgx_ustdc ${RUST_SGX_SDK}/sgx_ustdc)
8+
9+
set(_urts_lib "sgx_urts")
10+
if(SGX_MODE STREQUAL "SIM")
11+
set(_urts_lib "${_urts_lib}_sim")
12+
endif()
13+
14+
add_custom_command(
15+
OUTPUT ${_tvm_u_h}
16+
COMMAND ${USE_SGX}/bin/x64/sgx_edger8r --untrusted
17+
--untrusted-dir ${_sgx_src}/untrusted
18+
--search-path ${USE_SGX}/include --search-path ${RUST_SGX_SDK}/edl
19+
${_tvm_edl}
20+
COMMAND sed -i "4i '#include <tvm/runtime/c_runtime_api.h>'" ${_tvm_u_h}
21+
DEPENDS ${_tvm_edl}
22+
)
23+
add_custom_command(
24+
OUTPUT ${_sgx_ustdc}/libsgx_ustdc.a
25+
COMMAND make
26+
WORKING_DIRECTORY ${_sgx_ustdc}
27+
)
28+
add_custom_target(sgx_edl DEPENDS ${_tvm_u_h} ${_sgx_ustdc}/libsgx_ustdc.a)
29+
30+
include_directories(${USE_SGX}/include)
31+
file(GLOB RUNTIME_SGX_SRCS ${_sgx_src}/untrusted/*.c*)
32+
list(APPEND TVM_RUNTIME_LINKER_LIBS
33+
-lpthread
34+
-L${USE_SGX}/lib64 -l${_urts_lib}
35+
-L${RUST_SGX_SDK}/sgx_ustdc -lsgx_ustdc)
36+
list(APPEND RUNTIME_SRCS ${RUNTIME_SGX_SRCS})
37+
endif()

src/runtime/sgx/tvm.edl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
enclave {
22
from "sgx_tstdc.edl" import *;
3+
from "sgx_stdio.edl" import *;
4+
from "sgx_backtrace.edl" import *;
35

46
trusted {
57
public void tvm_ecall_init([isptr, user_check] TVMRetValueHandle ret);

src/runtime/sgx/untrusted/sgx_module.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* \brief SGX enclave module.
55
*/
66
#include <dmlc/logging.h>
7+
#include <sgx_urts.h>
78
#include <tvm/runtime/c_runtime_api.h>
89
#include <tvm/runtime/device_api.h>
910
#include <tvm/runtime/registry.h>
1011
#include <tvm/runtime/threading_backend.h>
11-
#include <sgx_urts.h>
1212
#include <algorithm>
1313
#include <fstream>
1414
#include <iostream>
@@ -18,6 +18,7 @@
1818
#include <unordered_map>
1919
#include "../common.h"
2020
#include "../../file_util.h"
21+
#include "./tvm_u.h"
2122

2223
namespace tvm {
2324
namespace runtime {

0 commit comments

Comments
 (0)