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 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. elif [[ "${PYTHON_VERSION}" == "3.6" ]]; then
  41. PY_TAGS="cp36-cp36m"
  42. else
  43. echo "Could not find 'Python 3.6' or 'Python 3.7'"
  44. exit 1
  45. fi
  46. PLATFORM_TAG=$(to_lower "$(uname)_$(uname -m)")
  47. elif [[ $(uname) == "Darwin" ]]; then
  48. if [[ "${PYTHON_VERSION}" == "3.7" || "${PYTHON_VERSION}" == "3.6" ]]; then
  49. PY_TAGS="py3-none"
  50. else
  51. echo "Could not find 'Python 3.6' or 'Python 3.7'"
  52. exit 1
  53. fi
  54. PLATFORM_TAG="any"
  55. fi
  56. echo "=========${BASEPATH}==================="
  57. mk_new_dir "${OUTPUT_PATH}"
  58. #copy necessary file to pack_path
  59. cp ${BASEPATH}/mindspore/*.py "${PACKAGE_PATH}/mindspore"
  60. cp -rf "${BUILD_PATH}/../mindspore/nn" "${PACKAGE_PATH}/mindspore"
  61. cp -rf "${BUILD_PATH}/../mindspore/_extends" "${PACKAGE_PATH}/mindspore"
  62. cp -rf "${BUILD_PATH}/../mindspore/parallel" "${PACKAGE_PATH}/mindspore"
  63. cp -rf "${BUILD_PATH}/../mindspore/mindrecord" "${PACKAGE_PATH}/mindspore"
  64. cp -rf "${BUILD_PATH}/../mindspore/train" "${PACKAGE_PATH}/mindspore"
  65. cp -rf "${BUILD_PATH}/../mindspore/model_zoo" "${PACKAGE_PATH}/mindspore"
  66. cp -rf "${BUILD_PATH}/../mindspore/common" "${PACKAGE_PATH}/mindspore"
  67. cp -rf "${BUILD_PATH}/../mindspore/ops" "${PACKAGE_PATH}/mindspore"
  68. cp -rf "${BUILD_PATH}/../mindspore/communication" "${PACKAGE_PATH}/mindspore"
  69. if [[ "X$2" = "Xgpu" ]]; then
  70. echo "package akg when gpu enable."
  71. cp -rf "${BASEPATH}/mindspore/akg" "${PACKAGE_PATH}"
  72. if [[ -d "${BUILD_PATH}/mindspore/incubator-tvm" ]]; then
  73. cp -rf "${BUILD_PATH}/mindspore/incubator-tvm/topi/python/topi" "${PACKAGE_PATH}/akg"
  74. cp -rf "${BUILD_PATH}/mindspore/incubator-tvm/python/tvm" "${PACKAGE_PATH}/akg"
  75. fi
  76. fi
  77. # move dataset
  78. if [[ -d "${BASEPATH}/mindspore/dataset" ]]; then
  79. cp -rf "${BASEPATH}/mindspore/dataset" "${PACKAGE_PATH}/mindspore"
  80. fi
  81. cd "${PACKAGE_PATH}"
  82. if [ -n "$1" ];then
  83. export BACKEND_POLICY=$1
  84. else
  85. export BACKEND_POLICY="ms"
  86. fi
  87. ${PYTHON} "${BASEPATH}/setup_package.py" bdist_wheel
  88. chmod -R 700 ${PACKAGE_PATH}/mindspore/
  89. chmod -R 700 ${PACKAGE_PATH}/mindspore.egg-info/
  90. # rename package
  91. PACKAGE_FULL_NAME=$(find "${PACKAGE_PATH}" -iname "*.whl")
  92. PACKAGE_BASE_NAME=$(echo ${PACKAGE_FULL_NAME} | awk -F / '{print $NF}' | awk -F - '{print $1"-"$2}')
  93. PACKAGE_NEW_NAME="${PACKAGE_BASE_NAME}-${PY_TAGS}-${PLATFORM_TAG}.whl"
  94. cp -rf "${PACKAGE_PATH}/dist"/*.whl "${PACKAGE_PATH}/${PACKAGE_NEW_NAME}"
  95. cp -f "${PACKAGE_PATH}/${PACKAGE_NEW_NAME}" "${OUTPUT_PATH}"
  96. cd "${BASEPATH}"
  97. echo "------Successfully created mindspore package------"