You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

package.sh 4.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/bash
  2. # Copyright 2019 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. set -e
  17. BASEPATH=$(cd "$(dirname $0)"; pwd)
  18. echo "${BASEPATH}"
  19. cd "${BASEPATH}"
  20. BUILD_PATH="${BASEPATH}/build"
  21. PACKAGE_PATH="${BUILD_PATH}/package"
  22. OUTPUT_PATH="${BASEPATH}/output"
  23. mk_new_dir() {
  24. local create_dir="$1" # the target to make
  25. if [[ -d "${create_dir}" ]];then
  26. rm -rf "${create_dir}"
  27. fi
  28. mkdir -pv "${create_dir}"
  29. }
  30. to_lower () {
  31. echo "$1" | tr '[:upper:]' '[:lower:]'
  32. }
  33. COMMIT_ID=$(git log --format='[sha1]:%h,[branch]:%d' -1 | sed 's/ //g')
  34. export COMMIT_ID
  35. PYTHON=$(which python3)
  36. PYTHON_VERSION=$("${PYTHON}" -V 2>&1 | awk '{print $2}' | cut -d. -f-2)
  37. if [[ $(uname) == "Linux" ]]; then
  38. if [[ "${PYTHON_VERSION}" == "3.7" ]]; then
  39. PY_TAGS="cp37-cp37m"
  40. else
  41. echo "Could not find 'Python 3.7'"
  42. exit 1
  43. fi
  44. PLATFORM_TAG=$(to_lower "$(uname)_$(uname -m)")
  45. elif [[ $(uname) == "Darwin" ]]; then
  46. if [[ "${PYTHON_VERSION}" == "3.7" ]]; then
  47. PY_TAGS="py3-none"
  48. else
  49. echo "Could not find 'Python 3.7'"
  50. exit 1
  51. fi
  52. PLATFORM_TAG="any"
  53. fi
  54. echo "=========${BASEPATH}==================="
  55. mk_new_dir "${OUTPUT_PATH}"
  56. #copy necessary file to pack_path
  57. cp ${BASEPATH}/mindspore/*.py "${PACKAGE_PATH}/mindspore"
  58. cp -rf "${BUILD_PATH}/../mindspore/nn" "${PACKAGE_PATH}/mindspore"
  59. cp -rf "${BUILD_PATH}/../mindspore/_extends" "${PACKAGE_PATH}/mindspore"
  60. cp -rf "${BUILD_PATH}/../mindspore/parallel" "${PACKAGE_PATH}/mindspore"
  61. cp -rf "${BUILD_PATH}/../mindspore/mindrecord" "${PACKAGE_PATH}/mindspore"
  62. cp -rf "${BUILD_PATH}/../mindspore/train" "${PACKAGE_PATH}/mindspore"
  63. cp -rf "${BUILD_PATH}/../mindspore/model_zoo" "${PACKAGE_PATH}/mindspore"
  64. cp -rf "${BUILD_PATH}/../mindspore/common" "${PACKAGE_PATH}/mindspore"
  65. cp -rf "${BUILD_PATH}/../mindspore/ops" "${PACKAGE_PATH}/mindspore"
  66. cp -rf "${BUILD_PATH}/../mindspore/communication" "${PACKAGE_PATH}/mindspore"
  67. if [[ "X$2" = "Xgpu" ]]; then
  68. echo "package _akg when gpu enable."
  69. cp -rf "${BASEPATH}/mindspore/_akg" "${PACKAGE_PATH}"
  70. if [[ -d "${BUILD_PATH}/mindspore/incubator-tvm" ]]; then
  71. cp -rf "${BUILD_PATH}/mindspore/incubator-tvm/topi/python/topi" "${PACKAGE_PATH}/_akg"
  72. cp -rf "${BUILD_PATH}/mindspore/incubator-tvm/python/tvm" "${PACKAGE_PATH}/_akg"
  73. fi
  74. fi
  75. # move dataset
  76. if [[ -d "${BASEPATH}/mindspore/dataset" ]]; then
  77. cp -rf "${BASEPATH}/mindspore/dataset" "${PACKAGE_PATH}/mindspore"
  78. fi
  79. cd "${PACKAGE_PATH}"
  80. if [ -n "$1" ];then
  81. export BACKEND_POLICY=$1
  82. else
  83. export BACKEND_POLICY="ms"
  84. fi
  85. # package name
  86. if [[ "X$1" = "Xge" ]]; then
  87. export MS_PACKAGE_NAME="mindspore"
  88. elif [[ "X$1" = "Xms" && "X$2" = "Xgpu" ]]; then
  89. export MS_PACKAGE_NAME="mindspore-gpu"
  90. elif [[ "X$1" = "Xms" && "X$2" = "Xascend" ]]; then
  91. export MS_PACKAGE_NAME="mindspore-ascend"
  92. elif [[ "X$1" = "Xms" && "X$2" = "Xcpu" ]]; then
  93. export MS_PACKAGE_NAME="mindspore"
  94. else
  95. export MS_PACKAGE_NAME="mindspore"
  96. fi
  97. ${PYTHON} "${BASEPATH}/setup.py" bdist_wheel
  98. chmod -R 700 ${PACKAGE_PATH}/mindspore/
  99. chmod -R 700 ${PACKAGE_PATH}/${MS_PACKAGE_NAME//-/_}.egg-info/
  100. # rename package
  101. PACKAGE_FULL_NAME=$(find "${PACKAGE_PATH}" -iname "*.whl")
  102. PACKAGE_BASE_NAME=$(echo ${PACKAGE_FULL_NAME} | awk -F / '{print $NF}' | awk -F - '{print $1"-"$2}')
  103. PACKAGE_BASE_NAME=${PACKAGE_BASE_NAME//_*-/-}
  104. PACKAGE_NEW_NAME="${PACKAGE_BASE_NAME}-${PY_TAGS}-${PLATFORM_TAG}.whl"
  105. cp -rf "${PACKAGE_PATH}/dist"/*.whl "${PACKAGE_PATH}/${PACKAGE_NEW_NAME}"
  106. cp -f "${PACKAGE_PATH}/${PACKAGE_NEW_NAME}" "${OUTPUT_PATH}"
  107. find ${OUTPUT_PATH} -name "*.whl" -print0 | xargs -0 -I {} sh -c "sha256sum {} | awk '{printf \$1}' > {}.sha256"
  108. cd "${BASEPATH}"
  109. echo "------Successfully created mindspore package------"