Commit a80d833
committed
Guard aten_device.h against -Wswitch-enum
The new header switches over c10::DeviceType to map a PyTorch device onto
an ExecuTorch one. That enum has over twenty values, and a build with
-Wswitch-enum turned on asks for every one of them to be listed even
though the switch already has a default. So the header does not compile
there.
This was hidden before. The same code used to live in aten_bridge.cpp, and
the aten_bridge library is built with -Wno-error, which demotes the
warning. Moving the code into a header exposed it to ETDump, which has no
such setting.
The fix wraps the file in
C10_DIAGNOSTIC_PUSH_AND_IGNORED_IF_DEFINED("-Wswitch-enum"), the same way
extension/tensor/tensor_ptr.h already does for its own switch over a c10
enum. Plain -Wswitch is left alone, so forgetting to handle a new
ExecuTorch device type is still a compile error.
Three smaller corrections to the previous commit come with it:
- The comment on the new Buck target was wrong. Splitting device.h out
does not keep the portable Tensor out of an ATen mode target, because
the ETDump target already reaches it through
runtime/core:device_allocator. The split is still worth doing, so that a
caller wanting only Device does not depend on every portable type. That
is the same reason :scalar_type is split out, and the comment now says
so.
- aten_bridge.h no longer uses std::optional, so its <optional> include is
removed.
- The new comments are shortened.
Test plan: compiled aten_device.h and the ETDump device helper with and
without USE_ATEN_LIB, under -Wall -Wextra -Wswitch-enum -Werror, against
PyTorch headers on Linux x86_64. All four are clean. Removing only the new
guard puts the 20 -Wswitch-enum errors back, so the guard is doing the
work. Adding a third ExecuTorch device type still fails the build through
plain -Wswitch, so the guard does not hide that. Also recompiled
aten_bridge.cpp and the exact call shapes the existing aten_bridge test
uses, in portable mode.1 parent f47a717 commit a80d833
4 files changed
Lines changed: 16 additions & 13 deletions
File tree
- extension/aten_util
- runtime/core/portable_type
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | | - | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
0 commit comments