9
9
# EXIR to capture and export a model file. Then use `executor_runner` demo C++
10
10
# binary to run the model.
11
11
12
- set -e
12
+ set -eu
13
+ set -o pipefail
13
14
14
15
# shellcheck source=/dev/null
15
16
source " $( dirname " ${BASH_SOURCE[0]} " ) /../../../.ci/scripts/utils.sh"
16
17
18
+ # Allow overriding the number of build jobs. The `-` makes this safe to check
19
+ # even if the variable isn't defined; it is not a negative value.
20
+ readonly NUM_JOBS=${CMAKE_BUILD_PARALLEL_LEVEL:- 9}
21
+
17
22
test_buck2_custom_op_1 () {
18
23
local model_name=' custom_ops_1'
19
24
echo " Exporting ${model_name} .pte"
@@ -39,13 +44,12 @@ test_cmake_custom_op_1() {
39
44
rm -rf ${build_dir}
40
45
retry cmake \
41
46
-DREGISTER_EXAMPLE_CUSTOM_OP=1 \
42
- -DCMAKE_INSTALL_PREFIX=cmake-out \
43
47
-DPYTHON_EXECUTABLE=" $PYTHON_EXECUTABLE " \
44
48
-B${build_dir} \
45
49
${example_dir}
46
50
47
51
echo " Building ${example_dir} "
48
- cmake --build ${build_dir} -j9 --config Release
52
+ cmake --build ${build_dir} -j ${NUM_JOBS} --config Release
49
53
50
54
echo ' Running custom_ops_executor_runner'
51
55
${build_dir} /custom_ops_executor_runner --model_path=" ./${model_name} .pte"
@@ -85,21 +89,27 @@ get_shared_lib_ext() {
85
89
86
90
test_cmake_custom_op_2 () {
87
91
local model_name=' custom_ops_2'
88
- SITE_PACKAGES=" $( ${PYTHON_EXECUTABLE} -c ' from distutils.sysconfig import get_python_lib; print(get_python_lib())' ) "
89
- CMAKE_PREFIX_PATH=" $PWD /cmake-out/lib/cmake/ExecuTorch;${SITE_PACKAGES} /torch"
92
+ # Declare as local separately so it doesn't hide errors when executing the
93
+ # subcommand.
94
+ local site_packages
95
+ site_packages=" $( ${PYTHON_EXECUTABLE} -c \
96
+ ' from distutils.sysconfig import get_python_lib; print(get_python_lib())' ) "
97
+ # executorch-config.cmake is installed under cmake-out. The torch config lives
98
+ # inside its installed pip package.
99
+ local cmake_prefix_path=" $PWD /cmake-out;${site_packages} /torch"
90
100
91
101
local example_dir=examples/portable/custom_ops
92
102
local build_dir=cmake-out/${example_dir}
93
103
rm -rf ${build_dir}
94
104
retry cmake \
95
105
-DREGISTER_EXAMPLE_CUSTOM_OP=2 \
96
- -DCMAKE_PREFIX_PATH=" $CMAKE_PREFIX_PATH " \
97
- -DPYTHON_EXECUTABLE=" $PYTHON_EXECUTABLE " \
106
+ -DCMAKE_PREFIX_PATH=" ${cmake_prefix_path} " \
107
+ -DPYTHON_EXECUTABLE=" ${ PYTHON_EXECUTABLE} " \
98
108
-B${build_dir} \
99
109
${example_dir}
100
110
101
111
echo " Building ${example_dir} "
102
- cmake --build ${build_dir} -j9 --config Release
112
+ cmake --build ${build_dir} -j ${NUM_JOBS} --config Release
103
113
104
114
EXT=$( get_shared_lib_ext)
105
115
echo " Exporting ${model_name} .pte"
@@ -110,12 +120,12 @@ test_cmake_custom_op_2() {
110
120
${build_dir} /custom_ops_executor_runner --model_path=" ./${model_name} .pte"
111
121
}
112
122
113
- if [[ -z $PYTHON_EXECUTABLE ]];
123
+ if [[ -z ${ PYTHON_EXECUTABLE:- } ]];
114
124
then
115
125
PYTHON_EXECUTABLE=python3
116
126
fi
117
127
118
- if [[ -z $BUCK ]];
128
+ if [[ -z ${ BUCK:- } ]];
119
129
then
120
130
BUCK=buck2
121
131
fi
0 commit comments