From 5b5cb2fcf8618eee64d7821adb65e4626f81cbe3 Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Mon, 27 Feb 2023 20:58:42 +0800 Subject: [PATCH] compile cuda_ops.so for cuda10.1 Signed-off-by: zhoufeng --- cmake/package.cmake | 3 ++- cmake/package_plugin.cmake | 5 ++-- mindspore/ccsrc/CMakeLists.txt | 14 +++++------ .../gpu/kernel/cuda_impl/CMakeLists.txt | 3 +++ scripts/build/merge_whl_package.sh | 25 +++++++++++++++---- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/cmake/package.cmake b/cmake/package.cmake index 5bd3c01610e..9104f24c79b 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -184,9 +184,10 @@ if(ENABLE_GPU) endif() endif() install( - TARGETS cuda_ops + TARGETS cuda_ops LIBRARY DESTINATION ${INSTALL_PLUGIN_DIR}/gpu${CUDA_VERSION} COMPONENT mindspore + NAMELINK_SKIP ) endif() diff --git a/cmake/package_plugin.cmake b/cmake/package_plugin.cmake index e45ca525df3..97b5704a207 100644 --- a/cmake/package_plugin.cmake +++ b/cmake/package_plugin.cmake @@ -89,9 +89,10 @@ if(ENABLE_GPU) endif() endif() install( - TARGETS cuda_ops + TARGETS cuda_ops LIBRARY DESTINATION ${INSTALL_PLUGIN_DIR}/gpu${CUDA_VERSION} COMPONENT mindspore + NAMELINK_SKIP ) endif() @@ -117,7 +118,7 @@ if(ENABLE_SYM_FILE) install(CODE "\ execute_process(COMMAND ${CMAKE_COMMAND} -DMS_PACK_ROOT_DIR=${CPACK_PACKAGE_DIRECTORY} \ -DMS_INSTALL_DIR=${CPACK_PACKAGE_DIRECTORY}/_CPack_Packages/${CMAKE_HOST_SYSTEM_NAME}/${CPACK_GENERATOR} \ - -DMS_PACKAGE_FILE_NAME=${CPACK_PACKAGE_FILE_NAME} -P${CMAKE_SOURCE_DIR}/cmake/plugin_debuginfo_script.cmake)" + -DMS_PACKAGE_FILE_NAME=${CPACK_PACKAGE_FILE_NAME} -P ${CMAKE_SOURCE_DIR}/cmake/plugin_debuginfo_script.cmake)" ) endif() diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index b7534df8a5e..e4e79ebbb10 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -59,18 +59,16 @@ function(set_nvcc_flag CUDA_NVCC_FLAGS) list(APPEND cuda_archs_bin ${arch_bin}) endforeach() else() - message("Failed to detect gpu arch automatically, build a base arch 5.3.") - list(APPEND CUDA_NVCC_FLAGS -arch=sm_53) + message("Failed to detect gpu arch automatically, build a base arch 6.0.") + list(APPEND CUDA_NVCC_FLAGS -arch=sm_60) endif() # Get build flag from env to choose common/auto build. set(NVCC_ARCH_FLAG_FROM_ENV $ENV{CUDA_ARCH}) if(NVCC_ARCH_FLAG_FROM_ENV STREQUAL "common") message("Build common archs for release.") - list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_53,code=sm_53 - -gencode=arch=compute_60,code=sm_60 + list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61 - -gencode=arch=compute_70,code=sm_70 - -gencode=arch=compute_72,code=sm_72) + -gencode=arch=compute_70,code=sm_70) if(${CUDA_VERSION} VERSION_GREATER "9.5") list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_75,code=sm_75) if(${CUDA_VERSION} VERSION_LESS "11.0") @@ -93,9 +91,9 @@ function(set_nvcc_flag CUDA_NVCC_FLAGS) foreach(arch ${cuda_archs_bin}) list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_${arch},code=sm_${arch}) endforeach() - # For auto build, it only generate the code for indeed arch, so add sm_53 as a default arch + # For auto build, it only generate the code for indeed arch, so add sm_60 as a default arch # to avoid error in different archs. It may increase the compilation time. - list(APPEND CUDA_NVCC_FLAGS -arch=sm_53) + list(APPEND CUDA_NVCC_FLAGS -arch=sm_60) endif() list(REMOVE_DUPLICATES CUDA_NVCC_FLAGS) message("Final CUDA_NVCC_FLASG " ${CUDA_NVCC_FLAGS}) diff --git a/mindspore/ccsrc/plugin/device/gpu/kernel/cuda_impl/CMakeLists.txt b/mindspore/ccsrc/plugin/device/gpu/kernel/cuda_impl/CMakeLists.txt index 2b5bb9ecd63..7b3a55ad630 100644 --- a/mindspore/ccsrc/plugin/device/gpu/kernel/cuda_impl/CMakeLists.txt +++ b/mindspore/ccsrc/plugin/device/gpu/kernel/cuda_impl/CMakeLists.txt @@ -34,6 +34,9 @@ if(ENABLE_GPU) target_compile_options(cuda_common_obj PRIVATE "/std:c++17") endif() cuda_add_library(cuda_ops SHARED ${CUDA_OPS_SRC_LIST} $) + if(NOT BUILD_LITE) + set_target_properties(cuda_ops PROPERTIES SOVERSION ${CUDA_VERSION_MAJOR}) + endif() if(NOT MSVC) target_link_options(cuda_ops PRIVATE "-Wl,--allow-shlib-undefined") else() diff --git a/scripts/build/merge_whl_package.sh b/scripts/build/merge_whl_package.sh index d39d6eec07d..a93e073e88d 100755 --- a/scripts/build/merge_whl_package.sh +++ b/scripts/build/merge_whl_package.sh @@ -28,6 +28,7 @@ for whl in "$@"; do done MAX_GPU_VERSION=0 +declare -A GPU_VERSION_MAP for ((i=1;i<$counter;i=$i+1)) do echo "Rename $i dirname to mindspore ..." @@ -50,18 +51,32 @@ do fi; CUR_GPU_VERSION=`find "./$i/mindspore/lib/plugin" -name 'gpu*' -exec sh -c 'echo ${0##*gpu}' {} \;` if [ -n "$CUR_GPU_VERSION" ]; then + GPU_VERSION_MAP[$CUR_GPU_VERSION]=$i + else + rm -rf $i + fi; +done + +for key in $(for x in "${!GPU_VERSION_MAP[@]}"; do echo $x; done | sort) +do + i=${GPU_VERSION_MAP[$key]} + CUR_GPU_VERSION=$key + CUDA_OPS_FILE=`basename ./$i/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so*` + if [ "`echo "$CUR_GPU_VERSION > $MAX_GPU_VERSION" | bc`" -eq 1 ]; then if [ "`echo "$CUR_GPU_VERSION > $MAX_GPU_VERSION" | bc`" -eq 1 ]; then MAX_GPU_VERSION=$CUR_GPU_VERSION - if [ ! -d "$BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu" ]; then - mkdir -p $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu - fi; - \cp -rf ./$i/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu fi; - rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so + if [ ! -d "$BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu" ]; then + mkdir -p $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu + fi; + \cp -rf ./$i/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/$CUDA_OPS_FILE \ + $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu/$CUDA_OPS_FILE fi; + rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so* rm -rf $i done + export COMMIT_ID=`cat $BASE_PACKAGE_UNZIP_DIR/mindspore/.commit_id | awk '{print $3}' | sed $'s/\'//g'` VERSION=`cat $BASE_PACKAGE_UNZIP_DIR/mindspore/version.py | awk '{print $3}' | sed $'s/\'//g'` echo -n "$VERSION" > $MINDSPORE_ROOT_PATH/version.txt