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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 14)
  18. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
  19. set(GE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
  20. set(GE_PROTO_DIR ${GE_SOURCE_DIR}/src)
  21. if (NOT BUILD_PATH)
  22. set(BUILD_PATH "${CMAKE_SOURCE_DIR}/build")
  23. endif()
  24. # architecture: aarch64 or x86_64
  25. message(STATUS "System architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
  26. # system: euleros or ubuntu
  27. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  28. execute_process(
  29. COMMAND bash "-c" "cat /etc/os-release | grep ^ID= | awk -F '=' '{print $2}'"
  30. OUTPUT_VARIABLE SYSTEM_TYPE
  31. )
  32. MESSAGE(STATUS "System type: ${SYSTEM_TYPE}.")
  33. endif()
  34. # download json headers, rather than whole repository
  35. include(${GE_SOURCE_DIR}/cmake/ge_utils.cmake)
  36. include(${GE_SOURCE_DIR}/cmake/external_libs/json.cmake)
  37. include(${GE_SOURCE_DIR}/cmake/external_libs/eigen.cmake)
  38. include(${GE_SOURCE_DIR}/cmake/external_libs/gtest.cmake)
  39. include(${GE_SOURCE_DIR}/cmake/external_libs/protobuf.cmake)
  40. include(${GE_SOURCE_DIR}/cmake/external_libs/onnx.cmake)
  41. set(CMAKE_SKIP_RPATH TRUE)
  42. # for CPU/GPU mode, find c_sec and slog from local prebuild
  43. if(NOT ENABLE_D AND NOT GE_ONLY)
  44. set(GE_PREBUILD_PATH ${GE_SOURCE_DIR}/third_party/prebuild/${CMAKE_HOST_SYSTEM_PROCESSOR})
  45. find_library(c_sec libc_sec.so ${GE_PREBUILD_PATH})
  46. find_library(slog libslog.so ${GE_PREBUILD_PATH})
  47. # if D_LINK_PATH is set in environment variables, search libraries in given path
  48. elseif(DEFINED ENV{D_LINK_PATH})
  49. # D_LINK_PATH is set
  50. set(GE_LIB_PATH $ENV{D_LINK_PATH})
  51. set(GE_SYS_ARCH "")
  52. if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
  53. # x86 ubuntu
  54. set(GE_SYS_ARCH "x86_64")
  55. elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
  56. # arm euleros
  57. set(GE_SYS_ARCH "aarch64")
  58. else()
  59. message(FATAL_ERROR "Running on a unsupported architecture: ${SYSTEM_TYPE}, build terminated")
  60. endif()
  61. set(GE_LIB_PATH ${GE_LIB_PATH}/${GE_SYS_ARCH})
  62. find_library(c_sec libc_sec.so ${GE_LIB_PATH})
  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. else()
  71. # Ascend mode
  72. if(DEFINED ENV{ASCEND_CUSTOM_PATH})
  73. set(ASCEND_DIR $ENV{ASCEND_CUSTOM_PATH})
  74. else()
  75. set(ASCEND_DIR /usr/local/Ascend)
  76. endif()
  77. set(ASCEND_DRIVER_DIR ${ASCEND_DIR}/driver/lib64/common)
  78. set(ASCEND_RUNTIME_DIR ${ASCEND_DIR}/fwkacllib/lib64)
  79. find_library(c_sec libc_sec.so ${ASCEND_DRIVER_DIR})
  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. endif()
  88. # add compile flags
  89. include(CheckCXXCompilerFlag)
  90. check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
  91. if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  92. message("Build in Debug mode")
  93. set(CMAKE_C_FLAGS "-O0 -g -Wall -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe -fPIC ${CMAKE_C_FLAGS}")
  94. set(CMAKE_CXX_FLAGS "-O0 -g -Wall -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe -fPIC ${CMAKE_CXX_FLAGS}")
  95. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  96. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic")
  97. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
  98. endif()
  99. else()
  100. set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe ${CMAKE_C_FLAGS}")
  101. set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe ${CMAKE_CXX_FLAGS}")
  102. endif ()
  103. # force __FILE__ to show relative path of file, from source directory, as cmake project makes __FILE__ absolute directory
  104. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILE__='\"$(subst $(realpath ${CMAKE_SOURCE_DIR})/,,$(abspath $<))\"' -Wno-builtin-macro-redefined")
  105. # compile libraries from following directories
  106. # libgraph is compiled in any situation
  107. add_subdirectory(${GE_SOURCE_DIR}/src/common/graph)
  108. if(ENABLE_D)
  109. # if MindSpore compiles in D mode, compile the following libraries
  110. add_subdirectory(${GE_SOURCE_DIR}/src/ge/common)
  111. add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_runtime)
  112. elseif(GE_ONLY)
  113. # standalone GraphEngine compiles all following libraries
  114. add_subdirectory(${GE_SOURCE_DIR}/src/ge/common)
  115. add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_runtime)
  116. add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_local_engine)
  117. add_subdirectory(${GE_SOURCE_DIR}/src/ge/graph/build/memory)
  118. add_subdirectory(${GE_SOURCE_DIR}/src/ge/)
  119. add_subdirectory(${GE_SOURCE_DIR}/src/ge/executor)
  120. add_subdirectory(${GE_SOURCE_DIR}/src/ge/client)
  121. add_subdirectory(${GE_SOURCE_DIR}/src/ge/plugin/engine)
  122. endif()
  123. if (ENABLE_GE_COV OR ENABLE_GE_UT OR ENABLE_GE_ST)
  124. add_subdirectory(tests)
  125. endif()

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