1#!/bin/bash 2# Copyright 2022 Huawei Technologies Co., Ltd 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================ 16 17set -e 18BASEPATH=$(cd "$(dirname $0)"; pwd) 19MINDSPORE_ROOT_PATH=`realpath $BASEPATH/../../` 20BASE_PACKAGE_UNZIP_DIR=./0 21PACKAGE_FILE_NAME=`basename $1` 22 23counter=0 24for whl in "$@"; do 25 echo "Unzip $whl ..." 26 unzip -q $whl -d $counter 27 ((++counter)) 28done 29 30MAX_GPU_VERSION=0 31declare -A GPU_VERSION_MAP 32for ((i=1;i<$counter;i=$i+1)) 33do 34 echo "Rename $i dirname to mindspore ..." 35 mv ./$i/mindspore.py* "./$i/mindspore" 36 echo "Copy $i plugin files to 0 ..." 37 if [ -d "./$i/mindspore/lib/plugin" ]; then 38 \cp -rf ./$i/mindspore/lib/plugin/* $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin 39 fi; 40 if [ -f "./$i/mindspore/lib/libmpi_collective.so" ]; then 41 \cp -rf ./$i/mindspore/lib/libmpi_collective.so $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/ 42 fi; 43 if [ -f "./$i/mindspore/lib/libmpi_adapter.so" ]; then 44 \cp -rf ./$i/mindspore/lib/libmpi_adapter.so $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/ 45 fi; 46 if [ -f "./$i/mindspore/lib/libmindspore.so" ]; then 47 \cp -rf ./$i/mindspore/lib/libmindspore.so $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/ 48 fi; 49 if [ -f "./$i/mindspore/lib/libmindspore_shared_lib.so" ]; then 50 \cp -rf ./$i/mindspore/lib/libmindspore_shared_lib.so $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/ 51 fi; 52 53 # dataset library "mindspore/_c_dataengine.*.so" with 910b dvpp which is biggest should be used 54 file_size_src=`du ./$i/mindspore/_c_dataengine.*.so | awk '{print $1;}'` 55 file_size_dst=`du $BASE_PACKAGE_UNZIP_DIR/mindspore/_c_dataengine.*.so | awk '{print $1;}'` 56 echo "_c_dataengine.*.so, file_size_src: ${file_size_src}, file_size_dst: ${file_size_dst}" 57 if [ $file_size_src -gt $file_size_dst ]; then 58 \cp -rf ./$i/mindspore/_c_dataengine.*.so $BASE_PACKAGE_UNZIP_DIR/mindspore/ 59 fi; 60 61 CUR_GPU_VERSION=`find "./$i/mindspore/lib/plugin" -name 'gpu*' -exec sh -c 'echo ${0##*gpu}' {} \;` 62 if [ -n "$CUR_GPU_VERSION" ]; then 63 GPU_VERSION_MAP[$CUR_GPU_VERSION]=$i 64 else 65 rm -rf $i 66 fi; 67done 68 69for key in $(for x in "${!GPU_VERSION_MAP[@]}"; do echo $x; done | sort) 70do 71 i=${GPU_VERSION_MAP[$key]} 72 CUR_GPU_VERSION=$key 73 CUDA_OPS_FILE=`basename ./$i/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so*` 74 if [ "`echo "$CUR_GPU_VERSION > $MAX_GPU_VERSION" | bc`" -eq 1 ]; then 75 if [ "`echo "$CUR_GPU_VERSION > $MAX_GPU_VERSION" | bc`" -eq 1 ]; then 76 MAX_GPU_VERSION=$CUR_GPU_VERSION 77 fi; 78 if [ ! -d "$BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu" ]; then 79 mkdir -p $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu 80 fi; 81 \cp -rf ./$i/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/$CUDA_OPS_FILE \ 82 $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu/$CUDA_OPS_FILE 83 fi; 84 rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/plugin/gpu$CUR_GPU_VERSION/libcuda_ops.so* 85 rm -rf $i 86done 87 88 89export COMMIT_ID=`cat $BASE_PACKAGE_UNZIP_DIR/mindspore/.commit_id | awk '{print $3}' | sed $'s/\'//g'` 90VERSION=`cat $BASE_PACKAGE_UNZIP_DIR/mindspore/version.py | awk '{print $3}' | sed $'s/\'//g'` 91echo -n "$VERSION" > $MINDSPORE_ROOT_PATH/version.txt 92 93echo "Delete useless file ..." 94rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/version.py 95rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/default_config.py 96rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/.commit_id 97rm -f $BASE_PACKAGE_UNZIP_DIR/mindspore/lib/libakg.so 98 99echo "Repacking new wheel package ..." 100PACKAGE_WORK_DIR=$MINDSPORE_ROOT_PATH/build 101if [ -d "$PACKAGE_WORK_DIR/package" ]; then 102 rm -rf $PACKAGE_WORK_DIR/package 103fi 104mkdir -p $MINDSPORE_ROOT_PATH/mindspore/python/mindspore 105mkdir -p $PACKAGE_WORK_DIR 106PACKAGE_WORK_DIR=`realpath $PACKAGE_WORK_DIR` 107mv $BASE_PACKAGE_UNZIP_DIR $PACKAGE_WORK_DIR/package 108export MS_PACKAGE_NAME="mindspore" 109export BACKEND_POLICY="ms" 110export BUILD_PATH=$PACKAGE_WORK_DIR 111cd $BUILD_PATH/package 112python $MINDSPORE_ROOT_PATH/setup.py bdist_wheel 113if [ -d "$MINDSPORE_ROOT_PATH/output" ]; then 114 rm -rf $MINDSPORE_ROOT_PATH/output 115fi 116mkdir -p $MINDSPORE_ROOT_PATH/output 117mv dist/*.whl $MINDSPORE_ROOT_PATH/output/$PACKAGE_FILE_NAME 118cd - 119cd $MINDSPORE_ROOT_PATH/output/ 120echo "$(sha256sum $PACKAGE_FILE_NAME)" > $PACKAGE_FILE_NAME.sha256 121cd - 122