Skip to content

Commit dbd0e9f

Browse files
authored
updated cmake and doc for bundled program
Differential Revision: D84526104 Pull Request resolved: #15081
1 parent 50f96a0 commit dbd0e9f

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

docs/source/bundled-io.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,27 +199,43 @@ This stage mainly focuses on executing the model with the bundled inputs and com
199199

200200
### Get ExecuTorch Program Pointer from `BundledProgram` Buffer
201201
We need the pointer to ExecuTorch program to do the execution. To unify the process of loading and executing `BundledProgram` and Program flatbuffer, we create an API for this
202-
`executorch::bundled_program::get_program_data`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp#L128-L137) of this API.
202+
`executorch::bundled_program::get_program_data`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp#L128-L137) of this API.
203203

204204
### Load Bundled Input to Method
205-
To execute the program on the bundled input, we need to load the bundled input into the method. Here we provided an API called `executorch::bundled_program::load_bundled_input`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp#L253-L259) of this API.
205+
To execute the program on the bundled input, we need to load the bundled input into the method. Here we provided an API called `executorch::bundled_program::load_bundled_input`. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp#L253-L259) of this API.
206206

207207
### Verify the Method's Output.
208-
We call `executorch::bundled_program::verify_method_outputs` to verify the method's output with bundled expected outputs. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp#L300-L311) of this API.
208+
We call `executorch::bundled_program::verify_method_outputs` to verify the method's output with bundled expected outputs. Check out an [example usage](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp#L301-L307) of this API.
209209

210210
### Runtime Example
211211

212212
Please checkout our [example runner](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/README.md#bundledprogram) for a bundled program. You could run these commands to test with the BundledProgram binary (`.bpte`) file you generated in the previous step:
213213

214214
```bash
215215
cd executorch
216-
./examples/devtools/build_example_runner.sh
217-
./cmake-out/examples/devtools/example_runner --bundled_program_path {your-bpte-file} --output_verification
216+
./examples/devtools/build_example_runner.sh
217+
./cmake-out/examples/devtools/example_runner --bundled_program_path {your-bpte-file} --output_verification
218218
```
219219

220220
It is expected to see no output from running the above mentioned snippet.
221+
For a detailed example of how the runner should be like, please refer to our [example runner](https://github.com/pytorch/executorch/blob/release/1.0/examples/devtools/example_runner/example_runner.cpp).
221222

222-
For a detailed example of how the runner should be like, please refer to our [example runner](https://github.com/pytorch/executorch/blob/release/0.6/examples/devtools/example_runner/example_runner.cpp).
223+
224+
### Try the Complete Workflow
225+
226+
To test the entire end-to-end workflow including building the example runner, exporting a model, and verifying the bundled program execution, you can use the test script:
227+
228+
```bash
229+
cd executorch
230+
./examples/devtools/test_example_runner.sh
231+
```
232+
233+
This script will:
234+
1. Build the example runner using `build_example_runner.sh`
235+
2. Export a MobileNetV2 model as a bundled program
236+
3. Run the example runner with the bundled program to verify correctness
237+
238+
This is a great way to ensure your environment is set up correctly and to see the complete BundledProgram workflow in action.
223239

224240
## Common Errors
225241

examples/devtools/build_example_runner.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ main() {
6161

6262
local example_dir=examples/devtools
6363
local build_dir="cmake-out/${example_dir}"
64-
local cmake_prefix_path="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
64+
65+
# Check for both lib and lib64 directories
66+
local executorch_dir="${PWD}/cmake-out/lib/cmake/ExecuTorch"
67+
if [[ ! -d "${executorch_dir}" ]]; then
68+
executorch_dir="${PWD}/cmake-out/lib64/cmake/ExecuTorch"
69+
fi
70+
71+
local cmake_prefix_path="${executorch_dir};${PWD}/cmake-out/third-party/gflags"
72+
6573
rm -rf ${build_dir}
6674
cmake -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \
6775
-DCMAKE_BUILD_TYPE=Release \

examples/devtools/test_example_runner.sh

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,32 @@
88
# Test the end-to-end flow of building devtools/example_runner and use it to run
99
# an actual model.
1010

11-
1211
set -e
1312

14-
# shellcheck source=/dev/null
15-
source "$(dirname "${BASH_SOURCE[0]}")/../../.ci/scripts/utils.sh"
13+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
14+
readonly SCRIPT_DIR
1615

17-
cmake_install_executorch_devtools_lib() {
18-
echo "Installing libexecutorch.a, libportable_kernels.a, libetdump.a, libbundled_program.a"
19-
clean_executorch_install_folders
16+
readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../.."
2017

21-
retry cmake -DCMAKE_INSTALL_PREFIX=cmake-out \
22-
-DCMAKE_BUILD_TYPE=Release \
23-
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
24-
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
25-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
26-
-Bcmake-out .
27-
cmake --build cmake-out -j9 --target install --config Release
28-
}
18+
if [[ -z $PYTHON_EXECUTABLE ]];
19+
then
20+
PYTHON_EXECUTABLE=python3
21+
fi
2922

3023
test_cmake_devtools_example_runner() {
31-
echo "Exporting MobilenetV2"
32-
${PYTHON_EXECUTABLE} -m examples.devtools.scripts.export_bundled_program --model_name="mv2"
24+
cd "${EXECUTORCH_ROOT}"
25+
26+
echo "Building example_runner using build_example_runner.sh"
27+
"${SCRIPT_DIR}/build_example_runner.sh"
28+
3329
local example_dir=examples/devtools
3430
local build_dir=cmake-out/${example_dir}
35-
CMAKE_PREFIX_PATH="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
36-
rm -rf ${build_dir}
37-
retry cmake \
38-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
39-
-DCMAKE_BUILD_TYPE=Release \
40-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
41-
-B${build_dir} \
42-
${example_dir}
43-
44-
echo "Building ${example_dir}"
45-
cmake --build ${build_dir} -j9 --config Release
31+
32+
echo "Exporting MobilenetV2"
33+
${PYTHON_EXECUTABLE} -m examples.devtools.scripts.export_bundled_program --model_name="mv2"
4634

4735
echo 'Running example_runner'
4836
${build_dir}/example_runner --bundled_program_path="./mv2_bundled.bpte"
4937
}
5038

51-
if [[ -z $PYTHON_EXECUTABLE ]];
52-
then
53-
PYTHON_EXECUTABLE=python3
54-
fi
55-
56-
if [[ -z $BUCK ]];
57-
then
58-
BUCK=buck2
59-
fi
60-
61-
cmake_install_executorch_devtools_lib
6239
test_cmake_devtools_example_runner

0 commit comments

Comments
 (0)