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 11 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. cmake_minimum_required(VERSION 3.14)
  2. project (Parser[CXX])
  3. include(CMakePrintHelpers)
  4. message(STATUS "Variables in parser project :")
  5. cmake_print_variables(ASCEND_OPENSDK_DIR)
  6. cmake_print_variables(CMAKE_BUILD_TYPE)
  7. cmake_print_variables(CMAKE_INSTALL_PREFIX)
  8. cmake_print_variables(CMAKE_PREFIX_PATH)
  9. cmake_print_variables(CMAKE_MODULE_PATH)
  10. cmake_print_variables(protoc_ROOT)
  11. cmake_print_variables(protobuf_grpc_ROOT)
  12. cmake_print_variables(protobuf_static_ROOT)
  13. cmake_print_variables(ascend_protobuf_shared_ROOT)
  14. cmake_print_variables(ascend_protobuf_static_ROOT)
  15. cmake_print_variables(ENABLE_OPEN_SRC ENABLE_GITEE ENABLE_PARSER_UT ENABLE_PARSER_ST ENABLE_PARSER_COV)
  16. cmake_print_variables(BUILD_WITHOUT_AIR BUILD_METADEF METADEF_DIR)
  17. set(INSTALL_BASE_DIR "")
  18. set(INSTALL_LIBRARY_DIR lib)
  19. set(INSTALL_RUNTIME_DIR bin)
  20. set(INSTALL_INCLUDE_DIR include)
  21. set(INSTALL_CONFIG_DIR cmake)
  22. include(CMakePackageConfigHelpers)
  23. set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR})
  24. option(ENABLE_OPEN_SRC "Enable graphengine compile in opensource." FALSE)
  25. if (ENABLE_OPEN_SRC)
  26. set(HI_PYTHON python3)
  27. # 开源软件包
  28. find_package(json MODULE)
  29. find_package(protoc MODULE)
  30. find_package(ascend_protobuf_shared MODULE)
  31. find_package(ascend_protobuf_static MODULE)
  32. find_package(GTest CONFIG REQUIRED)
  33. # 自研软件包
  34. find_package(securec MODULE REQUIRED)
  35. find_package(slog CONFIG REQUIRED)
  36. find_package(mmpa CONFIG REQUIRED)
  37. find_package(runtime CONFIG REQUIRED)
  38. find_package(msprof CONFIG REQUIRED)
  39. find_package(cce CONFIG REQUIRED)
  40. if (BUILD_WITHOUT_AIR)
  41. find_package(air CONFIG REQUIRED)
  42. endif()
  43. if (NOT BUILD_METADEF)
  44. find_package(metadef CONFIG REQUIRED)
  45. endif()
  46. if (BUILD_METADEF)
  47. # 使用medadef源码编译
  48. if (BUILD_WITHOUT_AIR)
  49. # parser集成metadef源码
  50. set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef)
  51. else ()
  52. # air已经集成metadef源码,parser直接使用
  53. message(STATUS "METADEF_DIR = ${METADEF_DIR}")
  54. endif()
  55. else ()
  56. # 使用medadef发布包编译
  57. set(METADEF_DIR ${ASCEND_OPENSDK_DIR})
  58. endif()
  59. include(cmake/intf_pub_linux.cmake)
  60. include(cmake/function.cmake)
  61. else()
  62. # 使用全量源码构建框架集成的metadef源码
  63. set(METADEF_DIR ${TOP_DIR}/metadef)
  64. endif()
  65. set(PARSER_PROTO_LIST
  66. "${METADEF_DIR}/proto/onnx/ge_onnx.proto"
  67. "${METADEF_DIR}/proto/om.proto"
  68. "${METADEF_DIR}/proto/caffe/caffe.proto"
  69. "${METADEF_DIR}/proto/tensorflow/graph_library.proto"
  70. "${METADEF_DIR}/proto/tensorflow/graph.proto"
  71. "${METADEF_DIR}/proto/tensorflow/node_def.proto"
  72. "${METADEF_DIR}/proto/tensorflow/function.proto"
  73. "${METADEF_DIR}/proto/tensorflow/versions.proto"
  74. "${METADEF_DIR}/proto/tensorflow/attr_value.proto"
  75. "${METADEF_DIR}/proto/tensorflow/op_def.proto"
  76. "${METADEF_DIR}/proto/tensorflow/tensor.proto"
  77. "${METADEF_DIR}/proto/tensorflow/tensor_shape.proto"
  78. "${METADEF_DIR}/proto/tensorflow/types.proto"
  79. "${METADEF_DIR}/proto/tensorflow/resource_handle.proto"
  80. )
  81. protobuf_generate(parser_protos PARSER_PROTO_SRCS PARSER_PROTO_HDRS ${PARSER_PROTO_LIST} TARGET)
  82. add_library(parser_headers INTERFACE)
  83. target_include_directories(parser_headers INTERFACE
  84. $<BUILD_INTERFACE:${PARSER_DIR}/inc>
  85. $<BUILD_INTERFACE:${PARSER_DIR}/inc/external>
  86. $<BUILD_INTERFACE:${PARSER_DIR}/inc/external/parser>
  87. $<INSTALL_INTERFACE:include>
  88. $<INSTALL_INTERFACE:include/parser>
  89. $<INSTALL_INTERFACE:include/parser/external>
  90. $<INSTALL_INTERFACE:include/parser/external/parser>
  91. )
  92. set(PARSER_GRAPH_LIBRARY_PROTO_SRC
  93. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/graph_library.pb.cc"
  94. )
  95. set(PARSER_TENSORFLOW_PROTO_SRCS
  96. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/graph.pb.cc"
  97. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/node_def.pb.cc"
  98. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/function.pb.cc"
  99. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/versions.pb.cc"
  100. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/attr_value.pb.cc"
  101. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/op_def.pb.cc"
  102. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/tensor.pb.cc"
  103. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/tensor_shape.pb.cc"
  104. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/types.pb.cc"
  105. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/tensorflow/resource_handle.pb.cc"
  106. )
  107. set(PARSER_ONNX_PROTO_SRCS
  108. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/onnx/ge_onnx.pb.cc"
  109. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/om.pb.cc"
  110. )
  111. set(PARSER_CAFFE_PROTO_SRC
  112. "${CMAKE_BINARY_DIR}/proto/parser_protos/proto/caffe/caffe.pb.cc"
  113. )
  114. add_library(parser_graph_library_proto_obj OBJECT ${PARSER_GRAPH_LIBRARY_PROTO_SRC})
  115. add_dependencies(parser_graph_library_proto_obj parser_protos)
  116. target_compile_definitions(parser_graph_library_proto_obj PRIVATE
  117. google=ascend_private
  118. )
  119. target_link_libraries(parser_graph_library_proto_obj PRIVATE ascend_protobuf intf_pub)
  120. target_compile_options(parser_graph_library_proto_obj PRIVATE
  121. $<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
  122. $<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
  123. $<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
  124. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
  125. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
  126. )
  127. add_library(parser_tensorflow_protos_obj OBJECT ${PARSER_TENSORFLOW_PROTO_SRCS})
  128. add_dependencies(parser_tensorflow_protos_obj parser_protos)
  129. target_compile_definitions(parser_tensorflow_protos_obj PRIVATE
  130. google=ascend_private
  131. )
  132. target_link_libraries(parser_tensorflow_protos_obj PRIVATE ascend_protobuf intf_pub)
  133. target_compile_options(parser_tensorflow_protos_obj PRIVATE
  134. $<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
  135. $<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
  136. $<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
  137. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
  138. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
  139. )
  140. add_library(parser_onnx_protos_obj OBJECT ${PARSER_ONNX_PROTO_SRCS})
  141. add_dependencies(parser_onnx_protos_obj parser_protos)
  142. target_compile_definitions(parser_onnx_protos_obj PRIVATE
  143. google=ascend_private
  144. )
  145. target_link_libraries(parser_onnx_protos_obj PRIVATE ascend_protobuf intf_pub)
  146. target_compile_options(parser_onnx_protos_obj PRIVATE
  147. $<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
  148. $<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
  149. $<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
  150. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
  151. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
  152. )
  153. add_library(parser_caffe_proto_obj OBJECT ${PARSER_CAFFE_PROTO_SRC})
  154. add_dependencies(parser_caffe_proto_obj parser_protos)
  155. target_compile_definitions(parser_caffe_proto_obj PRIVATE
  156. google=ascend_private
  157. )
  158. target_link_libraries(parser_caffe_proto_obj PRIVATE ascend_protobuf intf_pub)
  159. target_compile_options(parser_caffe_proto_obj PRIVATE
  160. $<$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>:-O2 -fPIC -Wextra -Wfloat-equal>
  161. $<$<OR:$<STREQUAL:${PRODUCT_SIDE},host>,$<STREQUAL:${ENABLE_OPEN_SRC},True>>:-fexceptions>
  162. $<$<OR:$<STREQUAL:${TARGET_SYSTEM_NAME},Linux>,$<STREQUAL:${TARGET_SYSTEM_NAME},Android>>:-fno-common -Wextra -Wfloat-equal>
  163. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Debug>>:/MTd>
  164. $<$<AND:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,$<STREQUAL:${CMAKE_CONFIGURATION_TYPES},Release>>:/MT>
  165. )
  166. ############ lib_caffe_parser.so ############
  167. add_library(_caffe_parser SHARED
  168. $<TARGET_OBJECTS:parser_caffe_proto_obj>
  169. )
  170. target_compile_definitions(_caffe_parser PRIVATE
  171. google=ascend_private
  172. )
  173. target_include_directories(_caffe_parser PRIVATE
  174. ${CMAKE_CURRENT_LIST_DIR}
  175. )
  176. target_link_options(_caffe_parser PRIVATE
  177. -Wl,-Bsymbolic
  178. )
  179. target_link_libraries(_caffe_parser
  180. PRIVATE
  181. intf_pub
  182. -Wl,--no-as-needed
  183. ascend_protobuf
  184. -Wl,--as-needed
  185. PUBLIC
  186. parser_headers
  187. )
  188. add_subdirectory(parser)
  189. add_subdirectory(parser/common)
  190. add_subdirectory(parser/func_to_graph)
  191. add_subdirectory(parser/onnx)
  192. if (BUILD_METADEF AND BUILD_WITHOUT_AIR)
  193. add_subdirectory(metadef)
  194. endif()
  195. if(ENABLE_PARSER_UT OR ENABLE_PARSER_COV OR ENABLE_PARSER_ST)
  196. add_subdirectory(tests)
  197. endif()
  198. install(TARGETS _caffe_parser parser_common fmk_onnx_parser fmk_parser parser_headers
  199. EXPORT parser-targets
  200. LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR} OPTIONAL COMPONENT opensdk
  201. ARCHIVE DESTINATION ${INSTALL_LIBRARY_DIR} OPTIONAL COMPONENT opensdk
  202. RUNTIME DESTINATION ${INSTALL_RUNTIME_DIR} OPTIONAL COMPONENT opensdk
  203. )
  204. install(FILES ${PARSER_DIR}/inc/external/parser/onnx_parser.h
  205. ${PARSER_DIR}/inc/external/parser/caffe_parser.h
  206. ${PARSER_DIR}/inc/external/parser/tensorflow_parser.h
  207. DESTINATION ${INSTALL_INCLUDE_DIR}/parser/external/parser COMPONENT opensdk EXCLUDE_FROM_ALL
  208. )
  209. # 下列头文件发布是非法的,需要在后续整改中删掉
  210. # --------------------start------------------------
  211. install(FILES ${PARSER_DIR}/parser/common/pre_checker.h
  212. DESTINATION ${INSTALL_INCLUDE_DIR}/parser/parser/common COMPONENT opensdk EXCLUDE_FROM_ALL
  213. )
  214. install(FILES ${PARSER_DIR}/parser/common/convert/pb2json.h
  215. DESTINATION ${INSTALL_INCLUDE_DIR}/parser/parser/common/convert COMPONENT opensdk EXCLUDE_FROM_ALL
  216. )
  217. # ---------------------end-------------------------
  218. if (PACKAGE STREQUAL "opensdk")
  219. install(EXPORT parser-targets DESTINATION ${INSTALL_CONFIG_DIR}
  220. FILE parser-targets.cmake COMPONENT opensdk EXCLUDE_FROM_ALL
  221. )
  222. set(PKG_NAME parser)
  223. configure_package_config_file(${TOP_DIR}/cmake/config/pkg_config_template.cmake.in
  224. ${CMAKE_CURRENT_BINARY_DIR}/parser-config.cmake
  225. INSTALL_DESTINATION ${INSTALL_CONFIG_DIR}
  226. PATH_VARS INSTALL_BASE_DIR INSTALL_INCLUDE_DIR INSTALL_LIBRARY_DIR INSTALL_RUNTIME_DIR INSTALL_CONFIG_DIR
  227. INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}
  228. )
  229. unset(PKG_NAME)
  230. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/parser-config.cmake
  231. DESTINATION ${INSTALL_CONFIG_DIR} COMPONENT opensdk EXCLUDE_FROM_ALL
  232. )
  233. endif()