You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 9.8 kB

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