diff --git a/cmake/external_libs/dmlc_core.cmake b/cmake/external_libs/dmlc_core.cmake index e07df83fd6e..386a52429d4 100644 --- a/cmake/external_libs/dmlc_core.cmake +++ b/cmake/external_libs/dmlc_core.cmake @@ -1,4 +1,4 @@ -mindspore_add_pkg(dmlc-core +mindspore_add_pkg(dmlc_core VER 0.3 HEAD_ONLY ./ URL https://github.com/dmlc/dmlc-core/archive/808f485387f9a03f78fa9f1159f387d0d91b7a28.zip diff --git a/cmake/external_libs/tvm_gpu.cmake b/cmake/external_libs/tvm_gpu.cmake index 2edec52ee1f..57a045cb035 100644 --- a/cmake/external_libs/tvm_gpu.cmake +++ b/cmake/external_libs/tvm_gpu.cmake @@ -1,16 +1,8 @@ -set(incubator_tvm_gpu_CFLAGS "-pipe -Wall -fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2") -set(incubator_tvm_gpu_CXXFLAGS "-std=c++11 -pipe -Wall -fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2") -set(USE_CUDA "ON") +set(incubator_tvm_gpu_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2") +set(incubator_tvm_gpu_CFLAGS "-D_FORTIFY_SOURCE=2 -O2") mindspore_add_pkg(incubator_tvm_gpu VER 0.6.0 - LIBS tvm + HEAD_ONLY ./ URL https://github.com/apache/incubator-tvm/archive/v0.6.0.tar.gz - MD5 9cbbd32545a776023acabbba270449fe - SUBMODULES ${dlpack_DIRPATH} ${dmlc-core_DIRPATH} ${rang_DIRPATH} - SOURCEMODULES topi/python/topi python/tvm - PATCHES ${CMAKE_SOURCE_DIR}/third_party/patch/incubator-tvm/find_library.patch - ${CMAKE_SOURCE_DIR}/third_party/patch/incubator-tvm/include.patch - ${CMAKE_SOURCE_DIR}/third_party/patch/incubator-tvm/src_pass.patch - CMAKE_OPTION -DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON) -include_directories(${incubator_tvm_gpu_INC}) -add_library(mindspore::tvm ALIAS incubator_tvm_gpu::tvm) + MD5 9cbbd32545a776023acabbba270449fe) + diff --git a/cmake/package.cmake b/cmake/package.cmake index d35ce0463b9..531dff29ca7 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -191,17 +191,11 @@ if (ENABLE_GPU) DESTINATION ${INSTALL_PY_DIR}/../ COMPONENT mindspore ) - if (EXISTS ${incubator_tvm_gpu_ROOT}) - file(GLOB_RECURSE GLOG_LIB_LIST ${incubator_tvm_gpu_LIBPATH}/lib*) - install( - FILES ${GLOG_LIB_LIST} - DESTINATION ${INSTALL_LIB_DIR} - COMPONENT mindspore - ) + if (EXISTS ${CMAKE_BINARY_DIR}/incubator-tvm) install( DIRECTORY - ${incubator_tvm_gpu_ROOT}/topi/python/topi - ${incubator_tvm_gpu_ROOT}/python/tvm + ${CMAKE_BINARY_DIR}/incubator-tvm/topi/python/topi + ${CMAKE_BINARY_DIR}/incubator-tvm/python/tvm DESTINATION ${INSTALL_PY_DIR}/../_akg COMPONENT mindspore ) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 501522a44b7..894a0de1b8d 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -206,7 +206,7 @@ function(mindspore_add_pkg pkg_name ) set(options ) set(oneValueArgs URL MD5 GIT_REPOSITORY GIT_TAG VER EXE DIR HEAD_ONLY CMAKE_PATH RELEASE LIB_PATH) - set(multiValueArgs CMAKE_OPTION LIBS PRE_CONFIGURE_COMMAND CONFIGURE_COMMAND BUILD_OPTION INSTALL_INCS INSTALL_LIBS PATCHES SUBMODULES SOURCEMODULES) + set(multiValueArgs CMAKE_OPTION LIBS PRE_CONFIGURE_COMMAND CONFIGURE_COMMAND BUILD_OPTION INSTALL_INCS INSTALL_LIBS PATCHES) cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) if (NOT PKG_LIB_PATH) @@ -270,21 +270,11 @@ function(mindspore_add_pkg pkg_name ) endif () if (NOT PKG_DIR) - if (PKG_GIT_REPOSITORY) - __download_pkg_with_git(${pkg_name} ${PKG_GIT_REPOSITORY} ${PKG_GIT_TAG} ${PKG_MD5}) - else() + if (PKG_GIT_REPOSITORY) + __download_pkg_with_git(${pkg_name} ${PKG_GIT_REPOSITORY} ${PKG_GIT_TAG} ${PKG_MD5}) + else() __download_pkg(${pkg_name} ${PKG_URL} ${PKG_MD5}) - endif() - foreach(_SUBMODULE_FILE ${PKG_SUBMODULES}) - STRING( REGEX REPLACE "(.+)_(.+)" "\\1" _SUBMODEPATH ${_SUBMODULE_FILE}) - STRING( REGEX REPLACE "(.+)/(.+)" "\\2" _SUBMODENAME ${_SUBMODEPATH}) - file(GLOB ${pkg_name}_INSTALL_SUBMODULE ${_SUBMODULE_FILE}/*) - file(COPY ${${pkg_name}_INSTALL_SUBMODULE} DESTINATION ${${pkg_name}_SOURCE_DIR}/3rdparty/${_SUBMODENAME}) - endforeach (_SUBMODULE_FILE) - foreach(_SOURCE_DIR ${PKG_SOURCEMODULES}) - file(GLOB ${pkg_name}_INSTALL_SOURCE ${${pkg_name}_SOURCE_DIR}/${_SOURCE_DIR}/*) - file(COPY ${${pkg_name}_INSTALL_SOURCE} DESTINATION ${${pkg_name}_BASE_DIR}/${_SOURCE_DIR}/) - endforeach (_SUBMODULE_FILE) + endif() else() set(${pkg_name}_SOURCE_DIR ${PKG_DIR}) endif () diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index 8c33b9051c5..9b615b0dadf 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -395,7 +395,114 @@ if(USE_GLOG) endif() if(ENABLE_GPU) - target_link_libraries(_c_expression PRIVATE mindspore::tvm) + execute_process(COMMAND bash ${CMAKE_SOURCE_DIR}/third_party/apply_patches.sh + ${CMAKE_BINARY_DIR} + ${dlpack_DIRPATH} + ${dmlc_core_DIRPATH} + ${rang_DIRPATH} + ${incubator_tvm_gpu_DIRPATH}) + set(TVM_DIR "${CMAKE_BINARY_DIR}/incubator-tvm") + # Utility functions + include(${TVM_DIR}/cmake/util/Util.cmake) + include(${TVM_DIR}/cmake/util/FindCUDA.cmake) + + # include directories + include_directories(AFTER "${TVM_DIR}/include") + include_directories(AFTER "${TVM_DIR}/src") + include_directories(AFTER "${TVM_DIR}") + include_directories(AFTER "${TVM_DIR}/src/schedule") + + include_directories(AFTER "${TVM_DIR}/3rdparty/dmlc-core/include") + include_directories(AFTER "${TVM_DIR}/3rdparty/dlpack/include") + include_directories(AFTER "${TVM_DIR}/3rdparty/compiler-rt") + include_directories(AFTER "${TVM_DIR}/3rdparty/rang/include") + + # lib contain dlopen and dlclose + set(TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS}) + + # add source group + file(GLOB_RECURSE GROUP_SOURCE "${TVM_DIR}/src/*.cc" "src/*.cc") + file(GLOB_RECURSE GROUP_INCLUDE "${TVM_DIR}/src/*.h" + "${TVM_DIR}/include/*.h" "src/*.h" "include/*.h") + assign_source_group("Source" ${GROUP_SOURCE}) + assign_source_group("Include" ${GROUP_INCLUDE}) + + file(GLOB COMPILER_SRCS + "pre_activate/gpu/*.cc" + ${TVM_DIR}/src/api/*.cc + ${TVM_DIR}/src/arithmetic/*.cc + ${TVM_DIR}/src/autotvm/*.cc + ${TVM_DIR}/src/codegen/*.cc + ${TVM_DIR}/src/lang/*.cc + ${TVM_DIR}/src/pass/*.cc + ${TVM_DIR}/src/op/*.cc + ${TVM_DIR}/src/node/*.cc + ${TVM_DIR}/src/schedule/*.cc + ${TVM_DIR}/src/runtime/*.cc + ${TVM_DIR}/src/runtime/vm/*.cc + ${TVM_DIR}/src/runtime/vm/profiler/*.cc + ${TVM_DIR}/src/codegen/stackvm/*.cc) + + file(GLOB_RECURSE RELAY_SRCS ${TVM_DIR}/src/relay/*.cc) + list(APPEND COMPILER_SRCS ${RELAY_SRCS}) + + file(GLOB DATATYPE_SRCS ${TVM_DIR}/src/codegen/datatype/*.cc) + list(APPEND COMPILER_SRCS ${DATATYPE_SRCS}) + + file(GLOB COMPILER_VERILOG_SRCS ${TVM_DIR}/src/codegen/verilog/*.cc) + list(APPEND COMPILER_SRCS ${COMPILER_VERILOG_SRCS}) + + file(GLOB TOPI_SRCS ${TVM_DIR}/topi/src/*.cc) + + file(GLOB RUNTIME_SRCS + ${TVM_DIR}/src/runtime/*.cc + ${TVM_DIR}/src/runtime/vm/*.cc + ${TVM_DIR}/src/runtime/stub/*.cc + ${TVM_DIR}/src/runtime/stackvm/*.cc) + + + file(GLOB COMPILER_OFF_SRCS + ${TVM_DIR}/src/codegen/opt/build_*_off.cc) + set(USE_CUDA "OFF") + if(ENABLE_GPU) + list(REMOVE_ITEM COMPILER_OFF_SRCS + ${TVM_DIR}/src/codegen/opt/build_cuda_off.cc) + set(USE_CUDA "ON") + endif() + list(APPEND COMPILER_SRCS ${COMPILER_OFF_SRCS}) + # Module rules + include(${TVM_DIR}/cmake/modules/CUDA.cmake) + + set(CMAKE_C_FLAGS_AKG -pipe -Wall -fPIC -fstack-protector-all) + set(CMAKE_C_FLAGS_AKG ${CMAKE_C_FLAGS_AKG} -Wl,-z,relro,-z,now,-z,noexecstack) + + set(CMAKE_CXX_FLAGS_AKG -std=c++11 -pipe -Wall -fPIC -fstack-protector-all) + set(CMAKE_CXX_FLAGS_AKG ${CMAKE_CXX_FLAGS_AKG} -Wl,-z,relro,-z,now,-z,noexecstack) + + if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + message("-- Build in Debug mode") + set(CMAKE_C_FLAGS_AKG ${CMAKE_C_FLAGS_AKG} -O0 -g -rdynamic) + set(CMAKE_CXX_FLAGS_AKG ${CMAKE_CXX_FLAGS_AKG} -O0 -g -rdynamic) + else() + message("-- Build in Release mode") + set(CMAKE_C_FLAGS_AKG ${CMAKE_C_FLAGS_AKG} -O2 -Werror) + set(CMAKE_CXX_FLAGS_AKG ${CMAKE_CXX_FLAGS_AKG} -O2 -Werror) + endif() + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION + VERSION_GREATER 7.0) + set(CMAKE_CXX_FLAGS_AKG ${CMAKE_CXX_FLAGS_AKG} -faligned-new) + endif() + + add_library(akg OBJECT ${COMPILER_SRCS} ${RUNTIME_SRCS} ${TOPI_SRCS}) + + target_link_libraries(akg ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) + target_compile_options(akg PRIVATE + $<$:${CMAKE_C_FLAGS_AKG}> + $<$:${CMAKE_CXX_FLAGS_AKG}>) + target_include_directories(akg PRIVATE "${TVM_DIR}/topi/include") + + add_dependencies(_c_expression akg) + target_link_libraries(_c_expression PRIVATE akg) endif() if(ENABLE_DUMP_PROTO)