Makefile 2.5 KB
Newer Older
nhynes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# 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
SGX_MODE ?= SIM
SGX_ARCH ?= x64
SGX_DEBUG ?= 1

sgx_edger8r := $(SGX_SDK)/bin/x64/sgx_edger8r
sgx_enclave_signer := $(SGX_SDK)/bin/x64/sgx_sign

ifneq ($(SGX_MODE), HW)
	sgx_sim := _sim
endif
urts_library_name := sgx_urts$(sgx_sim)
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}/dlpack/include\
	-I.\
	-DDMLC_LOG_STACK_TRACE=0\
29
	-fmax-errors=4
nhynes committed
30 31 32 33 34 35 36 37 38 39 40 41

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++\

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

45
enclave_cxxflags := -nostdinc++ $(enclave_cflags) -DTVM_SGX_MAX_CONCURRENCY=4
nhynes committed
46 47 48 49 50 51 52 53 54 55 56 57 58

enclave_ldflags :=\
	-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)\
	-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

nhynes committed
59
all: lib/test_addone.signed.so
nhynes committed
60 61 62 63 64

# The code library built by TVM
lib/test_addone_sys.o: prepare_test_libs.py
	python prepare_test_libs.py

nhynes committed
65
lib/tvm_t.h: ../../src/runtime/sgx/tvm.edl
nhynes committed
66
	$(sgx_edger8r) --trusted $< --trusted-dir lib --search-path $(SGX_SDK)/include
nhynes committed
67 68
	mv $@ $@.in
	awk 'NR==4{print "#include <tvm/runtime/c_runtime_api.h>"}1' $@.in > $@
nhynes committed
69

nhynes committed
70 71 72 73
lib/tvm_t.c: lib/tvm_t.h

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
nhynes committed
74 75

# The enclave library
nhynes committed
76
lib/test_addone.so: $(TVM_ROOT)/src/runtime/sgx/trusted/runtime.cc lib/tvm_t.o lib/test_addone_sys.o
nhynes committed
77 78 79 80 81 82 83
	$(CXX) $^ -o $@ $(pkg_cflags) $(pkg_ldflags) $(enclave_cxxflags) $(enclave_ldflags) -g

# The signed enclave
lib/test_addone.signed.so: lib/test_addone.so enclave_config.xml
	$(sgx_enclave_signer) sign -key enclave_private.pem -enclave $< -out $@ -config enclave_config.xml

clean:
nhynes committed
84
	rm -rf lib