Skip to content

Commit 012c9d7

Browse files
tarun292facebook-github-bot
authored andcommitted
Adding CMake and OSS Buck build details for ETDump (#779)
Summary: Adding documentation on how to generate ETDump with CMake and Buck. Pull Request resolved: #779 Reviewed By: Jack-Khuu Differential Revision: D50127466 fbshipit-source-id: d698144514d61e5101a730bac72769882cbe1783
1 parent beb2129 commit 012c9d7

File tree

6 files changed

+64
-43
lines changed

6 files changed

+64
-43
lines changed

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ Topics in this section will help you get started with ExecuTorch.
155155
:hidden:
156156

157157
sdk-overview
158+
sdk-bundled-io
158159
sdk-etrecord
159160
sdk-etdump
160161
sdk-profiling
161162
sdk-inspector
162-
sdk-bundled-io
163163
sdk-delegate-integration
164164

165165
.. toctree::

docs/source/sdk-etdump.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
ETDump (ExecuTorch Dump) is one of the core components of the ExecuTorch SDK experience. It is the mechanism through which all forms of profiling and debugging data is extracted from the runtime. Users can't parse ETDump directly; instead, they should pass it into the Inspector API, which deserializes the data, offering interfaces for flexible analysis and debugging.
44

55

6-
## Generating an ETDump:
6+
## Generating an ETDump
77

88
Generating an ETDump is a relatively straight forward process. Users can follow the steps detailed below to integrate it into their application that uses ExecuTorch.
99

@@ -20,7 +20,7 @@ Result<Method> method =
2020
program->load_method(method_name, &memory_manager, &etdump_gen);
2121
```
2222
23-
3. ***Dump out the ETDump buffer*** - after the inference iterations have been completed, users can dump out the ETDump buffer. If users are on a device which has a file-system, they could just write it out to the fileystem. For more constrained embedded devices, users will have to extract the ETDump buffer from the device through a mechanism that best suits them (e.g. UART, JTAG etc.)
23+
3. ***Dump Out the ETDump Buffer*** - after the inference iterations have been completed, users can dump out the ETDump buffer. If users are on a device which has a file-system, they could just write it out to the fileystem. For more constrained embedded devices, users will have to extract the ETDump buffer from the device through a mechanism that best suits them (e.g. UART, JTAG etc.)
2424
2525
```C++
2626
etdump_result result = etdump_gen.get_etdump_data();
@@ -34,28 +34,31 @@ if (result.buf != nullptr && result.size > 0) {
3434
}
3535
```
3636

37-
4. ***Compile*** your binary with the flags that enable events to be traced and logged into ETDump inside the ExecuTorch runtime. The pre-processor flag that controls this is `ET_EVENT_TRACER_ENABLED`.
37+
4. ***Compile*** your binary with the `ET_EVENT_TRACER_ENABLED` flag to enable events to be traced and logged into ETDump inside the ExecuTorch runtime.
3838

39-
i). ***CMake***
39+
i). ***Buck***
4040

41-
In CMake users can add this to their compile flags:
41+
In Buck, users simply depend on the etdump target which is:
4242
```
43-
-DET_EVENT_TRACER_ENABLED
43+
//executorch/sdk/etdump:etdump_flatcc
44+
```
45+
When compiling their binary through Buck, users can pass in this buck config to enable the pre-processor flag. For example, when compiling `sdk_example_runner` to enable ETDump generation, users compile using the following command:
46+
```
47+
buck2 build -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner
4448
```
4549
46-
ii). ***Buck***
50+
ii). ***CMake***
4751
48-
In Buck users can simply depend on the etdump target which is:
52+
In CMake, users add this to their compile flags:
4953
```
50-
//executorch/sdk/etdump:etdump_flatcc
54+
-DET_EVENT_TRACER_ENABLED
5155
```
52-
When compiling their binary through Buck, users can pass in this buck config which will enable this pre-processor flag:
56+
57+
This flag needs to be added to the ExecuTorch library and any operator library that the users are compiling into their binary. For reference, users can take a look at `examples/sdk/CMakeLists.txt`. The lines of of interest are:
5358
```
54-
buck build -c executorch.event_tracer_enabled=true your_binary_target
59+
target_compile_options(executorch PUBLIC -DET_EVENT_TRACER_ENABLED)
60+
target_compile_options(portable_ops_lib PUBLIC -DET_EVENT_TRACER_ENABLED)
5561
```
62+
## Using an ETDump
5663
57-
TODO : Point to sample runner in examples here.
58-
59-
## Using an ETDump:
60-
61-
1. Pass this ETDump into the [Inspector API](./sdk-inspector.rst) for access to this data and to do post-run analysis on this data.
64+
1. Pass this ETDump into the [Inspector API](./sdk-inspector.rst) to access this data and do post-run analysis.

docs/source/sdk-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ All the components of the SDK have been designed from the ground up with deep in
88

99
The ExecuTorch SDK supports the following features:
1010

11+
- **BundledProgram** is a utility tool for exporting the model bundled with a sample set of (representative) inputs and expected outputs, so that during runtime users can validate that the actual output is in fact the same as the expected output.
1112
- **Profiling** models with operator level breakdown of performance stats
1213
- Linking back operator performance stats to source code and module hierarchy
1314
- Model loading and execution time
14-
- **BundledProgram** is a utility tool for exporting the model bundled with a sample set of (representative) inputs and expected outputs, so that during runtime users can validate that the actual output is in fact the same as the expected output.
1515
- **Delegate Integration** - Surfacing performance details from delegate backends
1616
- Link back delegate operator execution to the nodes they represent in the edge dialect graph (and subsequently linking back to source code and module hierarchy)
1717
- **Debugging** (Intermediate outputs and output quality analysis) - Coming soon

docs/source/sdk-profiling.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Profiling Models in ExecuTorch
22

33
Profiling in ExecuTorch gives users access to these runtime metrics:
4-
- Model loading time.
5-
- Operator level execution time
6-
- Delegate execution time
4+
- Model Load Time.
5+
- Operator Level Execution Time.
6+
- Delegate Execution Time.
77
- If the delegate that the user is calling into has been integrated with the [SDK](./sdk-delegate-integration.md), then users will also be able to access delegated operator execution time.
8-
- End-to-end inference execution time
8+
- End-to-end Inference Execution Time.
99

1010
One uniqe aspect of ExecuTorch Profiling is the ability to link every runtime executed operator back to the exact line of python code from which this operator originated. This capability enables users to easily identify hotspots in their model, source them back to the exact line of Python code, and optimize if chosen to.
1111

@@ -20,4 +20,4 @@ We provide access to all the profiling data via the Python [Inspector API](./sdk
2020
- Through the Inspector API, users can do a wide range of analysis varying from printing out performance details to doing more finer granular calculation on module level.
2121

2222

23-
Please refer to the [SDK tutorial](link to SDK tutorial) for a step-by-step walkthrough of the above process on a sample model.
23+
Please refer to the [SDK tutorial](./tutorials/sdk-integration-tutorial.rst) for a step-by-step walkthrough of the above process on a sample model.

docs/source/tutorials_source/sdk-integration-tutorial.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,23 @@
102102
# ---------------
103103
#
104104
# Next step is to generate an ``ETDump``. ``ETDump`` contains runtime results
105-
# from executing the model. To generate, simply pass the ExecuTorch model
106-
# to the ``executor_runner``::
105+
# from executing the model. To generate, users have two options:
107106
#
108-
# buck2 run executorch/examples/portable/scripts:export -- -m mv2
109-
# buck2 run @mode/opt -c executorch.event_tracer_enabled=true executorch/sdk/runners:executor_runner -- --model_path mv2.pte
107+
# **Option 1:**
110108
#
111-
# TODO: Add Instructions for CMake, when landed
109+
# Use Buck::
110+
#
111+
# python3 -m examples.sdk.scripts.export_bundled_program -m mv2
112+
# buck2_oss run -c executorch.event_tracer_enabled=true examples/sdk/sdk_example_runner:sdk_example_runner -- --bundled_program_path mv2_bundled.bp
113+
#
114+
# **Option 2:**
115+
#
116+
# Use CMake::
117+
# cd executorch
118+
# rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DBUCK2=buck2_oss -DEXECUTORCH_BUILD_SDK=1 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=1 ..
119+
# cd ..
120+
# cmake --build cmake-out -j8 -t sdk_example_runner
121+
# ./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path mv2_bundled.bp
112122

113123
######################################################################
114124
# Creating an Inspector

examples/sdk/sdk_example_runner/sdk_example_runner.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ DEFINE_string(
4040
bundled_program_path,
4141
"model_bundled.bp",
4242
"Model serialized in flatbuffer format.");
43+
4344
DEFINE_string(
4445
prof_result_path,
4546
"prof_result.bin",
@@ -56,6 +57,11 @@ DEFINE_string(
5657
"etdump.etdp",
5758
"If etdump generation is enabled an etdump will be written out to this path");
5859

60+
DEFINE_bool(
61+
output_verification,
62+
false,
63+
"Comapre the model output to the reference outputs present in the BundledProgram.");
64+
5965
using namespace torch::executor;
6066
using torch::executor::util::FileDataLoader;
6167

@@ -255,21 +261,23 @@ int main(int argc, char** argv) {
255261
free(result.buf);
256262
}
257263

258-
// Verify the outputs.
259-
status = torch::executor::util::VerifyResultWithBundledExpectedOutput(
260-
*method,
261-
file_data->data(),
262-
&bundled_input_allocator,
263-
method_name,
264-
FLAGS_testset_idx,
265-
1e-5, // rtol
266-
1e-8 // atol
267-
);
268-
ET_CHECK_MSG(
269-
status == Error::Ok,
270-
"Bundle verification failed with status 0x%" PRIx32,
271-
status);
272-
ET_LOG(Info, "Model verified successfully.");
264+
if (FLAGS_output_verification) {
265+
// Verify the outputs.
266+
status = torch::executor::util::VerifyResultWithBundledExpectedOutput(
267+
*method,
268+
file_data->data(),
269+
&bundled_input_allocator,
270+
method_name,
271+
FLAGS_testset_idx,
272+
1e-4, // rtol
273+
1e-8 // atol
274+
);
275+
ET_CHECK_MSG(
276+
status == Error::Ok,
277+
"Bundle verification failed with status 0x%" PRIx32,
278+
status);
279+
ET_LOG(Info, "Model verified successfully.");
280+
}
273281

274282
return 0;
275283
}

0 commit comments

Comments
 (0)