Skip to content

Commit 9f16db1

Browse files
Varun Purimergennachin
authored andcommitted
SDK Tutorial: ETDump usage docs (#865)
Summary: Pull Request resolved: #865 Docs for ETDump usage Reviewed By: guangy10 Differential Revision: D50206992 fbshipit-source-id: 0dceb63713cba0382e439c4ab99c2086ed26b0da
1 parent 4836bf2 commit 9f16db1

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

examples/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ You will find demos of [ExecuTorch QNN Backend](./qualcomm) in the [`qualcomm/`]
6363

6464
The [`xtensa/`](./xtensa) directory hosts a demo that showcases the process of exporting and executing a model on Xtensa Hifi4 DSP. You can utilize [this tutorial](../docs/source/build-run-xtensa.md) to guide you in configuring the demo and running it.
6565

66+
67+
## Demo of ExecuTorch SDK
68+
69+
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.
70+
6671
## Dependencies
6772

6873
Various models and workflows listed in this directory have dependencies on some other packages. You need to follow the setup guide in [Setting up ExecuTorch from GitHub](../docs/source/getting-started-setup.md) to have appropriate packages installed.

examples/sdk/README.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,58 @@ buck2 run examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_progra
3737
```
3838

3939

40-
## Generate ETDump
40+
## ETDump
4141

42-
Next step is to generate an ``ETDump``. ``ETDump`` contains runtime results
43-
from executing the model. To generate, users have two options:
42+
### Getting Started
4443

45-
**Option 1:**
44+
After exporting a `BundledProgram`, runtime profiling and debug data can be collected in an ``ETDump``. An ``ETDump`` is a buffer containing data generated by hooks within the ExecuTorch runtime.
45+
We offer an example runner that accepts a `BundledProgram` (`.bp`) and runs a single iteration over the first method defined.
46+
47+
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.
48+
49+
**Buck**
4650

47-
Use Buck::
4851
```bash
4952
python3 -m examples.sdk.scripts.export_bundled_program -m mv2
50-
buck2 run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp
53+
buck2 run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp --etdump_path mv2_etdump.etdp
5154
```
52-
**Option 2:**
55+
**CMake**
5356

54-
Use CMake::
5557
```bash
5658
cd executorch
5759
rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DBUCK2=buck2 -DEXECUTORCH_BUILD_SDK=1 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=1 ..
5860
cd ..
5961
cmake --build cmake-out -j8 -t sdk_example_runner
60-
./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bp
62+
./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bp --etdump_path mv2_etdump.etdp
63+
```
64+
65+
### Parsing ETDump
66+
67+
Once an `ETDump` has been generated, it can be viewed using the CLI inspector. This will print a tabular view of the data recorded in the ETDump.
68+
69+
```bash
70+
python3 -m sdk.inspector.inspector_cli --etdump_path mv2_etdump.etdp
71+
```
72+
### ETDump C++ API
73+
74+
ETDump profiling can also be used in a custom C++ program. `ETDumpGen` is an implementation of the abstract `EventTracer` class. Include the header file located at `sdk/etdump/etdump_flatcc.h`. To initialize the ETDump generator, construct it before loading the method from the program.
75+
76+
```cpp
77+
torch::executor::ETDumpGen etdump_gen = torch::executor::ETDumpGen();
78+
Result<Method> method =
79+
program->load_method(method_name, &memory_manager, &etdump_gen);
80+
```
81+
82+
Since the `EventTracer` hooks are embedded within the runtime, profiling and debug data will be automatically recorded.
83+
84+
Once execution has completed, finalize the ETDump buffer. This returns an `etdump_result`, a struct with the finalized buffer and its size.
85+
86+
```cpp
87+
etdump_result result = etdump_gen.get_etdump_data();
88+
if (result.buf != nullptr && result.size > 0) {
89+
FILE* f = fopen(FLAGS_etdump_path.c_str(), "w+");
90+
fwrite((uint8_t*)result.buf, 1, result.size, f);
91+
fclose(f);
92+
free(result.buf);
93+
}
6194
```

0 commit comments

Comments
 (0)