Repository navigation
Commit 6a36ebe
authored
Fix the ATen mode build of ETDump (pytorch#22135)
### Summary
ETDump maps the device a tensor lives on to the runtime device type so
it can pick the right allocator. In ATen mode it did that by calling
`torch_to_executorch_device` from `extension/aten_util/aten_bridge.h`.
That header cannot be included from a file compiled with `USE_ATEN_LIB`.
It declares functions over `torch::executor::ScalarType` and
`torch::executor::Tensor`, and those two names only exist when
`runtime/core/exec_aten/exec_aten.h` takes its non ATen branch. So the
include fired in exactly the one mode where it does not compile, and the
ATen flavor of the ETDump library failed to build with 7 errors like:
```
no type named 'ScalarType' in namespace 'torch::executor'
```
Nothing in the CMake build compiles these files in ATen mode, so this is
invisible in the CMake based CI jobs and only shows up for the Buck
targets that carry the `_aten` suffix.
### What this changes
* New header `extension/aten_util/aten_device.h` holds the two device
conversions. They are small and self contained, so they are now `inline`
functions that need only `c10/core/Device.h` and the portable `Device`
type, and they compile in both modes.
* `aten_bridge.h` includes the new header and keeps exporting the same
names, so its callers do not change. It also gains a short note saying
it is portable mode only, so the same include does not come back later.
* `etdump_flatcc.cpp` includes the new header instead of the whole
portable mode bridge, and the ATen only Buck dep points at the new
target.
* The portable `Device` type gets its own Buck target, so a caller that
wants only `Device` does not have to depend on every portable type. This
mirrors the existing `:scalar_type` split in the same file.
* The new header is wrapped in
`C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wswitch-enum")`.
`c10::DeviceType` has over twenty values, and `-Wswitch-enum` asks for
every one to be listed even when the switch already has a default.
`extension/tensor/tensor_ptr.h` already does the same thing for its own
switch over a c10 enum. Plain `-Wswitch` is left alone, so an unhandled
new ExecuTorch device type is still a compile error.
No behavior change. The mapping itself is byte for byte the same code,
just moved.
### Test plan
Compiled with `-Wall -Wextra -Wswitch-enum -Werror` against PyTorch
headers on Linux x86_64:
| what | ATen mode | portable mode |
| --- | --- | --- |
| `aten_device.h` | clean | clean |
| the ETDump device helper | clean | clean |
| `aten_bridge.cpp` | not applicable | clean |
| the call shapes the existing `aten_bridge` test uses | not applicable
| clean |
Each check was confirmed to fail when its fix is removed, so none of
them is a test that cannot fail:
* Without the move, the ATen mode compile of the ETDump helper fails
with the 7 errors above.
* Without the `-Wswitch-enum` guard, `aten_device.h` fails with 20
errors.
* Adding a third value to the portable `DeviceType` enum still fails the
build through plain `-Wswitch`, so the guard does not hide a missing
case.
What is not covered: no job in this repository builds the `_aten` Buck
targets, so CI on this pull request exercises the portable build only.
The ATen mode results above come from compiling those translation units
by hand.1 parent 6b53322 commit 6a36ebe
7 files changed
Lines changed: 110 additions & 48 deletions
File tree
- devtools/etdump
- extension/aten_util
- runtime/core/portable_type
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 138 | + | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | 137 | | |
168 | 138 | | |
169 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
11 | 16 | | |
12 | 17 | | |
13 | | - | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
21 | | - | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 36 | | |
47 | 37 | | |
48 | 38 | | |
| |||
| 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 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
10 | 25 | | |
11 | 26 | | |
12 | 27 | | |
| |||
23 | 38 | | |
24 | 39 | | |
25 | 40 | | |
| 41 | + | |
26 | 42 | | |
27 | 43 | | |
28 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
49 | 63 | | |
50 | 64 | | |
51 | 65 | | |
| |||
0 commit comments