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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # Copyright 2019-2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. cmake_minimum_required(VERSION 3.14)
  16. project (GraphEngine[CXX])
  17. set(CMAKE_CXX_STANDARD 17)
  18. add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
  19. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
  20. set(GE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
  21. set(GE_PROTO_DIR ${GE_SOURCE_DIR}/src)
  22. if (NOT BUILD_PATH)
  23. set(BUILD_PATH "${CMAKE_SOURCE_DIR}/build")
  24. endif()
  25. # architecture: aarch64 or x86_64
  26. message(STATUS "System architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
  27. # system: euleros or ubuntu
  28. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  29. execute_process(
  30. COMMAND bash "-c" "cat /etc/os-release | grep ^ID= | awk -F '=' '{print $2}'"
  31. OUTPUT_VARIABLE SYSTEM_TYPE
  32. )
  33. MESSAGE(STATUS "System type: ${SYSTEM_TYPE}.")
  34. endif()
  35. # download json headers, rather than whole repository
  36. include(${GE_SOURCE_DIR}/cmake/ge_utils.cmake)
  37. include(${GE_SOURCE_DIR}/cmake/external_libs/json.cmake)
  38. include(${GE_SOURCE_DIR}/cmake/external_libs/eigen.cmake)
  39. include(${GE_SOURCE_DIR}/cmake/external_libs/gtest.cmake)
  40. include(${GE_SOURCE_DIR}/cmake/external_libs/protobuf.cmake)
  41. include(${GE_SOURCE_DIR}/cmake/external_libs/onnx.cmake)
  42. include(${GE_SOURCE_DIR}/cmake/external_libs/securec.cmake)
  43. set(CMAKE_SKIP_RPATH TRUE)
  44. # for CPU/GPU mode, find c_sec and slog from local prebuild
  45. if(NOT ENABLE_D AND NOT GE_ONLY)
  46. set(GE_PREBUILD_PATH ${GE_SOURCE_DIR}/third_party/prebuild/${CMAKE_HOST_SYSTEM_PROCESSOR})
  47. find_library(slog libslog.so ${GE_PREBUILD_PATH})
  48. # if D_LINK_PATH is set in environment variables, search libraries in given path
  49. elseif(DEFINED ENV{D_LINK_PATH})
  50. # D_LINK_PATH is set
  51. set(GE_LIB_PATH $ENV{D_LINK_PATH})
  52. set(GE_SYS_ARCH "")
  53. if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
  54. # x86 ubuntu
  55. set(GE_SYS_ARCH "x86_64")
  56. elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
  57. # arm euleros
  58. set(GE_SYS_ARCH "aarch64")
  59. else()
  60. message(FATAL_ERROR "Running on a unsupported architecture: ${SYSTEM_TYPE}, build terminated")
  61. endif()
  62. set(GE_LIB_PATH ${GE_LIB_PATH}/${GE_SYS_ARCH})
  63. find_library(slog libslog.so ${GE_LIB_PATH})
  64. find_library(mmpa libmmpa.so ${GE_LIB_PATH})
  65. find_library(runtime libruntime.so ${GE_LIB_PATH})
  66. find_library(msprof libmsprof.so ${GE_LIB_PATH})
  67. find_library(register libregister.so ${GE_LIB_PATH})
  68. find_library(hccl libhccl.so ${GE_LIB_PATH})
  69. find_library(resource libresource.so ${GE_LIB_PATH})
  70. find_library(error_manager liberror_manager.so ${GE_LIB_PATH})
  71. else()
  72. # Ascend mode
  73. if(DEFINED ENV{ASCEND_CUSTOM_PATH})
  74. set(ASCEND_DIR $ENV{ASCEND_CUSTOM_PATH})
  75. else()
  76. set(ASCEND_DIR /usr/local/Ascend)
  77. endif()
  78. set(ASCEND_DRIVER_DIR ${ASCEND_DIR}/driver/lib64/common)
  79. set(ASCEND_RUNTIME_DIR ${ASCEND_DIR}/fwkacllib/lib64)
  80. find_library(slog libslog.so ${ASCEND_DRIVER_DIR})
  81. find_library(mmpa libmmpa.so ${ASCEND_DRIVER_DIR})
  82. find_library(msprof libmsprof.so ${ASCEND_DRIVER_DIR})
  83. find_library(hccl libhccl.so ${ASCEND_RUNTIME_DIR})
  84. find_library(runtime libruntime.so ${ASCEND_RUNTIME_DIR})
  85. find_library(register libregister.so ${ASCEND_RUNTIME_DIR})
  86. find_library(resource libresource.so ${ASCEND_RUNTIME_DIR})
  87. find_library(error_manager liberror_manager.so ${ASCEND_RUNTIME_DIR})
  88. endif()
  89. # add compile flags
  90. if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  91. message("Build in Debug mode")
  92. set(CMAKE_C_FLAGS "-O0 -g -Wall -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe -fPIC ${CMAKE_C_FLAGS}")
  93. set(CMAKE_CXX_FLAGS "-O0 -g -Wall -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe -fPIC ${CMAKE_CXX_FLAGS}")
  94. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  95. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic")
  96. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
  97. endif()
  98. else()
  99. set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe ${CMAKE_C_FLAGS}")
  100. set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe ${CMAKE_CXX_FLAGS}")
  101. endif ()
  102. # force __FILE__ to show relative path of file, from source directory, as cmake project makes __FILE__ absolute directory
  103. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILE__='\"$(subst $(realpath ${CMAKE_SOURCE_DIR})/,,$(abspath $<))\"' -Wno-builtin-macro-redefined")
  104. # compile libraries from following directories
  105. # libgraph is compiled in any situation
  106. add_subdirectory(${GE_SOURCE_DIR}/src/common/graph)
  107. if(ENABLE_D)
  108. # if MindSpore compiles in D mode, compile the following libraries
  109. add_subdirectory(${GE_SOURCE_DIR}/src/ge/common)
  110. add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_runtime)
  111. elseif(GE_ONLY)
  112. # standalone GraphEngine compiles all following libraries
  113. add_subdirectory(${GE_SOURCE_DIR}/src/ge/common)
  114. add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_runtime)
  115. add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_local_engine)
  116. add_subdirectory(${GE_SOURCE_DIR}/src/ge/graph/build/memory)
  117. add_subdirectory(${GE_SOURCE_DIR}/src/ge/)
  118. add_subdirectory(${GE_SOURCE_DIR}/src/ge/plugin/engine)
  119. endif()
  120. # if (ENABLE_GE_COV OR ENABLE_GE_UT OR ENABLE_GE_ST)
  121. # add_subdirectory(tests)
  122. # endif()

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示