compile cuda_ops.so for cuda10.1

Signed-off-by: zhoufeng <zhoufeng54@huawei.com>
This commit is contained in:
zhoufeng 2023-02-27 20:58:42 +08:00
parent 81e98d3f82
commit 5b5cb2fcf8
5 changed files with 34 additions and 16 deletions

View File

@ -184,9 +184,10 @@ if(ENABLE_GPU)
endif() endif()
endif() endif()
install( install(
TARGETS cuda_ops TARGETS cuda_ops LIBRARY
DESTINATION ${INSTALL_PLUGIN_DIR}/gpu${CUDA_VERSION} DESTINATION ${INSTALL_PLUGIN_DIR}/gpu${CUDA_VERSION}
COMPONENT mindspore COMPONENT mindspore
NAMELINK_SKIP
) )
endif() endif()

View File

@ -89,9 +89,10 @@ if(ENABLE_GPU)
endif() endif()
endif() endif()
install( install(
TARGETS cuda_ops TARGETS cuda_ops LIBRARY
DESTINATION ${INSTALL_PLUGIN_DIR}/gpu${CUDA_VERSION} DESTINATION ${INSTALL_PLUGIN_DIR}/gpu${CUDA_VERSION}
COMPONENT mindspore COMPONENT mindspore
NAMELINK_SKIP
) )
endif() endif()

View File

@ -59,18 +59,16 @@ function(set_nvcc_flag CUDA_NVCC_FLAGS)
list(APPEND cuda_archs_bin ${arch_bin}) list(APPEND cuda_archs_bin ${arch_bin})
endforeach() endforeach()
else() else()
message("Failed to detect gpu arch automatically, build a base arch 5.3.") message("Failed to detect gpu arch automatically, build a base arch 6.0.")
list(APPEND CUDA_NVCC_FLAGS -arch=sm_53) list(APPEND CUDA_NVCC_FLAGS -arch=sm_60)
endif() endif()
# Get build flag from env to choose common/auto build. # Get build flag from env to choose common/auto build.
set(NVCC_ARCH_FLAG_FROM_ENV $ENV{CUDA_ARCH}) set(NVCC_ARCH_FLAG_FROM_ENV $ENV{CUDA_ARCH})
if(NVCC_ARCH_FLAG_FROM_ENV STREQUAL "common") if(NVCC_ARCH_FLAG_FROM_ENV STREQUAL "common")
message("Build common archs for release.") message("Build common archs for release.")
list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_53,code=sm_53 list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_70,code=sm_70)
-gencode=arch=compute_72,code=sm_72)
if(${CUDA_VERSION} VERSION_GREATER "9.5") if(${CUDA_VERSION} VERSION_GREATER "9.5")
list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_75,code=sm_75) list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_75,code=sm_75)
if(${CUDA_VERSION} VERSION_LESS "11.0") if(${CUDA_VERSION} VERSION_LESS "11.0")
@ -93,9 +91,9 @@ function(set_nvcc_flag CUDA_NVCC_FLAGS)
foreach(arch ${cuda_archs_bin}) foreach(arch ${cuda_archs_bin})
list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_${arch},code=sm_${arch}) list(APPEND CUDA_NVCC_FLAGS -gencode=arch=compute_${arch},code=sm_${arch})
endforeach() 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. # 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() endif()
list(REMOVE_DUPLICATES CUDA_NVCC_FLAGS) list(REMOVE_DUPLICATES CUDA_NVCC_FLAGS)
message("Final CUDA_NVCC_FLASG " ${CUDA_NVCC_FLAGS}) message("Final CUDA_NVCC_FLASG " ${CUDA_NVCC_FLAGS})

View File

@ -34,6 +34,9 @@ if(ENABLE_GPU)
target_compile_options(cuda_common_obj PRIVATE "/std:c++17") target_compile_options(cuda_common_obj PRIVATE "/std:c++17")
endif() endif()
cuda_add_library(cuda_ops SHARED ${CUDA_OPS_SRC_LIST} $<TARGET_OBJECTS:cuda_common_obj>) cuda_add_library(cuda_ops SHARED ${CUDA_OPS_SRC_LIST} $<TARGET_OBJECTS:cuda_common_obj>)
if(NOT BUILD_LITE)
set_target_properties(cuda_ops PROPERTIES SOVERSION ${CUDA_VERSION_MAJOR})
endif()
if(NOT MSVC) if(NOT MSVC)
target_link_options(cuda_ops PRIVATE "-Wl,--allow-shlib-undefined") target_link_options(cuda_ops PRIVATE "-Wl,--allow-shlib-undefined")
else() else()

View File

@ -28,6 +28,7 @@ for whl in "$@"; do
done done
MAX_GPU_VERSION=0 MAX_GPU_VERSION=0
declare -A GPU_VERSION_MAP
for ((i=1;i<$counter;i=$i+1)) for ((i=1;i<$counter;i=$i+1))
do do
echo "Rename $i dirname to mindspore ..." echo "Rename $i dirname to mindspore ..."
@ -50,18 +51,32 @@ do
fi; fi;
CUR_GPU_VERSION=`find "./$i/mindspore/lib/plugin" -name 'gpu*' -exec sh -c 'echo ${0##*gpu}' {} \;` CUR_GPU_VERSION=`find "./$i/mindspore/lib/plugin" -name 'gpu*' -exec sh -c 'echo ${0##*gpu}' {} \;`
if [ -n "$CUR_GPU_VERSION" ]; then 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 if [ "`echo "$CUR_GPU_VERSION > $MAX_GPU_VERSION" | bc`" -eq 1 ]; then
MAX_GPU_VERSION=$CUR_GPU_VERSION MAX_GPU_VERSION=$CUR_GPU_VERSION
fi;
if [ ! -d "$BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu" ]; then if [ ! -d "$BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu" ]; then
mkdir -p $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu mkdir -p $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu
fi; fi;
\cp -rf ./$i/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu \cp -rf ./$i/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/$CUDA_OPS_FILE \
fi; $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu/$CUDA_OPS_FILE
rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so
fi; fi;
rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so*
rm -rf $i rm -rf $i
done done
export COMMIT_ID=`cat $BASE_PACKAGE_UNZIP_DIR/mindspore/.commit_id | awk '{print $3}' | sed $'s/\'//g'` 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'` VERSION=`cat $BASE_PACKAGE_UNZIP_DIR/mindspore/version.py | awk '{print $3}' | sed $'s/\'//g'`
echo -n "$VERSION" > $MINDSPORE_ROOT_PATH/version.txt echo -n "$VERSION" > $MINDSPORE_ROOT_PATH/version.txt