-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·182 lines (164 loc) · 5.41 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·182 lines (164 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
# -----------------------------------------------------------------------------------------------------------
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
PROJECT_ROOT="${SCRIPT_DIR}"
MULTICORE_VALUE="mindspore"
SHMEM_VALUE="all"
CUSTOM_OPS_VALUE="on"
STRICT_VALUE="on"
function show_help() {
cat <<EOF
Usage:
./build.sh [OPTIONS]
Options:
--multicore VALUE Build multicore: off, mindspore/ms, torch/pytorch, all/both.
Default: mindspore.
--shmem VALUE Build symmetric memory: off, mindspore/ms, torch/pytorch, all/both.
Default: all.
--custom-ops VALUE Build custom ops: on or off. Default: on.
--strict VALUE Fail when an optional native build step fails. Default: on.
Set to off to keep setup.py's warning-and-continue behavior.
-h, --help Show this help message.
Examples:
./build.sh
./build.sh --multicore all --shmem all --custom-ops on
./build.sh --multicore torch --shmem torch --strict off
./build.sh --multicore off --shmem off --custom-ops off
EOF
}
function die() {
echo "ERROR: $*" >&2
echo "Run './build.sh --help' for usage." >&2
exit 1
}
function normalize_lower() {
printf '%s' "$1" | tr '[:upper:]' '[:lower:]'
}
function require_value() {
local option_name=$1
local option_value=${2:-}
if [[ -z "${option_value}" || "${option_value}" == --* ]]; then
die "${option_name} requires a value."
fi
}
function validate_multicore_value() {
local value
value=$(normalize_lower "$1")
case "${value}" in
off|mindspore|ms|torch|pytorch|all|both)
echo "${value}"
;;
*)
die "Unsupported --multicore value '${1}'. Use off, mindspore/ms, torch/pytorch, or all/both."
;;
esac
}
function validate_shmem_value() {
local value
value=$(normalize_lower "$1")
case "${value}" in
off|mindspore|ms|torch|pytorch|all|both)
echo "${value}"
;;
*)
die "Unsupported --shmem value '${1}'. Use off, mindspore/ms, torch/pytorch, or all/both."
;;
esac
}
function validate_custom_ops_value() {
local value
value=$(normalize_lower "$1")
case "${value}" in
on)
echo "on"
;;
off)
echo "off"
;;
*)
die "Unsupported --custom-ops value '${1}'. Use on or off."
;;
esac
}
function validate_strict_value() {
local value
value=$(normalize_lower "$1")
case "${value}" in
on)
echo "on"
;;
off)
echo "off"
;;
*)
die "Unsupported --strict value '${1}'. Use on or off."
;;
esac
}
while [[ $# -gt 0 ]]; do
case "$1" in
--multicore=*)
MULTICORE_VALUE=$(validate_multicore_value "${1#*=}")
shift
;;
--multicore)
require_value "$1" "${2:-}"
MULTICORE_VALUE=$(validate_multicore_value "$2")
shift 2
;;
--shmem=*)
SHMEM_VALUE=$(validate_shmem_value "${1#*=}")
shift
;;
--shmem)
require_value "$1" "${2:-}"
SHMEM_VALUE=$(validate_shmem_value "$2")
shift 2
;;
--custom-ops=*)
CUSTOM_OPS_VALUE=$(validate_custom_ops_value "${1#*=}")
shift
;;
--custom-ops)
require_value "$1" "${2:-}"
CUSTOM_OPS_VALUE=$(validate_custom_ops_value "$2")
shift 2
;;
--strict=*)
STRICT_VALUE=$(validate_strict_value "${1#*=}")
shift
;;
--strict)
require_value "$1" "${2:-}"
STRICT_VALUE=$(validate_strict_value "$2")
shift 2
;;
-h|--help)
show_help
exit 0
;;
*)
die "Unknown option '$1'."
;;
esac
done
export BUILD_MULTICORE_EXTENSION="${MULTICORE_VALUE}"
export BUILD_SHMEM_EXTENSION="${SHMEM_VALUE}"
export BUILD_CUSTOM_OPS_EXTENSION="${CUSTOM_OPS_VALUE}"
export HYPER_PARALLEL_BUILD_STRICT="${STRICT_VALUE}"
cd "${PROJECT_ROOT}"
echo "Build configuration:"
printf ' %-32s %s\n' "BUILD_MULTICORE_EXTENSION" "${BUILD_MULTICORE_EXTENSION}"
printf ' %-32s %s\n' "BUILD_SHMEM_EXTENSION" "${BUILD_SHMEM_EXTENSION}"
printf ' %-32s %s\n' "BUILD_CUSTOM_OPS_EXTENSION" "${BUILD_CUSTOM_OPS_EXTENSION}"
printf ' %-32s %s\n' "HYPER_PARALLEL_BUILD_STRICT" "${HYPER_PARALLEL_BUILD_STRICT}"
python setup.py bdist_wheel