-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
234 lines (201 loc) · 9.24 KB
/
CMakeLists.txt
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
cmake_minimum_required(VERSION 3.14)
project (Parser[CXX])
set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR})
if (DEFINED ENV{D_PKG_SERVER})
set(PARSER_PB_PKG $ENV{D_PKG_SERVER})
elseif (DEFINED ENV{MSLIBS_SERVER})
set(PARSER_PB_PKG "http://$ENV{MSLIBS_SERVER}:8081")
message("Download packages from MSPKG server")
endif ()
option(ENABLE_OPEN_SRC "Enable graphengine compile in opensource." FALSE)
if (ENABLE_OPEN_SRC)
set(HI_PYTHON python3)
include(cmake/external_libs/protobuf_shared.cmake)
include(cmake/external_libs/protoc.cmake)
include(cmake/external_libs/securec.cmake)
include(cmake/external_libs/json.cmake)
include(cmake/external_libs/gtest.cmake)
include(cmake/FindModule.cmake)
include(cmake/intf_pub_linux.cmake)
if(DEFINED ENV{D_LINK_PATH})
# D_LINK_PATH is set
set(GE_LIB_PATH $ENV{D_LINK_PATH})
set(GE_SYS_ARCH "")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
# x86 ubuntu
set(GE_SYS_ARCH "x86_64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
# arm euleros
set(GE_SYS_ARCH "aarch64")
else()
message(FATAL_ERROR "Running on a unsupported architecture: ${SYSTEM_TYPE}, build terminated")
endif()
set(GE_LIB_PATH ${GE_LIB_PATH}/${GE_SYS_ARCH})
find_module(slog libalog.so ${GE_LIB_PATH})
find_module(static_mmpa libmmpa.a ${GE_LIB_PATH})
elseif(ENABLE_GE_COV OR ENABLE_GE_UT)
message(STATUS "Runing on llt mode, no need to depend other component")
elseif(ENABLE_PARSER_UT OR ENABLE_PARSER_COV)
add_subdirectory(tests)
else()
if(DEFINED ENV{ASCEND_CUSTOM_PATH})
set(ASCEND_DIR $ENV{ASCEND_CUSTOM_PATH})
else()
set(ASCEND_DIR /usr/local/Ascend)
endif()
set(ASCEND_ATC_DIR ${ASCEND_DIR}/atc/lib64)
find_module(slog libalog.so ${ASCEND_ATC_DIR})
find_module(static_mmpa libmmpa.a ${ASCEND_ATC_DIR})
endif()
if (NOT DEFINED METADEF_DIR)
set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef)
add_subdirectory(metadef)
endif()
else()
####工程tigong
set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/../metadef)
endif()
set(PARSER_PROTO_LIST
"${METADEF_DIR}/proto/onnx/ge_onnx.proto"
"${METADEF_DIR}/proto/om.proto"
"${METADEF_DIR}/proto/caffe/caffe.proto"
"${METADEF_DIR}/proto/tensorflow/graph_library.proto"
"${METADEF_DIR}/proto/tensorflow/graph.proto"
"${METADEF_DIR}/proto/tensorflow/node_def.proto"
"${METADEF_DIR}/proto/tensorflow/function.proto"
"${METADEF_DIR}/proto/tensorflow/versions.proto"
"${METADEF_DIR}/proto/tensorflow/attr_value.proto"
"${METADEF_DIR}/proto/tensorflow/op_def.proto"
"${METADEF_DIR}/proto/tensorflow/tensor.proto"
"${METADEF_DIR}/proto/tensorflow/tensor_shape.proto"
"${METADEF_DIR}/proto/tensorflow/types.proto"
"${METADEF_DIR}/proto/tensorflow/resource_handle.proto"
)
protobuf_generate(parser_protos PARSER_PROTO_SRCS PARSER_PROTO_HDRS ${PARSER_PROTO_LIST} TARGET)
set(PARSER_GRAPH_LIBRARY_PROTO_SRC
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/graph_library.pb.cc"
)
set(PARSER_TENSORFLOW_PROTO_SRCS
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/graph.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/node_def.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/function.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/versions.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/attr_value.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/op_def.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/tensor.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/tensor_shape.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/types.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/resource_handle.pb.cc"
)
set(PARSER_ONNX_PROTO_SRCS
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/onnx/ge_onnx.pb.cc"
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/om.pb.cc"
)
set(PARSER_CAFFE_PROTO_SRC
"${CMAKE_BINARY_DIR}/proto/parser_protos/proto/caffe/caffe.pb.cc"
)
add_library(parser_graph_library_proto_obj OBJECT ${PARSER_GRAPH_LIBRARY_PROTO_SRC})
add_dependencies(parser_graph_library_proto_obj parser_protos)
target_include_directories(parser_graph_library_proto_obj PRIVATE
#### blue zone ####
${PROTOBUF_SHARED_PKG_DIR}/include
#### yellow zone ####
${ASCEND_PROTOBUF_SHARED_PKG_DIR}/include
)
target_compile_definitions(parser_graph_library_proto_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_graph_library_proto_obj PRIVATE ascend_protobuf $<BUILD_INTERFACE:intf_pub>)
target_compile_options(parser_graph_library_proto_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>: -Wno-deprecated-declarations -fno-common>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
add_library(parser_tensorflow_protos_obj OBJECT ${PARSER_TENSORFLOW_PROTO_SRCS})
add_dependencies(parser_tensorflow_protos_obj parser_protos)
target_include_directories(parser_tensorflow_protos_obj PRIVATE
#### blue zone ####
${PROTOBUF_SHARED_PKG_DIR}/include
#### yellow zone ####
${ASCEND_PROTOBUF_SHARED_PKG_DIR}/include
)
target_compile_definitions(parser_tensorflow_protos_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_tensorflow_protos_obj PRIVATE ascend_protobuf $<BUILD_INTERFACE:intf_pub>)
target_compile_options(parser_tensorflow_protos_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>: -Wno-deprecated-declarations -fno-common>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
add_library(parser_onnx_protos_obj OBJECT ${PARSER_ONNX_PROTO_SRCS})
add_dependencies(parser_onnx_protos_obj parser_protos)
target_include_directories(parser_onnx_protos_obj PRIVATE
#### blue zone ####
${PROTOBUF_SHARED_PKG_DIR}/include
#### yellow zone ####
${ASCEND_PROTOBUF_SHARED_PKG_DIR}/include
)
target_compile_definitions(parser_onnx_protos_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_onnx_protos_obj PRIVATE ascend_protobuf $<BUILD_INTERFACE:intf_pub>)
target_compile_options(parser_onnx_protos_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>: -Wno-deprecated-declarations -fno-common>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
add_library(parser_caffe_proto_obj OBJECT ${PARSER_CAFFE_PROTO_SRC})
add_dependencies(parser_caffe_proto_obj parser_protos)
target_include_directories(parser_caffe_proto_obj PRIVATE
#### blue zone ####
${PROTOBUF_SHARED_PKG_DIR}/include
#### yellow zone ####
${ASCEND_PROTOBUF_SHARED_PKG_DIR}/include
)
target_compile_definitions(parser_caffe_proto_obj PRIVATE
google=ascend_private
)
target_link_libraries(parser_caffe_proto_obj PRIVATE ascend_protobuf $<BUILD_INTERFACE:intf_pub>)
target_compile_options(parser_caffe_proto_obj PRIVATE
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC>
$<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
$<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>: -Wno-deprecated-declarations -fno-common>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
$<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
)
############ lib_caffe_parser.so ############
add_library(_caffe_parser SHARED
$<TARGET_OBJECTS:parser_caffe_proto_obj>
)
target_compile_definitions(_caffe_parser PRIVATE
google=ascend_private
)
target_include_directories(_caffe_parser PRIVATE
${CMAKE_CURRENT_LIST_DIR}
)
target_link_options(_caffe_parser PRIVATE
-Wl,-Bsymbolic
)
target_link_libraries(_caffe_parser PRIVATE
$<BUILD_INTERFACE:intf_pub>
-Wl,--no-as-needed
ascend_protobuf
-Wl,--as-needed
)
############ install ############
set(INSTALL_BASE_DIR "")
set(INSTALL_LIBRARY_DIR lib)
install(TARGETS _caffe_parser OPTIONAL
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
)
add_subdirectory(parser)
add_subdirectory(parser/common)
add_subdirectory(parser/func_to_graph)
add_subdirectory(parser/onnx)