Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit dd3eb67

Browse files
author
Zhang Shuai
authored
Merge pull request #529 from uraj/sgx
Fix SGX build failure
2 parents 6c43406 + 2fd6926 commit dd3eb67

File tree

10 files changed

+115
-57
lines changed

10 files changed

+115
-57
lines changed

cmake/compiler_options.cmake

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,34 @@ anakin_add_compile_option(-Wno-missing-field-initializers)
5757
anakin_add_compile_option(-Wno-extra)
5858

5959
if(ENABLE_NOISY_WARNINGS)
60-
anakin_add_compile_option(-Wcast-align)
61-
anakin_add_compile_option(-Wstrict-aliasing=2)
62-
anakin_add_compile_option(-Wundef)
63-
anakin_add_compile_option(-Wsign-compare)
60+
anakin_add_compile_option(-Wcast-align)
61+
anakin_add_compile_option(-Wstrict-aliasing=2)
62+
anakin_add_compile_option(-Wundef)
63+
anakin_add_compile_option(-Wsign-compare)
6464
else()
65-
anakin_add_compile_option(-Wno-undef)
66-
anakin_add_compile_option(-Wno-narrowing)
67-
anakin_add_compile_option(-Wno-unknown-pragmas)
68-
anakin_add_compile_option(-Wno-delete-non-virtual-dtor)
69-
anakin_add_compile_option(-Wno-comment)
70-
anakin_add_compile_option(-Wno-sign-compare)
65+
anakin_add_compile_option(-Wno-undef)
66+
anakin_add_compile_option(-Wno-narrowing)
67+
anakin_add_compile_option(-Wno-unknown-pragmas)
68+
anakin_add_compile_option(-Wno-delete-non-virtual-dtor)
69+
anakin_add_compile_option(-Wno-comment)
70+
anakin_add_compile_option(-Wno-sign-compare)
7171
anakin_add_compile_option(-Wno-write-strings)
7272
anakin_add_compile_option(-Wno-ignored-qualifiers)
7373
anakin_add_compile_option(-Wno-enum-compare)
7474
anakin_add_compile_option(-Wno-missing-field-initializers)
7575
endif()
7676

77+
if(USE_SGX)
78+
# SGX build uses MKL instead of MKLMKL, possibly a higer version
79+
# Some APIs may be deprecated by later MKL. We want to ignore
80+
# these warnings
81+
anakin_add_compile_option(-Wno-deprecated-declarations)
82+
endif()
83+
7784
if(CMAKE_BUILD_TYPE MATCHES Debug)
7885
anakin_add_compile_option(-O0)
79-
anakin_add_compile_option(-g)
80-
anakin_add_compile_option(-gdwarf-2) # for old version gcc and gdb. see: http://stackoverflow.com/a/15051109/673852
86+
anakin_add_compile_option(-g)
87+
anakin_add_compile_option(-gdwarf-2) # for old version gcc and gdb. see: http://stackoverflow.com/a/15051109/673852
8188
else()
8289
if(USE_SGX)
8390
anakin_add_compile_option(-Os)
@@ -95,16 +102,16 @@ else()
95102
endif()
96103

97104
if(TARGET_ANDROID)
98-
anakin_add_compile_option(-pie)
105+
anakin_add_compile_option(-pie)
99106
add_compile_options(-ldl)
100-
anakin_add_compile_option(-lc)
107+
anakin_add_compile_option(-lc)
101108
set(ANAKIN_EXTRA_CXX_FLAGS "${ANAKIN_EXTRA_CXX_FLAGS} ${ANDROID_CXX_FLAGS}")
102109
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
103110
set(MAKE_STATIC_LINKER_FLAGS "${MAKE_STATIC_LINKER_FLAGS} -Wl,--gc-sections")
104111
endif()
105112

106113
if(TARGET_IOS)
107-
# none temp
114+
# none temp
108115
endif()
109116

110117
if(BUILD_STATIC OR X86_COMPILE_482)
@@ -141,18 +148,11 @@ endif()
141148

142149
# The -Wno-long-long is required in 64bit systems when including sytem headers.
143150
if(X86_64)
144-
anakin_add_compile_option(-Wno-long-long)
151+
anakin_add_compile_option(-Wno-long-long)
145152
endif()
146153

147154
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ANAKIN_EXTRA_CXX_FLAGS}")
148155

149-
#if(WIN32)
150-
# if(MSVC)
151-
# message(STATUS "Using msvc compiler")
152-
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_SCL_SECURE_NO_WARNINGS")
153-
# endif()
154-
#endif()
155-
156156
if(USE_CUDA)
157157
if(CMAKE_BUILD_TYPE MATCHES Debug)
158158
anakin_add_compile_option("-Xcompiler -fPIC" NVCC)

cmake/external/xbyak.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ message(STATUS "Scanning external modules ${Green}xbyak${ColourReset} ...")
2828
include_directories(${XBYAK_INC_DIR})
2929

3030
if(USE_SGX)
31-
set(SGX_PATCH_CMD "cd ${ANAKIN_TEMP_THIRD_PARTY_PATH} && patch -p0 <${ANAKIN_THIRD_PARTY_PATH}/xbyak.patch")
31+
set(SGX_PATCH_CMD "cd ${XBYAK_INSTALL_ROOT} && patch -p1 <${ANAKIN_THIRD_PARTY_PATH}/xbyak.patch")
3232
else()
3333
# use a whitespace as nop so that sh won't complain about missing argument
3434
set(SGX_PATCH_CMD " ")

framework/core/functor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Functor {
3535
Functor(){}
3636
Functor(FuncType& func):_func(func){};
3737

38-
Functor<RetType, ParamTypes...>& operator=(FuncType& func) { _func=func; return ;}
38+
Functor<RetType, ParamTypes...>& operator=(FuncType& func) { _func=func; return *this;}
3939

4040
/// must be overwritten
4141
virtual RetType operator()(ParamTypes ...parameters) = 0;

framework/core/net/net.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,9 @@ void Net<Ttype, Ptype, RunType>::fusion_init(graph::Graph<Ttype, Ptype>& graph,
917917
// shallow copy
918918
_graph_p->CopyFrom(graph);
919919
auto node_names_in_exec_order = graph.get_nodes_in_order();
920+
#ifndef USE_SGX
920921
load_calibrator_config(graph,!_has_loaded_layout_from_file,auto_config_layout);
922+
#endif
921923
#ifndef USE_BM_PLACE // anbl add
922924
// infer basic shape and parsing parameter from graph
923925
for (auto& node_name : node_names_in_exec_order) {

framework/graph/llvm/scheduler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ void Scheduler::Run() {
126126

127127
// debug info
128128
for (const auto& op : this->_wait_que) {
129-
std::ostringstream oss;
130129
LOG(INFO) << "op.name=" << op.name;
131130
int i = 0;
132131
for (const auto& in : op_inputs[op.name]) {

saber/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ endif()
7171

7272
if(USE_SGX)
7373
set(SGX_INCOMPATIBLE_SRC
74-
${ANAKIN_SABER}/funcs/impl/x86/mkl_gemm.cpp
75-
${ANAKIN_SABER}/funcs/impl/x86/mkldnn_helper.cpp
76-
${ANAKIN_SABER}/funcs/impl/x86/saber_lstmp.cpp
77-
${ANAKIN_SABER}/funcs/impl/x86/saber_lstm.cpp
78-
${ANAKIN_SABER}/funcs/impl/x86/mkl_packed_int8_gemm.cpp
74+
${ANAKIN_SABER}/funcs/impl/x86/mkl_gemm.cpp
75+
${ANAKIN_SABER}/funcs/impl/x86/mkldnn_helper.cpp
76+
${ANAKIN_SABER}/funcs/impl/x86/saber_lstmp.cpp
77+
#${ANAKIN_SABER}/funcs/impl/x86/saber_lstm.cpp
78+
${ANAKIN_SABER}/funcs/impl/x86/mkl_packed_int8_gemm.cpp
7979
)
8080
foreach(toremove ${SGX_INCOMPATIBLE_SRC})
8181
list(REMOVE_ITEM ANAKIN_SABER_BASE_SRC ${toremove})

saber/funcs/impl/x86/vender_fc.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ ::create(const std::vector<Tensor<X86> *>& inputs,
5858
for (int i = 0; i < inputs.size(); i++) {
5959
cblas_int IC = inputs[i]->count_valid(param.axis, inputs[i]->dims());
6060
packed_weights.push_back(cblas_sgemm_alloc(CblasAMatrix, OC, MB, IC));
61-
// LOG(INFO) << "anakin input[" << i << "] alloc passed";
6261
cblas_sgemm_pack(CblasColMajor,
6362
CblasAMatrix,
6463
param.is_transpose_weights ? CblasNoTrans : CblasTrans,
@@ -67,7 +66,6 @@ ::create(const std::vector<Tensor<X86> *>& inputs,
6766
weights + total_IC * OC, IC,
6867
packed_weights[i]);
6968
total_IC += IC;
70-
// LOG(INFO) << "anakin input[" << i << "] pack passed";
7169
}
7270

7371
CHECK_EQ(inputs.size(), 1);
@@ -182,7 +180,6 @@ ::dispatch(const std::vector<Tensor<X86> *>& inputs,
182180
cblas_int IC = inputs[i]->count_valid(param.axis, inputs[i]->dims());
183181

184182
if (i == 0) {
185-
// C := alpha * op(A) * op(B) + beta * C
186183
cblas_sgemm_compute(CblasColMajor, // Layout
187184
CblasPacked, // a
188185
CblasNoTrans, // b是否转置
@@ -201,14 +198,6 @@ ::dispatch(const std::vector<Tensor<X86> *>& inputs,
201198
1.0, // beta
202199
dst, OC); // c, ldc
203200
}
204-
205-
//LOG(INFO) << "anakin compute[" << i << "] passed";
206-
207-
// LOG(INFO) << "inputs[]:dims: " << inputs[0]->dims();
208-
// LOG(INFO) << "inputs:size: " << inputs.size();
209-
// LOG(INFO) << "inputs:capacity: " << inputs.capacity();
210-
// LOG(INFO) << "output:size: " << outputs.size();
211-
// LOG(INFO) << "OC, MB, IC: " << OC << " "<< MB << " " << IC;
212201
}
213202

214203
if (bias) {
@@ -246,7 +235,6 @@ SaberStatus VenderFc<X86, AK_INT8>::create(const std::vector<Tensor<X86> *>& inp
246235
ws_ = nullptr;
247236
}
248237

249-
// LOG(INFO)<<"batch size = "<<_batch_size<<","<<_output_channel;
250238
ws_ = zmalloc(_batch_size * _output_channel * sizeof(int), 256);
251239

252240
if (ws_ == nullptr) {
@@ -291,7 +279,6 @@ SaberStatus VenderFc<X86, AK_INT8>::init(const std::vector<Tensor<X86> *>& input
291279
_need_weights_trans = true;
292280
_weights_trans.re_alloc(param.weights->valid_shape(), AK_INT8);
293281
utils::ScaleUtils::scale_fc_weights_to_nchw_host(_weights_trans, *param.weights);
294-
// LOG(INFO)<<"input shape "<<inputs[0]->valid_shape()<<" , weights shape "<<param.weights->valid_shape();
295282
}
296283

297284
if (_need_weights_trans) {
@@ -369,18 +356,9 @@ SaberStatus VenderFc<X86, AK_INT8>::dispatch(const std::vector<Tensor<X86> *>& i
369356
auto weight = static_cast<const int8_t*>(param.weights->data()) + total_ic * _output_channel;
370357

371358
if (_need_weights_trans) {
372-
// LOG(INFO)<<"weights trans";
373359
weight = static_cast<const int8_t*>(_weights_trans.data()) + total_ic * _output_channel;
374-
// print_tensor(_weights_trans);
375360
}
376361

377-
// for(auto a:_scale){
378-
// LOG(INFO)<<"scale = "<<a;
379-
// }
380-
// LOG(INFO)<<"m,n,k = "<<_output_channel<<","<<_batch_size<<","<<IC;
381-
// print_tensor(_bias_scale);
382-
/* c = scale * { op(A) + a_offset_scale * a_offset } *
383-
{ op(B) + b_offset_scale * b_offset } + beta * C + c_offset */
384362
if (i == 0) {
385363
cblas_gemm_s8u8s32(CblasColMajor, // Layout
386364
_is_transpose_weights, // a need to transpose or not

saber/funcs/impl/x86/vender_fc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class VenderFc<X86, OpDtype> : public ImplBase<X86, OpDtype, FcParam<X86> > {
6868
Tensor<X86> _input_scale;
6969
Tensor<X86> _bias_scale;
7070

71-
#ifndef USE_SGX
71+
//#ifndef USE_SGX
7272
PackedMKLInt8Gemm _packed_int8_gemm;
73-
#endif
73+
//#endif
7474
};
7575

7676

sgx/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ target_link_libraries(anakin_app
165165
set(CLI11_SRC ${UNTRUSTED_DIR}/CLI11.hpp)
166166
add_custom_command(
167167
OUTPUT ${CLI11_SRC}
168-
WORKING_DIRECTORY ${UNTRUSTED_DIR}
169-
COMMAND wget ARGS -q https://github.com/CLIUtils/CLI11/releases/download/v1.7.1/CLI11.hpp
168+
COMMAND ${CMAKE_COMMAND} -E make_directory ${UNTRUSTED_DIR}
169+
COMMAND wget ARGS
170+
-q https://github.com/CLIUtils/CLI11/releases/download/v1.7.1/CLI11.hpp
171+
-O ${UNTRUSTED_DIR}/CLI11.hpp
170172
COMMENT "Downloading CLI11.hpp..."
171173
)
172174
add_custom_target(cli11 ALL

third-party/xbyak.patch

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
--- xbyak/include/xbyak/xbyak.h.orig 2019-01-17 11:58:36.391601030 -0800
2+
+++ xbyak/include/xbyak/xbyak.h 2019-01-17 11:59:09.367746049 -0800
3+
@@ -27,9 +27,7 @@
4+
// #define XBYAK_DISABLE_AVX512
5+
6+
//#define XBYAK_USE_MMAP_ALLOCATOR
7+
-#if !defined(__GNUC__) || defined(__MINGW32__)
8+
- #undef XBYAK_USE_MMAP_ALLOCATOR
9+
-#endif
10+
+#undef XBYAK_USE_MMAP_ALLOCATOR
11+
12+
#ifdef __GNUC__
13+
#define XBYAK_GNUC_PREREQ(major, minor) ((__GNUC__) * 100 + (__GNUC_MINOR__) >= (major) * 100 + (minor))
14+
@@ -69,7 +67,6 @@
15+
#include <malloc.h>
16+
#elif defined(__GNUC__)
17+
#include <unistd.h>
18+
- #include <sys/mman.h>
19+
#include <stdlib.h>
20+
#endif
21+
#if !defined(_MSC_VER) || (_MSC_VER >= 1600)
22+
@@ -253,15 +250,8 @@
23+
24+
inline void *AlignedMalloc(size_t size, size_t alignment)
25+
{
26+
-#ifdef __MINGW32__
27+
- return __mingw_aligned_malloc(size, alignment);
28+
-#elif defined(_WIN32)
29+
- return _aligned_malloc(size, alignment);
30+
-#else
31+
- void *p;
32+
- int ret = posix_memalign(&p, alignment, size);
33+
- return (ret == 0) ? p : 0;
34+
-#endif
35+
+ abort();
36+
+ return nullptr;
37+
}
38+
39+
inline void AlignedFree(void *p)
40+
@@ -970,35 +960,7 @@
41+
*/
42+
static inline bool protect(const void *addr, size_t size, int protectMode)
43+
{
44+
-#if defined(_WIN32)
45+
- const DWORD c_rw = PAGE_READWRITE;
46+
- const DWORD c_rwe = PAGE_EXECUTE_READWRITE;
47+
- const DWORD c_re = PAGE_EXECUTE_READ;
48+
- DWORD mode;
49+
-#else
50+
- const int c_rw = PROT_READ | PROT_WRITE;
51+
- const int c_rwe = PROT_READ | PROT_WRITE | PROT_EXEC;
52+
- const int c_re = PROT_READ | PROT_EXEC;
53+
- int mode;
54+
-#endif
55+
- switch (protectMode) {
56+
- case PROTECT_RW: mode = c_rw; break;
57+
- case PROTECT_RWE: mode = c_rwe; break;
58+
- case PROTECT_RE: mode = c_re; break;
59+
- default:
60+
- return false;
61+
- }
62+
-#if defined(_WIN32)
63+
- DWORD oldProtect;
64+
- return VirtualProtect(const_cast<void*>(addr), size, mode, &oldProtect) != 0;
65+
-#elif defined(__GNUC__)
66+
- size_t pageSize = sysconf(_SC_PAGESIZE);
67+
- size_t iaddr = reinterpret_cast<size_t>(addr);
68+
- size_t roundAddr = iaddr & ~(pageSize - static_cast<size_t>(1));
69+
- return mprotect(reinterpret_cast<void*>(roundAddr), size + (iaddr - roundAddr), mode) == 0;
70+
-#else
71+
- return true;
72+
-#endif
73+
+ return false;
74+
}
75+
/**
76+
get aligned memory pointer
77+

0 commit comments

Comments
 (0)