Skip to content

Commit d5fd03f

Browse files
authored
Depend on c10 alone from aten_device (pytorch#22151)
### Summary `aten_device.h` uses `c10::Device` and the c10 diagnostic macros, and it uses them only from inline functions. Plain c10 is all it needs. The target asks for the `torch-core-cpp` external dep instead. In build environments where that name maps to a library that also contains the ATen operator registry and the mobile interpreter, and where c10 is a separate library, those extra objects collide at link time with the copies the application already links. The link then fails with duplicate symbol errors on things the header never touches, for example `torch::jit::_get_runtime_bytecode_version()` and `c10::TypeParser::lex()`. This adds a `c10` external dep name and points `:aten_device` at it. The dep stays exported because `:aten_device` is header only and its consumers, including `aten_bridge.h`, include the header directly. Follow-up to pytorch#22146, which narrowed the same dep from `libtorch` to `torch-core-cpp`. That removed the ATen operator registry but not the mobile interpreter, so one class of link collision remained. ### Test plan In the open-source buck build `c10` maps to the same `//third-party:libtorch` target that `torch-core-cpp` and `libtorch` map to, so this is a no-op here and CI should stay green. The difference was checked in a build environment where the three names resolve to different targets: - An Android ATen-mode binary that failed to link with duplicate symbols now builds and produces a valid aarch64 executable. The same command at the same revision fails without this change. - A dependency query from `:aten_device` to the ATen operator registry library returns nothing after the change. The same query from `:aten_bridge`, which is unchanged, still returns a path, so the query does detect the dependency when it is there. - `:aten_bridge` and the ATen-mode `etdump_flatcc` build in all three environments where these names resolve differently.
1 parent d6a13e0 commit d5fd03f

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎extension/aten_util/targets.bzl‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ def define_common_targets():
1717
"//executorch/runtime/core/portable_type:device",
1818
"//executorch/runtime/platform:platform",
1919
],
20-
# aten_device.h needs c10::Device and nothing else. The full libtorch
21-
# also registers every ATen operator, which duplicates the
22-
# selective-build operator library in apps that reach this target
23-
# through :aten_bridge, and :aten_bridge is portable mode.
20+
# aten_device.h needs c10::Device and nothing else, and it only uses it
21+
# from inline functions, so plain c10 is enough. Anything wider also
22+
# brings in the ATen operator registry and the mobile interpreter. In
23+
# build environments where those live in a separate library from c10,
24+
# they collide at link time with the copies the application already
25+
# links.
2426
exported_external_deps = [
25-
"torch-core-cpp",
27+
"c10",
2628
],
2729
)
2830

‎shim_et/xplat/executorch/build/env_interface.bzl‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ _EXTERNAL_DEPS = {
2323
"aten-core": [], # TODO(larryliu0820): Add support
2424
# ATen native_functions.yaml file deps
2525
"aten-src-path": "//third-party:aten_src_path",
26+
# Just the c10 core of PyTorch: Device, ScalarType, and the C10_* macros
27+
"c10": "//third-party:libtorch",
2628
"cpuinfo": [], # TODO(larryliu0820): Add support
2729
# Flatbuffer C++ library deps
2830
"flatbuffers-api": "//third-party:flatbuffers-api",

0 commit comments

Comments
 (0)