#!/bin/bash # ---------------------------------------------------------------------------- # Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ---------------------------------------------------------------------------- if [ "$(id -u)" != "0" ]; then _LOG_PATH=$(echo "${HOME}")"/var/log/ascend_seclog" _INSTALL_LOG_FILE="${_LOG_PATH}/ascend_install.log" _OPERATE_LOG_FILE="${_LOG_PATH}/operation.log" else _LOG_PATH="/var/log/ascend_seclog" _INSTALL_LOG_FILE="${_LOG_PATH}/ascend_install.log" _OPERATE_LOG_FILE="${_LOG_PATH}/operation.log" fi # log functions getdate() { _cur_date=$(date +"%Y-%m-%d %H:%M:%S") echo "${_cur_date}" } logandprint() { is_error_level=$(echo $1 | grep -E 'ERROR|WARN|INFO') if [ "${is_quiet}" != "y" ] || [ "${is_error_level}" != "" ]; then echo "[Opp] [$(getdate)] ""$1" fi echo "[Opp] [$(getdate)] ""$1" >> "${_INSTALL_LOG_FILE}" } # create opapi soft link createrelativelysoftlink() { local src_path_="$1" local dst_path_="$2" local dst_parent_path_=$(dirname ${dst_path_}) # echo "dst_parent_path_: ${dst_parent_path_}" local relative_path_=$(realpath --relative-to="$dst_parent_path_" "$src_path_") # echo "relative_path_: ${relative_path_}" if [ -L "$2" ]; then logandprint "[WARNING]: Soft link for ops is existed. Cannot create new soft link." return 0 fi ln -s "${relative_path_}" "${dst_path_}" 2> /dev/null if [ "$?" != "0" ]; then return 1 else return 0 fi } createopapisoftlink() { architecture=$(uname -m) architectureDir="${architecture}-linux" osName="" if [ -f "$1/opp/scene.info" ]; then . $1/opp/scene.info osName=${os} fi opapi_lib_path="$1/opp/built-in/op_impl/ai_core/tbe/op_api/lib/${osName}/${architecture}" opapi_include_level1_path="$1/opp/built-in/op_impl/ai_core/tbe/op_api/include/aclnnop" opapi_include_level2_path="${opapi_include_level1_path}/level2" ascend_path="" if [ "x$2" = "x" ]; then ascend_path=$1 else ascend_path=$(dirname $1) fi # first the libopapi.so if [ -d $1/${architectureDir}/lib64 ]; then arch_lib64_src_path="${opapi_lib_path}/libopapi.so" arch_lib64_dst_path="$1/${architectureDir}/lib64/libopapi.so" arch_lib64_mod_num=$(stat -c %a "$1/${architectureDir}/lib64") chmod -R 755 "$1/${architectureDir}/lib64" > /dev/null 2>&1 if [ -f $arch_lib64_dst_path ] || [ -L $arch_lib64_dst_path ]; then rm -fr "$arch_lib64_dst_path" fi createrelativelysoftlink ${arch_lib64_src_path} ${arch_lib64_dst_path} chmod -R ${arch_lib64_mod_num} "$1/${architectureDir}/lib64" > /dev/null 2>&1 fi if [ -d $1/opp/lib64 ]; then opp_lib64_src_path="${arch_lib64_dst_path}" opp_lib64_dst_path="$1/opp/lib64/libopapi.so" opp_lib64_mod_num=$(stat -c %a "$1/opp/lib64") chmod -R 755 "$1/opp/lib64" > /dev/null 2>&1 if [ -f $opp_lib64_dst_path ] || [ -L $opp_lib64_dst_path ]; then rm -fr "$opp_lib64_dst_path" fi createrelativelysoftlink ${opp_lib64_src_path} ${opp_lib64_dst_path} chmod -R ${opp_lib64_mod_num} "$1/opp/lib64" > /dev/null 2>&1 fi if [ -d ${ascend_path}/latest/${architectureDir}/lib64 ]; then latest_arch_lib64_src_path="${arch_lib64_dst_path}" latest_arch_lib64_dst_path="${ascend_path}/latest/${architectureDir}/lib64/libopapi.so" lastest_arch_lib64_mod_num=$(stat -c %a "${ascend_path}/latest/${architectureDir}/lib64") chmod -R 755 "${ascend_path}/latest/${architectureDir}/lib64" > /dev/null 2>&1 if [ -f $latest_arch_lib64_dst_path ] || [ -L $latest_arch_lib64_dst_path ]; then rm -fr "$latest_arch_lib64_dst_path" fi createrelativelysoftlink ${latest_arch_lib64_src_path} ${latest_arch_lib64_dst_path} chmod -R ${lastest_arch_lib64_mod_num} "${ascend_path}/latest/${architectureDir}/lib64" > /dev/null 2>&1 fi # second the headfiles with 1 and 2 level if [ -d $1/${architectureDir}/include/aclnnop ]; then arch_include_mod_num=$(stat -c %a "$1/${architectureDir}/include/aclnnop") opp_include_mod_num=$(stat -c %a "$1/opp/include/aclnnop") chmod -R 755 "$1/${architectureDir}/include/aclnnop" > /dev/null 2>&1 chmod -R 755 "$1/opp/include/aclnnop" > /dev/null 2>&1 for file_level1 in $(ls -1 -F ${opapi_include_level1_path} | grep -v [/$]) do arch_include_src_path="${opapi_include_level1_path}/${file_level1}" arch_include_dst_path="$1/${architectureDir}/include/aclnnop/${file_level1}" if [ -f $arch_include_dst_path ] || [ -L $arch_include_dst_path ]; then rm -fr "$arch_include_dst_path" fi createrelativelysoftlink ${arch_include_src_path} ${arch_include_dst_path} opp_include_src_path="${arch_include_dst_path}" opp_include_dst_path="$1/opp/include/aclnnop/${file_level1}" if [ -f $opp_include_dst_path ] || [ -L $opp_include_dst_path ]; then rm -fr "$opp_include_dst_path" fi createrelativelysoftlink ${opp_include_src_path} ${opp_include_dst_path} done chmod -R ${arch_include_mod_num} "$1/${architectureDir}/include/aclnnop" > /dev/null 2>&1 chmod -R ${opp_include_mod_num} "$1/opp/include/aclnnop" > /dev/null 2>&1 if [ -d ${ascend_path}/latest/${architectureDir}/include/aclnnop ]; then latest_arch_include_mod_num=$(stat -c %a "${ascend_path}/latest/${architectureDir}/include/aclnnop") chmod -R 755 "${ascend_path}/latest/${architectureDir}/include/aclnnop" > /dev/null 2>&1 for file_level1 in $(ls -1 -F ${opapi_include_level1_path} | grep -v [/$]) do arch_include_dst_path="$1/${architectureDir}/include/aclnnop/${file_level1}" latest_arch_include_src_path="${arch_include_dst_path}" latest_arch_include_dst_path="${ascend_path}/latest/${architectureDir}/include/aclnnop/${file_level1}" if [ -f $latest_arch_include_dst_path ] || [ -L $latest_arch_include_dst_path ]; then rm -fr "$latest_arch_include_dst_path" fi createrelativelysoftlink ${latest_arch_include_src_path} ${latest_arch_include_dst_path} done chmod -R ${latest_arch_include_mod_num} "${ascend_path}/latest/${architectureDir}/include/aclnnop" > /dev/null 2>&1 fi fi if [ -d $1/${architectureDir}/include/aclnnop/level2 ]; then arch_include_level2_mod_num=$(stat -c %a "$1/${architectureDir}/include/aclnnop/level2") opp_include_level2_mod_num=$(stat -c %a "$1/opp/include/aclnnop/level2") chmod -R 755 "$1/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 chmod -R 755 "$1/opp/include/aclnnop/level2" > /dev/null 2>&1 for file_level2 in $(ls -1 -F ${opapi_include_level2_path} | grep -v [/$]) do arch_include_src_path="${opapi_include_level2_path}/${file_level2}" arch_include_dst_path="$1/${architectureDir}/include/aclnnop/level2/${file_level2}" if [ -f $arch_include_dst_path ] || [ -L $arch_include_dst_path ]; then rm -fr "$arch_include_dst_path" fi createrelativelysoftlink ${arch_include_src_path} ${arch_include_dst_path} opp_include_src_path="${arch_include_dst_path}" opp_include_dst_path="$1/opp/include/aclnnop/level2/${file_level2}" if [ -f $opp_include_dst_path ] || [ -L $opp_include_dst_path ]; then rm -fr "$opp_include_dst_path" fi createrelativelysoftlink ${opp_include_src_path} ${opp_include_dst_path} done chmod -R ${arch_include_level2_mod_num} "$1/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 chmod -R ${opp_include_level2_mod_num} "$1/opp/include/aclnnop/level2" > /dev/null 2>&1 if [ -d ${ascend_path}/latest/${architectureDir}/include/aclnnop ]; then latest_arch_include_level2_mod_num=$(stat -c %a "${ascend_path}/latest/${architectureDir}/include/aclnnop/level2") chmod -R 755 "${ascend_path}/latest/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 for file_level2 in $(ls -1 -F ${opapi_include_level2_path} | grep -v [/$]) do arch_include_dst_path="$1/${architectureDir}/include/aclnnop/level2/${file_level2}" latest_arch_include_src_path="${arch_include_dst_path}" latest_arch_include_dst_path="${ascend_path}/latest/${architectureDir}/include/aclnnop/level2/${file_level2}" if [ -f $latest_arch_include_dst_path ] || [ -L $latest_arch_include_dst_path ]; then rm -fr "$latest_arch_include_dst_path" fi createrelativelysoftlink ${latest_arch_include_src_path} ${latest_arch_include_dst_path} done chmod -R ${latest_arch_include_level2_mod_num} "${ascend_path}/latest/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 fi fi } # remove opapi soft link removeopapisoftlink() { local path="$1" if [ -L "$1" ]; then rm -fr ${path} return 0 else return 1 fi } softlinksRemove() { architecture=$(uname -m) architectureDir="${architecture}-linux" osName="" if [ -f "$1/opp/scene.info" ]; then . $1/opp/scene.info osName=${os} fi opapi_lib_path="$1/opp/built-in/op_impl/ai_core/tbe/op_api/lib/${osName}/${architecture}" opapi_include_level1_path="$1/opp/built-in/op_impl/ai_core/tbe/op_api/include/aclnnop" opapi_include_level2_path="${opapi_include_level1_path}/level2" targetdir=$1 ascend_path="" if [ "x$2" = "x" ]; then ascend_path=${targetdir} else ascend_path=$(dirname ${targetdir}) fi # if latest opp_kernel softlink not exits, then remove opapi softlinks if [ ! -L "${ascend_path}/latest/opp_kernel" ]; then # first the libopapi.so if [ -d $targetdir/${architectureDir}/lib64 ]; then for file_so in $(ls -1 $targetdir/${architectureDir}/lib64 | egrep "libaclnn_|libopapi.so") do arch_lib64_path="$targetdir/${architectureDir}/lib64/${file_so}" arch_lib64_mod_num=$(stat -c %a "$targetdir/${architectureDir}/lib64") chmod -R 755 "$targetdir/${architectureDir}/lib64" > /dev/null 2>&1 removeopapisoftlink ${arch_lib64_path} chmod -R ${arch_lib64_mod_num} "$targetdir/${architectureDir}/lib64" > /dev/null 2>&1 done fi if [ -d $targetdir/opp/lib64 ]; then for file_so in $(ls -1 $targetdir/opp/lib64 | egrep "libaclnn_|libopapi.so") do opp_lib64_path="$targetdir/opp/lib64/${file_so}" opp_lib64_mod_num=$(stat -c %a "$targetdir/opp/lib64") chmod -R 755 "$targetdir/opp/lib64" > /dev/null 2>&1 removeopapisoftlink ${opp_lib64_path} chmod -R ${opp_lib64_mod_num} "$targetdir/opp/lib64" > /dev/null 2>&1 done fi if [ -d ${ascend_path}/latest/${architectureDir}/lib64 ]; then for file_so in $(ls -1 ${ascend_path}/latest/${architectureDir}/lib64 | egrep "libaclnn_|libopapi.so") do latest_arch_lib64_path="${ascend_path}/latest/${architectureDir}/lib64/${file_so}" latest_arch_lib64_mod_num=$(stat -c %a "${ascend_path}/latest/${architectureDir}/lib64") chmod -R 755 "${ascend_path}/latest/${architectureDir}/lib64" > /dev/null 2>&1 removeopapisoftlink ${latest_arch_lib64_path} chmod -R ${latest_arch_lib64_mod_num} "${ascend_path}/latest/${architectureDir}/lib64" > /dev/null 2>&1 done fi # second the headfiles with 1 and 2 level if [ -d $targetdir/${architectureDir}/include/aclnnop ]; then arch_include_mod_num=$(stat -c %a "$targetdir/${architectureDir}/include/aclnnop") opp_include_mod_num=$(stat -c %a "$targetdir/opp/include/aclnnop") chmod -R 755 "$targetdir/${architectureDir}/include/aclnnop" > /dev/null 2>&1 chmod -R 755 "$targetdir/opp/include/aclnnop" > /dev/null 2>&1 for file_level1 in $(ls -1 -F ${opapi_include_level1_path} | grep -v [/$]) do arch_include_path="$targetdir/${architectureDir}/include/aclnnop/${file_level1}" removeopapisoftlink ${arch_include_path} opp_include_path="$targetdir/opp/include/aclnnop/${file_level1}" removeopapisoftlink ${opp_include_path} done chmod -R ${arch_include_mod_num} "$targetdir/${architectureDir}/include/aclnnop" > /dev/null 2>&1 chmod -R ${opp_include_mod_num} "$targetdir/opp/include/aclnnop" > /dev/null 2>&1 if [ -d ${ascend_path}/latest/${architectureDir}/include/aclnnop ]; then latest_arch_inculde_mod_num=$(stat -c %a "${ascend_path}/latest/${architectureDir}/include/aclnnop") chmod -R 755 "${ascend_path}/latest/${architectureDir}/include/aclnnop" > /dev/null 2>&1 for file_level1 in $(ls -1 -F ${opapi_include_level1_path} | grep -v [/$]) do latest_arch_include_path="${ascend_path}/latest/${architectureDir}/include/aclnnop/${file_level1}" removeopapisoftlink ${latest_arch_include_path} done chmod -R ${latest_arch_inculde_mod_num} "${ascend_path}/latest/${architectureDir}/include/aclnnop" > /dev/null 2>&1 fi fi if [ -d $targetdir/${architectureDir}/include/aclnnop ]; then arch_include_level2_mod_num=$(stat -c %a "$targetdir/${architectureDir}/include/aclnnop/level2") opp_include_level2_mod_num=$(stat -c %a "$targetdir/opp/include/aclnnop/level2") chmod -R 755 "$targetdir/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 chmod -R 755 "$targetdir/opp/include/aclnnop/level2" > /dev/null 2>&1 for file_level2 in $(ls -1 -F ${opapi_include_level2_path} | grep -v [/$]) do arch_include_path="$targetdir/${architectureDir}/include/aclnnop/level2/${file_level2}" removeopapisoftlink ${arch_include_path} opp_include_path="$targetdir/opp/include/aclnnop/level2/${file_level2}" removeopapisoftlink ${opp_include_path} done chmod -R ${arch_include_level2_mod_num} "$targetdir/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 chmod -R ${opp_include_level2_mod_num} "$targetdir/opp/include/aclnnop/level2" > /dev/null 2>&1 if [ -d ${ascend_path}/latest/${architectureDir}/include/aclnnop ]; then latest_arch_inculde_level2_mod_num=$(stat -c %a "${ascend_path}/latest/${architectureDir}/include/aclnnop/level2") chmod -R 755 "${ascend_path}/latest/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 for file_level2 in $(ls -1 -F ${opapi_include_level2_path} | grep -v [/$]) do latest_arch_include_path="${ascend_path}/latest/${architectureDir}/include/aclnnop/level2/${file_level2}" removeopapisoftlink ${latest_arch_include_path} done chmod -R ${latest_arch_inculde_level2_mod_num} "${ascend_path}/latest/${architectureDir}/include/aclnnop/level2" > /dev/null 2>&1 fi fi fi }