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

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. ## common setting
  2. include_directories(${CMAKE_SOURCE_DIR}/mindspore/core)
  3. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  4. include_directories(${CMAKE_BINARY_DIR})
  5. link_directories(${CMAKE_SOURCE_DIR}/build/mindspore/graphengine)
  6. if (CMAKE_SYSTEM_NAME MATCHES "Windows")
  7. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -DHAVE_SNPRINTF")
  8. add_compile_definitions(BUILDING_DLL)
  9. endif()
  10. if (ENABLE_MPI)
  11. add_compile_definitions(ENABLE_MPI)
  12. endif ()
  13. if(ENABLE_GPU)
  14. find_package(CUDA REQUIRED)
  15. find_package(Threads)
  16. if(${CUDA_VERSION} VERSION_LESS ${MS_REQUIRE_CUDA_VERSION})
  17. message(FATAL_ERROR "The minimum CUDA version ${MS_REQUIRE_CUDA_VERSION} is required, but only CUDA ${CUDA_VERSION} found.")
  18. endif()
  19. enable_language(CUDA)
  20. if(NOT CUDA_PATH OR CUDA_PATH STREQUAL "")
  21. if(DEFINED ENV{CUDA_HOME} AND NOT $ENV{CUDA_HOME} STREQUAL "")
  22. set(CUDA_PATH $ENV{CUDA_HOME})
  23. else()
  24. set(CUDA_PATH ${CUDA_TOOLKIT_ROOT_DIR})
  25. endif()
  26. endif()
  27. if (DEFINED ENV{CUDNN_HOME} AND NOT $ENV{CUDNN_HOME} STREQUAL "")
  28. set(CUDNN_INCLUDE_DIR $ENV{CUDNN_HOME}/include)
  29. set(CUDNN_LIBRARY_DIR $ENV{CUDNN_HOME}/lib64)
  30. find_path(CUDNN_INCLUDE_PATH cudnn.h HINTS ${CUDNN_INCLUDE_DIR} NO_DEFAULT_PATH)
  31. find_library(CUDNN_LIBRARY_PATH "cudnn" HINTS ${CUDNN_LIBRARY_DIR} NO_DEFAULT_PATH)
  32. if (CUDNN_INCLUDE_PATH STREQUAL CUDNN_INCLUDE_PATH-NOTFOUND)
  33. message(FATAL_ERROR "Failed to find cudnn header file, please set environment variable CUDNN_HOME to cudnn installation position.")
  34. endif()
  35. if (CUDNN_LIBRARY_PATH STREQUAL CUDNN_LIBRARY_PATH-NOTFOUND)
  36. message(FATAL_ERROR "Failed to find cudnn library file, please set environment variable CUDNN_HOME to cudnn installation position.")
  37. endif()
  38. else()
  39. list(APPEND CMAKE_PREFIX_PATH ${CUDA_TOOLKIT_ROOT_DIR})
  40. find_path(CUDNN_INCLUDE_PATH cudnn.h PATH_SUFFIXES cuda/inclulde include cuda)
  41. find_library(CUDNN_LIBRARY_PATH "cudnn" PATH_SUFFIXES cuda/lib64 lib64 lib cuda/lib lib/x86_64-linux-gnu)
  42. if (CUDNN_INCLUDE_PATH STREQUAL CUDNN_INCLUDE_PATH-NOTFOUND)
  43. message(FATAL_ERROR "Failed to find cudnn header file, if cudnn library is not installed, please put cudnn header file in cuda include path \
  44. or user include path(eg. /usr/local/cuda/include; /usr/local/include; /usr/include), if cudnn library is installed in other position,\
  45. please set environment variable CUDNN_HOME to cudnn installation position, there should be cudnn.h in {CUDNN_HOME}/include.")
  46. endif()
  47. if (CUDNN_LIBRARY_PATH STREQUAL CUDNN_LIBRARY_PATH-NOTFOUND)
  48. message(FATAL_ERROR "Failed to find cudnn library file, if cudnn library is not installed, please put cudnn library file in \
  49. cuda library path or user library path(eg. /usr/local/cuda/lib64; /usr/local/lib64; /usr/lib64; /usr/local/lib; /usr/lib),\
  50. if cudnn library is installed in other position, please set environment variable CUDNN_HOME to cudnn installation position, \
  51. there should be cudnn library file in {CUDNN_HOME}/lib64.")
  52. endif()
  53. endif()
  54. if(NOT CUPTI_INCLUDE_DIRS OR CUPTI_INCLUDE_DIRS STREQUAL "")
  55. set(CUPTI_INCLUDE_DIRS ${CUDA_PATH}/extras/CUPTI/include)
  56. endif()
  57. message("CUDA_PATH: ${CUDA_PATH}")
  58. message("CUDA_INCLUDE_DIRS: ${CUDA_INCLUDE_DIRS}")
  59. message("CUDNN_INCLUDE_PATH: ${CUDNN_INCLUDE_PATH}")
  60. message("CUDNN_LIBRARY_PATH: ${CUDNN_LIBRARY_PATH}")
  61. message("CUPTI_INCLUDE_DIRS: ${CUPTI_INCLUDE_DIRS}")
  62. include_directories(${CUDNN_INCLUDE_PATH} ${CUDA_PATH} ${CUDA_INCLUDE_DIRS} ${CUPTI_INCLUDE_DIRS})
  63. file(GLOB_RECURSE GPU_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  64. "runtime/device/gpu/*.cc"
  65. "runtime/device/gpu/*.cu"
  66. "backend/kernel_compiler/gpu/*.cu"
  67. "backend/kernel_compiler/akg/gpu/*.cc"
  68. "backend/kernel_compiler/akg/akg_kernel_json_generator.cc"
  69. "backend/kernel_compiler/akg/akg_kernel_json_decoder.cc"
  70. "backend/kernel_compiler/akg/akg_kernel_attrs_process.cc"
  71. )
  72. list(APPEND CUDA_NVCC_FLAGS -arch=sm_53 --expt-relaxed-constexpr)
  73. list(REMOVE_ITEM GPU_SRC_LIST "runtime/device/gpu/blocking_queue.cc" "runtime/device/gpu/gpu_buffer_mgr.cc")
  74. list(REMOVE_ITEM GPU_SRC_LIST "runtime/device/gpu/mpi/mpi_initializer.cc"
  75. "runtime/device/gpu/distribution/collective_wrapper.cc"
  76. "runtime/device/gpu/distribution/mpi_wrapper.cc"
  77. "runtime/device/gpu/distribution/nccl_wrapper.cc"
  78. )
  79. set(NVCC_TMP_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  80. string(REPLACE "-std=c++17" "-std=c++11" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  81. set_property(SOURCE ${GPU_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_DEVICE)
  82. cuda_add_library(gpu_cuda_lib STATIC ${GPU_SRC_LIST})
  83. set(CMAKE_CXX_FLAGS ${NVCC_TMP_CMAKE_CXX_FLAGS})
  84. add_compile_definitions(ENABLE_GPU)
  85. endif ()
  86. ## make protobuf files
  87. file(COPY "${ms_onnx_INC}/onnx/onnx.proto" DESTINATION ${CMAKE_BINARY_DIR}/proto)
  88. file(GLOB ONNX_PROTO "" ${CMAKE_BINARY_DIR}/proto/onnx.proto)
  89. message("onnx proto path is :" ${ONNX_PROTO})
  90. ms_protobuf_generate(ONNX_PROTO_SRCS ONNX_PROTO_HDRS ${ONNX_PROTO})
  91. list(APPEND MINDSPORE_PROTO_LIST ${ONNX_PROTO_SRCS})
  92. if (ENABLE_DEBUGGER)
  93. # debugger: compile proto files
  94. include_directories("${CMAKE_BINARY_DIR}/debug/debugger")
  95. file(GLOB_RECURSE DEBUGGER_PROTO_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "debug/debugger/debug_graph.proto")
  96. ms_protobuf_generate(DEBUGGER_PROTO_SRCS DEBUGGER_PROTO_HDRS ${DEBUGGER_PROTO_LIST})
  97. file(GLOB_RECURSE DEBUGGER_GRPC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "debug/debugger/debug_grpc.proto")
  98. ms_grpc_generate(DEBUGGER_GRPC_SRCS DEBUGGER_GRPC_HDRS ${DEBUGGER_GRPC_LIST})
  99. list(APPEND MINDSPORE_PROTO_LIST ${DEBUGGER_PROTO_SRCS})
  100. list(APPEND MINDSPORE_PROTO_LIST ${DEBUGGER_GRPC_SRCS})
  101. endif ()
  102. if (ENABLE_DUMP_PROTO)
  103. include_directories(${CMAKE_BINARY_DIR})
  104. file(GLOB_RECURSE PROTO_PY RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
  105. "utils/anf_ir.proto"
  106. "utils/summary.proto"
  107. "utils/lineage.proto"
  108. "utils/checkpoint.proto"
  109. "utils/print.proto"
  110. "utils/node_strategy.proto"
  111. )
  112. ms_protobuf_generate_py(PY_SRCS PY_HDRS PY_PYS ${PROTO_PY})
  113. list(APPEND MINDSPORE_PROTO_LIST ${PROTO_SRCS})
  114. list(APPEND MINDSPORE_PROTO_LIST ${PY_SRCS})
  115. endif ()
  116. if (ENABLE_D)
  117. include_directories("${CMAKE_BINARY_DIR}/backend/kernel_compiler/aicpu")
  118. file(GLOB_RECURSE PROTO_IN RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "backend/kernel_compiler/aicpu/proto/*.proto")
  119. ms_protobuf_generate(PROTOSRCS PROTOHDRS ${PROTO_IN})
  120. file(GLOB_RECURSE PROTO_DUMP RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "runtime/device/ascend/dump/proto/*.proto")
  121. ms_protobuf_generate(DUMP_PROTOSRCS PROTOHDRS ${PROTO_DUMP})
  122. list(APPEND MINDSPORE_PROTO_LIST ${PROTOSRCS})
  123. list(APPEND MINDSPORE_PROTO_LIST ${PREDICT_PROTOSRCS})
  124. list(APPEND MINDSPORE_PROTO_LIST ${DUMP_PROTOSRCS})
  125. add_compile_definitions(ENABLE_D)
  126. endif ()
  127. if (MINDSPORE_PROTO_LIST)
  128. add_library(proto_input STATIC ${MINDSPORE_PROTO_LIST})
  129. set_target_properties(proto_input PROPERTIES COMPILE_FLAGS "-Wno-unused-variable")
  130. endif()
  131. ## make sub objects
  132. set(SUB_COMP
  133. transform/graph_ir
  134. transform/onnx
  135. backend/optimizer
  136. backend/kernel_compiler
  137. backend/session
  138. runtime/device
  139. frontend/optimizer
  140. frontend/parallel
  141. frontend/operator
  142. pipeline/jit
  143. pipeline/pynative
  144. common debug pybind_api utils vm profiler ps
  145. )
  146. foreach (_comp ${SUB_COMP})
  147. add_subdirectory(${_comp})
  148. string(REPLACE "/" "_" sub ${_comp})
  149. if (TARGET _mindspore_${sub}_obj)
  150. list(APPEND SUB_OBJECTS_SRC $<TARGET_OBJECTS:_mindspore_${sub}_obj>)
  151. add_dependencies(_mindspore_${sub}_obj proto_input )
  152. endif ()
  153. endforeach ()
  154. set_property(SOURCE ${SUB_OBJECTS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ME)
  155. add_library(mindspore STATIC ${SUB_OBJECTS_SRC})
  156. target_link_libraries(mindspore mindspore_core)
  157. if (ENABLE_DEBUGGER)
  158. # debugger: link grpc
  159. target_link_libraries(proto_input mindspore::grpc++)
  160. endif()
  161. target_link_libraries(mindspore securec mindspore::flatbuffers)
  162. if (NOT WIN32)
  163. target_link_libraries(mindspore dl)
  164. endif()
  165. if (ENABLE_GE)
  166. if(ENABLE_TRAIN)
  167. target_link_libraries(mindspore ge_runner hccl)
  168. else ()
  169. target_link_libraries(mindspore ge_client)
  170. endif ()
  171. target_link_libraries(mindspore graph tsdclient datatransfer)
  172. endif()
  173. if (ENABLE_D)
  174. if (DEFINED ENV{D_LINK_PATH})
  175. if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
  176. MESSAGE("system processor matches aarch64")
  177. set(D_LIB_PATH $ENV{D_LINK_PATH}/aarch64)
  178. elseif (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
  179. MESSAGE("system processor matches x86_64")
  180. set(D_LIB_PATH $ENV{D_LINK_PATH}/x86_64)
  181. else ()
  182. MESSAGE("system ${CMAKE_HOST_SYSTEM_PROCESSOR} not support")
  183. endif()
  184. else ()
  185. MESSAGE("use system default lib")
  186. if (DEFINED ENV{ASCEND_CUSTOM_PATH})
  187. set(ASCEND_PATH $ENV{ASCEND_CUSTOM_PATH})
  188. else ()
  189. set(ASCEND_PATH /usr/local/Ascend)
  190. endif ()
  191. set(ASCEND_DRIVER_PATH ${ASCEND_PATH}/driver/lib64/common)
  192. set(ASCEND_DRIVER_BACK_PATH ${ASCEND_PATH}/driver/lib64/driver)
  193. set(ASCEND_RUNTIME_PATH ${ASCEND_PATH}/fwkacllib/lib64)
  194. set(ASCEND_OPP_PATH ${ASCEND_PATH}/opp/op_impl/built-in/ai_core/tbe/op_tiling)
  195. endif()
  196. MESSAGE("USE DAV LIB PATH: ${ASCEND_PATH}")
  197. find_library(HCCL hccl ${ASCEND_RUNTIME_PATH})
  198. find_library(CCE_LIB cce ${ASCEND_RUNTIME_PATH})
  199. find_library(RUNTIME_LIB runtime ${ASCEND_RUNTIME_PATH})
  200. find_library(TSDCLIENT tsdclient HINTS ${ASCEND_RUNTIME_PATH} ${ASCEND_DRIVER_BACK_PATH})
  201. find_library(DATATRANSFER datatransfer HINTS ${ASCEND_RUNTIME_PATH} ${ASCEND_DRIVER_BACK_PATH})
  202. find_library(PROFILING msprofiler ${ASCEND_RUNTIME_PATH})
  203. find_library(PROFILING_SHARED msprof ${ASCEND_DRIVER_PATH})
  204. find_library(OPTILING optiling ${ASCEND_OPP_PATH})
  205. target_link_libraries(mindspore ge_runtime ${CCE_LIB} ${RUNTIME_LIB} ${TSDCLIENT} ${HCCL} ${DATATRANSFER} ${OPTILING})
  206. target_link_libraries(mindspore -Wl,--start-group proto_input ${PROFILING_SHARED} ${PROFILING} mindspore::protobuf -Wl,--end-group)
  207. elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
  208. target_link_libraries(mindspore -Wl,--start-group proto_input mindspore::protobuf mindspore::sentencepiece -Wl,--end-group)
  209. else ()
  210. target_link_libraries(mindspore -Wl,--start-group proto_input mindspore::protobuf -Wl,--end-group)
  211. endif()
  212. # set c_expression building
  213. set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  214. set_property(SOURCE "pipeline/jit/init.cc" PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_PIPELINE)
  215. pybind11_add_module(_c_expression "pipeline/jit/init.cc")
  216. MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}")
  217. if (CMAKE_SYSTEM_NAME MATCHES "Linux")
  218. target_link_options(_c_expression PRIVATE -Wl,-init,mindspore_log_init)
  219. set(ORIGIN_PATH $ORIGIN)
  220. elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
  221. set_target_properties(_c_expression PROPERTIES MACOSX_RPATH ON)
  222. set(ORIGIN_PATH @loader_path)
  223. elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
  224. set(ORIGIN_PATH $ORIGIN)
  225. else ()
  226. MESSAGE(FATAL_ERROR "other platform: ${CMAKE_SYSTEM_NAME}")
  227. endif ()
  228. set(MINDSPORE_RPATH ${ORIGIN_PATH}/lib)
  229. if (ENABLE_D)
  230. set(MINDSPORE_RPATH ${MINDSPORE_RPATH}:/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64)
  231. set(MINDSPORE_RPATH ${MINDSPORE_RPATH}:/usr/local/Ascend/fwkacllib/lib64)
  232. set(MINDSPORE_RPATH ${MINDSPORE_RPATH}:/usr/local/Ascend/add-ons)
  233. set(MINDSPORE_RPATH ${MINDSPORE_RPATH}:/usr/local/Ascend/opp/op_impl/built-in/ai_core/tbe/op_tiling)
  234. elseif (ENABLE_GPU)
  235. set(MINDSPORE_RPATH ${MINDSPORE_RPATH}:/usr/local/cuda/lib64)
  236. endif ()
  237. set_target_properties(_c_expression PROPERTIES INSTALL_RPATH ${MINDSPORE_RPATH})
  238. if (CMAKE_SYSTEM_NAME MATCHES "Windows")
  239. target_link_libraries(mindspore mindspore::pybind11_module)
  240. target_link_libraries(mindspore mindspore_gvar)
  241. target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore -Wl,--no-whole-archive)
  242. else ()
  243. if (ENABLE_CPU AND (ENABLE_D OR ENABLE_GPU))
  244. target_link_libraries(mindspore mindspore::pslite mindspore::protobuf ${zeromq_DIRPATH}/zmq_install/lib/libzmq.a)
  245. if (${ENABLE_IBVERBS} STREQUAL "ON")
  246. target_link_libraries(mindspore ibverbs rdmacm)
  247. endif()
  248. endif()
  249. target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore proto_input -Wl,--no-whole-archive)
  250. target_link_libraries(_c_expression PRIVATE mindspore::pybind11_module)
  251. target_link_libraries(_c_expression PRIVATE mindspore_gvar)
  252. endif ()
  253. if (USE_GLOG)
  254. target_link_libraries(_c_expression PRIVATE mindspore::glog)
  255. endif ()
  256. if (ENABLE_GPU)
  257. message("add gpu lib to c_expression")
  258. target_link_libraries(_c_expression PRIVATE gpu_cuda_lib gpu_queue cublas
  259. ${CUDA_PATH}/lib64/libcurand.so
  260. ${CUDNN_LIBRARY_PATH}
  261. ${CUDA_PATH}/lib64/libcudart.so
  262. ${CUDA_PATH}/lib64/stubs/libcuda.so
  263. ${CUDA_PATH}/lib64/libcusolver.so)
  264. if (ENABLE_MPI)
  265. set_target_properties(_ms_mpi PROPERTIES INSTALL_RPATH ${MINDSPORE_RPATH})
  266. endif()
  267. endif ()
  268. if (ENABLE_CPU)
  269. target_link_libraries(_c_expression PRIVATE mindspore::dnnl mindspore::mkldnn)
  270. endif ()
  271. if (ENABLE_MINDDATA)
  272. add_subdirectory(minddata/mindrecord)
  273. add_subdirectory(minddata/dataset)
  274. endif ()
  275. # build inference
  276. set(LOAD_ONNX_SRC
  277. ${CMAKE_CURRENT_SOURCE_DIR}/utils/load_onnx/anf_converter.cc
  278. ${CMAKE_CURRENT_SOURCE_DIR}/utils/load_onnx/anf_model_parser.cc
  279. )
  280. add_library(inference SHARED
  281. ${CMAKE_CURRENT_SOURCE_DIR}/backend/session/infer_session.cc
  282. ${LOAD_ONNX_SRC}
  283. )
  284. set_target_properties(inference PROPERTIES INSTALL_RPATH ${MINDSPORE_RPATH})
  285. target_link_libraries(inference PRIVATE ${PYTHON_LIBRARIES} ${SECUREC_LIBRARY}
  286. -Wl,--whole-archive mindspore proto_input -Wl,--no-whole-archive mindspore_gvar)
  287. if (ENABLE_D)
  288. target_link_libraries(_c_expression PRIVATE ${ASCEND_PATH}/fwkacllib/lib64/libadump_server.a)
  289. target_link_libraries(inference PRIVATE ${ASCEND_PATH}/fwkacllib/lib64/libadump_server.a)
  290. endif()
  291. if (ENABLE_CPU)
  292. target_link_libraries(inference PRIVATE mindspore::dnnl mindspore::mkldnn)
  293. endif ()
  294. if (USE_GLOG)
  295. target_link_libraries(inference PRIVATE mindspore::glog)
  296. endif()
  297. if (CMAKE_SYSTEM_NAME MATCHES "Linux")
  298. target_link_options(inference PRIVATE -Wl,-init,common_log_init)
  299. elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
  300. set_target_properties(inference PROPERTIES MACOSX_RPATH ON)
  301. endif ()