Repository navigation
Commit 8b76a3e
Add ETDump profiling to the Apple frameworks and SwiftPM package (pytorch#22205)
## Summary
This adds **ETDump profiling** to the ExecuTorch SwiftPM package and
Apple frameworks. An ETDump is the profiling trace that records which
operators ran and how long they took. Before this, collecting one was
only possible from the pip wheel; now a Swift or C++ app can do it
directly.
## Design
**A separate framework.** ETDump ships as its own `ExecuTorchETDump`
framework rather than being folded into the core `executorch` framework.
That keeps the profiler and its `flatcc` serialization dependency out of
the runtime for apps that do not profile. It is built only when the
runtime is compiled with the tracing hooks on
(`EXECUTORCH_BUILD_DEVTOOLS` + `EXECUTORCH_ENABLE_EVENT_TRACER`), which
the Apple presets now enable.
**The tracer seam.** The profiler needs its tracer installed when the
model is constructed. The C++ `Module` takes its tracer at construction,
but an Objective-C category cannot add a designated initializer (doing
so makes the compiler treat the public initializers as convenience ones
that fail to chain). So an internal class method on `ExecuTorchModule`
builds a module with a tracer attached, leaving the public initializers
untouched. The `ETDump` object owns the module and reads the trace back
through it, so the tracer lives exactly as long as the module.
## Usage
```swift
let etdump = try ETDump(filePath: "model.pte")
_ = try etdump.module.forward([input])
let data = try etdump.takeData() // the trace, ready to save
// or straight to disk:
try etdump.takeData(toFile: "trace.etdump")
```
`ETDump.isAvailable` reports whether the build included the profiler.
## What changed
- `extension/apple/etdump/`: the new `ExecuTorchETDump` framework
(public `ETDump` API + error enum) and its CMake.
- `extension/apple/ExecuTorch/Internal/ExecuTorchModule+Internal.h` +
`ExecuTorchModule.mm`: the internal class-method seam that attaches a
tracer; public API unchanged.
- `tools/cmake/preset/default.cmake`: the
`EXECUTORCH_BUILD_EXTENSION_ETDUMP_APPLE` option, requiring the devtools
and event-tracer options.
- `tools/cmake/preset/apple_common.cmake`: enable the profiler and the
extension for Apple builds.
- `scripts/build_apple_frameworks.sh` + `.github/workflows/apple.yml`:
build and publish the framework.
- `Package.swift`: the `executorch_etdump` product.
A companion change to the package template branch adds the product to
the published manifest.
## Test plan
- Compiled the module seam and the wrapper against the runtime headers:
zero errors and no new warnings, in particular none of the
designated-initializer warnings the category approach produced.
- Confirmed the SwiftPM manifest parses with the `executorch_etdump`
product depending on `executorch`.
- Verified the build option requires the devtools and event-tracer
options and fails fast without them.
- Device and simulator builds are exercised by the Apple CI jobs this
adds the framework to.
---------
Co-authored-by: PyTorch Bot <pytorchbot@users.noreply.github.com>1 parent 16d3b9f commit 8b76a3e
25 files changed
Lines changed: 1220 additions & 205 deletions
File tree
- .Package.swift
- executorch_dump_debug
- executorch_dump
- .github/workflows
- docs/source
- extension/apple
- ExecuTorch
- Exported
- Internal
- dump
- ExecuTorchDump
- Exported
- Internal
- __tests__
- resources
- scripts
- tools/cmake/preset
Whitespace-only changes.
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| 195 | + | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
| |||
298 | 300 | | |
299 | 301 | | |
300 | 302 | | |
301 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
302 | 312 | | |
303 | 313 | | |
304 | 314 | | |
| |||
354 | 364 | | |
355 | 365 | | |
356 | 366 | | |
357 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
358 | 372 | | |
359 | 373 | | |
360 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1172 | 1172 | | |
1173 | 1173 | | |
1174 | 1174 | | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
1178 | 1181 | | |
1179 | 1182 | | |
1180 | 1183 | | |
| |||
1536 | 1539 | | |
1537 | 1540 | | |
1538 | 1541 | | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
1539 | 1546 | | |
1540 | 1547 | | |
1541 | 1548 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| |||
189 | 194 | | |
190 | 195 | | |
191 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
192 | 202 | | |
193 | 203 | | |
194 | 204 | | |
| |||
238 | 248 | | |
239 | 249 | | |
240 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
241 | 262 | | |
242 | 263 | | |
243 | 264 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments