Skip to content

Commit

Permalink
Rename the "executorch/examples/sdk" folder to "executorch/examples/d…
Browse files Browse the repository at this point in the history
…evtools" (pytorch#5207)

Summary:
Pull Request resolved: pytorch#5207

This is part of the bigger renaming "sdk" -> "devtools" task.
Renaming principles:
1. Replace "sdk" in the file paths to "devtools", that is, "fbcode/executorch/examples/**sdk**" -> "fbcode/executorch/examples/**devtools**";
2. When parent path has the word "devtools" in it, then the child paths do not include "devtools" anymore *to reduce redundancy*, e.g., "fbcode/executorch/examples/**sdk/sdk_example_runner**" -> "fbcode/executorch/examples/**devtools/example_runner**"

Reviewed By: dbort

Differential Revision: D62409715

fbshipit-source-id: 00ee0dc540349d85ba344d07e0000dcc5205b74d
  • Loading branch information
Olivia-liu authored and facebook-github-bot committed Sep 12, 2024
1 parent 08c8c6e commit 3ad2f16
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 77 deletions.
16 changes: 8 additions & 8 deletions backends/cadence/runtime/executor_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Test the end-to-end flow of building sdk_example_runner and use it to run
# Test the end-to-end flow of building devtools/example_runner and use it to run
# an actual model.


Expand All @@ -14,7 +14,7 @@ set -e
# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/../../.ci/scripts/utils.sh"

cmake_install_executorch_sdk_lib() {
cmake_install_executorch_devtools_lib() {
echo "Installing libexecutorch.a, libportable_kernels.a, libetdump.a, libbundled_program.a"
rm -rf cmake-out

Expand All @@ -27,8 +27,8 @@ cmake_install_executorch_sdk_lib() {
cmake --build cmake-out -j9 --target install --config Release
}

test_cmake_sdk_example_runner() {
local example_dir=examples/sdk
test_cmake_devtools_example_runner() {
local example_dir=examples/devtools
local build_dir=cmake-out/${example_dir}
CMAKE_PREFIX_PATH="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
rm -rf ${build_dir}
Expand All @@ -42,8 +42,8 @@ test_cmake_sdk_example_runner() {
echo "Building ${example_dir}"
cmake --build ${build_dir} -j9 --config Release

echo 'Running sdk_example_runner'
${build_dir}/sdk_example_runner --bundled_program_path="./CadenceDemoModel.bpte"
echo 'Running devtools/example_runner'
${build_dir}/example_runner --bundled_program_path="./CadenceDemoModel.bpte"
}

if [[ -z $PYTHON_EXECUTABLE ]];
Expand All @@ -56,5 +56,5 @@ then
BUCK=buck2
fi

cmake_install_executorch_sdk_lib
test_cmake_sdk_example_runner
cmake_install_executorch_devtools_lib
test_cmake_devtools_example_runner
2 changes: 1 addition & 1 deletion docs/source/sdk-bundled-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ We call `torch::executor::bundled_program::VerifyResultWithBundledExpectedOutput

### Runtime Example

Here we provide an example about how to run the bundled program step by step. Most of the code is borrowed from [executor_runner](https://github.com/pytorch/executorch/blob/main/examples/sdk/sdk_example_runner/sdk_example_runner.cpp), and please review that file if you need more info and context:
Here we provide an example about how to run the bundled program step by step. Most of the code is borrowed from [executor_runner](https://github.com/pytorch/executorch/blob/main/examples/devtools/example_runner/example_runner.cpp), and please review that file if you need more info and context:

```c++
// method_name is the name for the method we want to test
Expand Down
2 changes: 1 addition & 1 deletion docs/source/sdk-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Currently, ExecuTorch supports the following debugging flows:
## Steps to debug a model in ExecuTorch

### Runtime
For a real example reflecting the steps below, please refer to [sdk_example_runner.cpp](https://github.com/pytorch/executorch/blob/main/examples/sdk/sdk_example_runner/sdk_example_runner.cpp).
For a real example reflecting the steps below, please refer to [example_runner.cpp](https://github.com/pytorch/executorch/blob/main/examples/devtools/example_runner/example_runner.cpp).

1. [Optional] Generate an [ETRecord](./sdk-etrecord.rst) while exporting your model. When provided, this enables users to link profiling information back to the eager model source code (with stack traces and module hierarchy).
2. Integrate [ETDump generation](./sdk-etdump.md) into the runtime and set the debugging level by configuring the `ETDumpGen` object. Then, provide an additional buffer to which intermediate outputs and program outputs will be written. Currently we support two levels of debugging:
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorials_source/sdk-integration-tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def forward(self, x):
# Use CMake (follow `these instructions <../runtime-build-and-cross-compilation.html#configure-the-cmake-build>`__ to set up cmake) to execute the Bundled Program to generate the ``ETDump``::
#
# cd executorch
# ./examples/sdk/build_sdk_example_runner.sh
# cmake-out/examples/sdk/sdk_example_runner --bundled_program_path="bundled_program.bp"
# ./examples/devtools/build_example_runner.sh
# cmake-out/examples/devtools/example_runner --bundled_program_path="bundled_program.bp"

######################################################################
# Creating an Inspector
Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ examples
├── models # Contains a set of popular and representative PyTorch models
├── portable # Contains end-to-end demos for ExecuTorch in portable mode
├── selective_build # Contains demos of selective build for optimizing the binary size of the ExecuTorch runtime
├── sdk # Contains demos of BundledProgram and ETDump
├── devtools # Contains demos of BundledProgram and ETDump
├── demo-apps # Contains demo apps for Android and iOS
├── xnnpack # Contains end-to-end ExecuTorch demos with first-party optimization using XNNPACK
├── apple
Expand All @@ -39,9 +39,9 @@ A user's journey may commence by exploring the demos located in the [`portable/`

To understand how to deploy the ExecuTorch runtime with optimization for binary size, explore the demos available in the [`selective_build/`](./selective_build) directory. These demos are specifically designed to illustrate the [Selective Build](../docs/source/kernel-library-selective_build.md), offering insights into reducing the binary size while maintaining efficiency.

## Demo of ExecuTorch SDK
## Demo of ExecuTorch Developer Tools

You will find demos of [ExecuTorch SDK](./sdk/) in the [`sdk/`](./sdk/) directory. The examples focuses on exporting and executing BundledProgram for ExecuTorch model verification and ETDump for collecting profiling and debug data.
You will find demos of [ExecuTorch Developer Tools](./devtools/) in the [`devtools/`](./devtools/) directory. The examples focuses on exporting and executing BundledProgram for ExecuTorch model verification and ETDump for collecting profiling and debug data.

## Demo Apps

Expand Down
4 changes: 2 additions & 2 deletions examples/apple/coreml/scripts/debugger_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_root_dir_path() -> Path:
sys.path.append(str((get_root_dir_path() / "examples").resolve()))

from inspector_utils import (
build_sdk_runner_including_coreml,
build_devtools_runner_including_coreml,
ComparisonResult,
create_inspector_coreml,
create_inspector_reference,
Expand Down Expand Up @@ -145,7 +145,7 @@ def main() -> None:
f"Valid compute units are {valid_compute_units}."
)

build_sdk_runner_including_coreml(
build_devtools_runner_including_coreml(
root_dir_path=get_root_dir_path(), conda_env_name=args.conda_environment_name
)

Expand Down
32 changes: 17 additions & 15 deletions examples/apple/coreml/scripts/inspector_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,26 @@
]


def build_sdk_runner_including_coreml(
def build_devtools_runner_including_coreml(
root_dir_path: Path,
conda_env_name: str,
force: bool = False,
):
if not force:
sdk_executable_path = (
root_dir_path / "cmake-out" / "examples" / "sdk" / "sdk_example_runner"
devtools_executable_path = (
root_dir_path / "cmake-out" / "examples" / "devtools" / "example_runner"
)
print(sdk_executable_path)
if sdk_executable_path.is_file():
print(devtools_executable_path)
if devtools_executable_path.is_file():
return

cd_root_command: str = f"cd {root_dir_path.resolve()}"
conda_activate_env_command: str = f"source conda activate {conda_env_name}"
build_sdk_runner_command: str = (
"./examples/sdk/build_sdk_example_runner.sh --coreml"
build_devtools_runner_command: str = (
"./examples/devtools/build_example_runner.sh --coreml"
)
build_command: str = (
f"{cd_root_command} && {conda_activate_env_command} && {build_sdk_runner_command}"
f"{cd_root_command} && {conda_activate_env_command} && {build_devtools_runner_command}"
)
subprocess.run(
f'bash -c "{build_command}"', shell=True, check=True
Expand Down Expand Up @@ -173,22 +173,24 @@ def generate_etdump_with_intermediate_values(
debug_buffer_path: Path,
debug_buffer_size: int,
):
sdk_executable_path = (
root_dir_path / "cmake-out" / "examples" / "sdk" / "sdk_example_runner"
devtools_executable_path = (
root_dir_path / "cmake-out" / "examples" / "devtools" / "example_runner"
)
if not sdk_executable_path.is_file():
if not devtools_executable_path.is_file():
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), str(sdk_executable_path.resolve())
errno.ENOENT,
os.strerror(errno.ENOENT),
str(devtools_executable_path.resolve()),
)

sdk_runner_command: str = f"""
{sdk_executable_path.resolve()} -dump_intermediate_outputs\
devtools_runner_command: str = f"""
{devtools_executable_path.resolve()} -dump_intermediate_outputs\
-bundled_program_path {bundled_program_path.resolve()}\
-etdump_path {et_dump_path.resolve()}\
-debug_output_path {debug_buffer_path.resolve()}\
-debug_buffer_size {debug_buffer_size}"""
subprocess.run(
f'bash -c "{sdk_runner_command}"', shell=True, check=True
f'bash -c "{devtools_runner_command}"', shell=True, check=True
).check_returncode()


Expand Down
4 changes: 2 additions & 2 deletions examples/apple/mps/test_mps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -e

# shellcheck source=/dev/null
source "$(dirname "${BASH_SOURCE[0]}")/../../../.ci/scripts/utils.sh"
cmake_install_executorch_sdk_lib() {
cmake_install_executorch_devtools_lib() {
echo "Installing libexecutorch.a, libportable_kernels.a, libetdump.a, libbundled_program.a"
rm -rf cmake-out

Expand Down Expand Up @@ -60,5 +60,5 @@ then
fi


cmake_install_executorch_sdk_lib
cmake_install_executorch_devtools_lib
test_cmake_mps
17 changes: 10 additions & 7 deletions examples/sdk/CMakeLists.txt → examples/devtools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Example CMakeLists.txt for building executor_runner with sdk support. In this
# example we link sdk and bundled_program libraries into executor_runner binary
# Example CMakeLists.txt for building executor_runner with Developer Tools
# support. In this example we link devtools and bundled_program libraries into
# executor_runner binary
cmake_minimum_required(VERSION 3.19)
project(sdk_example)
project(devtools_example)

option(EXECUTORCH_BUILD_COREML "Build the Core ML backend" OFF)

Expand Down Expand Up @@ -45,15 +46,15 @@ find_package(
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party
)

add_executable(sdk_example_runner sdk_example_runner/sdk_example_runner.cpp)
add_executable(example_runner example_runner/example_runner.cpp)
target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED)

target_include_directories(
etdump INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../../devtools/include
${EXECUTORCH_ROOT}/third-party/flatcc/include
)
target_link_libraries(
sdk_example_runner
example_runner
executorch
gflags
etdump
Expand All @@ -80,10 +81,12 @@ if(EXECUTORCH_BUILD_COREML)
NO_DEFAULT_PATH
)

target_link_libraries(sdk_example_runner "-Wl,-force_load" coremldelegate)
target_link_libraries(
example_runner "-Wl,-force_load" coremldelegate
)

target_link_libraries(
sdk_example_runner ${PROTOBUF_LITE} ${ACCELERATE_FRAMEWORK}
example_runner ${PROTOBUF_LITE} ${ACCELERATE_FRAMEWORK}
${COREML_FRAMEWORK} ${FOUNDATION_FRAMEWORK} ${SQLITE_LIBRARY}
)
endif()
24 changes: 11 additions & 13 deletions examples/sdk/README.md → examples/devtools/README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
# SDK Examples
# Developer Tools Examples
This directory contains examples of BundledProgram and ETDump generation.

## Directory structure
```bash
examples/sdk
examples/devtools
├── scripts # Python scripts to illustrate export workflow of bundled program.
├── sdk_executor_runner # Contains an example for both BundledProgram to verify ExecuTorch model, and generate ETDump for runtime results.
├── executor_runner # Contains an example for both BundledProgram to verify ExecuTorch model, and generate ETDump for runtime results.
└── README.md # Current file
```

## BundledProgram

We will use an example model (in `torch.nn.Module`) and its representative inputs, both from [`models/`](../models) directory, to generate a [BundledProgram(`.bpte`)](../../docs/source/sdk-bundled-io.md) file using the [script](scripts/export_bundled_program.py). Then we will use [sdk_example_runner](sdk_example_runner/sdk_example_runner.cpp) to execute the `.bpte` model on the ExecuTorch runtime and verify the model on BundledProgram API.
We will use an example model (in `torch.nn.Module`) and its representative inputs, both from [`models/`](../models) directory, to generate a [BundledProgram(`.bpte`)](../../docs/source/sdk-bundled-io.md) file using the [script](scripts/export_bundled_program.py). Then we will use [devtools/example_runner](example_runner/example_runner.cpp) to execute the `.bpte` model on the ExecuTorch runtime and verify the model on BundledProgram API.


1. Sets up the basic development environment for ExecuTorch by [Setting up ExecuTorch from GitHub](https://pytorch.org/executorch/stable/getting-started-setup).

2. Using the [script](scripts/export_bundled_program.py) to generate a BundledProgram binary file by retreiving a `torch.nn.Module` model and its representative inputs from the list of available models in the [`models/`](../models) dir
2. Using the [script](scripts/export_bundled_program.py) to generate a BundledProgram binary file by retreiving a `torch.nn.Module` model and its representative inputs from the list of available models in the [`models/`](../models) dir.

```bash
cd executorch # To the top level dir

# To get a list of example models
python3 -m examples.sdk.scripts.export_bundled_program -h
python3 -m examples.devtools.scripts.export_bundled_program -h

# To generate a specific `.bpte` model
python3 -m examples.sdk.scripts.export_bundled_program -m mv2 # for MobileNetv2
python3 -m examples.devtools.scripts.export_bundled_program -m mv2 # for MobileNetv2

# This should generate ./mv2_bundled.bpte file, if successful.
```

3. Once we have the BundledProgram binary (`.bpte`) file, then let's run and verify it with ExecuTorch runtime and BundledProgram APIs using the [sdk_example_runner](sdk_example_runner/sdk_example_runner.cpp).
3. Once we have the BundledProgram binary (`.bpte`) file, then let's run and verify it with ExecuTorch runtime and BundledProgram APIs using the [devtools/example_runner](example_runner/example_runner.cpp).

```bash
cd executorch
rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_SDK=1 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=1 ..
cd ..
cmake --build cmake-out -j8 -t sdk_example_runner
./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bpte --output_verification
./examples/devtools/build_example_runner.sh
./cmake-out/examples/devtools/example_runner --bundled_program_path mv2_bundled.bpte --output_verification
```


Expand All @@ -51,7 +49,7 @@ We offer an example runner that accepts a `BundledProgram` (`.bpte`) and runs a
Running the program will generate an `ETDump` file (`.etdp`) at the location specified by `--etdump_path`. Make sure to build the program as specified below to enable the event tracer.

```bash
./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bpte --etdump_path mv2_etdump.etdp
./cmake-out/examples/devtools/example_runner --bundled_program_path mv2_bundled.bpte --etdump_path mv2_etdump.etdp
```

### Parsing ETDump
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

# Builds sdk_example_runner and prints its path.
# Builds example_runner and prints its path.

set -euo pipefail

Expand All @@ -20,9 +20,9 @@ export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-9}"
BUILD_COREML=OFF

usage() {
echo "Builds sdk example runner."
echo "Builds example runner."
echo "Options:"
echo " --coreml Include this flag to enable Core ML backend when building the SDK."
echo " --coreml Include this flag to enable Core ML backend when building the Developer Tools."
exit 0
}

Expand Down Expand Up @@ -59,7 +59,7 @@ main() {

cmake --build cmake-out --target install --config Release

local example_dir=examples/sdk
local example_dir=examples/devtools
local build_dir="cmake-out/${example_dir}"
local cmake_prefix_path="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
rm -rf ${build_dir}
Expand All @@ -70,12 +70,12 @@ main() {
"${example_dir}"
cmake --build "${build_dir}" --config Release

local runner="${PWD}/${build_dir}/sdk_example_runner"
local runner="${PWD}/${build_dir}/example_runner"
if [[ ! -f "${runner}" ]]; then
echo "ERROR: Failed to build ${build_dir}/sdk_example_runner" >&2
echo "ERROR: Failed to build ${build_dir}/example_runner" >&2
exit 1
else
echo "Built ${build_dir}/sdk_example_runner"
echo "Built ${build_dir}/example_runner"
fi
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
#include <executorch/runtime/platform/log.h>
#include <executorch/runtime/platform/runtime.h>

static uint8_t method_allocator_pool[4 * 1024U * 1024U]; // 4MB
static constexpr size_t kBundledAllocatorPoolSize = 16 * 1024U;
static uint8_t bundled_allocator_pool[kBundledAllocatorPoolSize];
static std::array<uint8_t, 4 * 1024U * 1024U> method_allocator_pool; // 4MB

DEFINE_string(
bundled_program_path,
Expand Down Expand Up @@ -170,8 +168,8 @@ int main(int argc, char** argv) {
// MallocMemoryAllocator).
//
// In this example we use a statically allocated memory pool.
MemoryAllocator method_allocator{
MemoryAllocator(sizeof(method_allocator_pool), method_allocator_pool)};
MemoryAllocator method_allocator{MemoryAllocator(
sizeof(method_allocator_pool), method_allocator_pool.data())};

// The memory-planned buffers will back the mutable tensors used by the
// method. The sizes of these buffers were determined ahead of time during the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def define_common_targets():

# Test driver for models with bundled inputs.
runtime.cxx_binary(
name = "sdk_example_runner",
name = "example_runner",
srcs = [
"sdk_example_runner.cpp",
"example_runner.cpp",
],
deps = [
"//executorch/runtime/executor/test:test_backend_compiler_lib",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

# Example script for exporting simple models to flatbuffer

# pyre-unsafe

import argparse

from typing import List
Expand Down
File renamed without changes.
Loading

0 comments on commit 3ad2f16

Please sign in to comment.