Skip to content

Commit 766d630

Browse files
committed
Fix the torch_cpu_library comments and make aten_bridge static
The same three-line comment sat at five link sites. It explained why the line does not link torch, but not what torch_cpu_library does differently, and "in a CUDA build" read as our own CUDA option rather than how PyTorch was built. Each site now says that torch records libtorch_cuda with a CUDA build of PyTorch, so a CPU-only torch could not load the library, and that torch_cpu_library does not. At aten_bridge the old reason did not apply. aten_bridge is a static library and is never loaded on its own. Its link matters because it is passed on to _training_lib. But it was only static by default: with BUILD_SHARED_LIBS=ON it became a shared library. Mark it STATIC so the comment holds in every layout. Nothing installs it and only _training_lib links it.
1 parent 8f0ae45 commit 766d630

5 files changed

Lines changed: 11 additions & 16 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ if(EXECUTORCH_BUILD_PYBIND)
14391439
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib"
14401440
)
14411441
add_library(
1442-
aten_bridge
1442+
aten_bridge STATIC
14431443
${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp
14441444
)
14451445
set_target_properties(aten_bridge PROPERTIES CXX_STANDARD 20)
@@ -1450,9 +1450,8 @@ if(EXECUTORCH_BUILD_PYBIND)
14501450
aten_bridge PUBLIC C10_USING_CUSTOM_GENERATED_MACROS
14511451
)
14521452
target_compile_options(aten_bridge PUBLIC ${_pybind_compile_options})
1453-
# torch_cpu_library is the CPU half of torch. Linking torch would also force
1454-
# libtorch_cuda into DT_NEEDED in a CUDA build, and a CPU-only torch could
1455-
# then not load this library.
1453+
# aten_bridge is static, so _training_lib gets this link. torch would record
1454+
# libtorch_cuda with a CUDA build of PyTorch; torch_cpu_library does not.
14561455
if(EXECUTORCH_BUILD_SHARED)
14571456
target_link_libraries(
14581457
aten_bridge PRIVATE torch_cpu_library c10 executorch_shared

‎extension/llm/custom_ops/CMakeLists.txt‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,8 @@ if(EXECUTORCH_BUILD_KERNELS_LLM_AOT)
230230
endif()
231231
executorch_target_link_shared_runtime(custom_ops_aot_lib)
232232

233-
# torch_cpu_library is the CPU half of torch. Linking torch would also force
234-
# libtorch_cuda into DT_NEEDED in a CUDA build, and a CPU-only torch could
235-
# then not load this library.
233+
# torch would record libtorch_cuda with a CUDA build of PyTorch, so a CPU-only
234+
# torch could not load this. torch_cpu_library does not.
236235
target_link_libraries(
237236
custom_ops_aot_lib PUBLIC cpublas torch_cpu_library extension_tensor
238237
extension_threadpool

‎extension/llm/runner/CMakeLists.txt‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ if(EXECUTORCH_BUILD_PYBIND)
122122
)
123123
# Link with the extension_llm_runner library and its dependencies.
124124
#
125-
# torch_cpu_library is the CPU half of torch. Linking torch would also force
126-
# libtorch_cuda into DT_NEEDED in a CUDA build, and a CPU-only torch could
127-
# then not load this library.
125+
# torch would record libtorch_cuda with a CUDA build of PyTorch, so a CPU-only
126+
# torch could not load this. torch_cpu_library does not.
128127
target_link_libraries(
129128
_llm_runner PRIVATE extension_llm_runner tokenizers::tokenizers
130129
portable_lib ${TORCH_PYTHON_LIBRARY} torch_cpu_library

‎extension/training/CMakeLists.txt‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ if(EXECUTORCH_BUILD_PYBIND)
5353
# is resolved from it rather than from the whole-archive-forcing static
5454
# `executorch` target, so this module shares the one backend registry.
5555
#
56-
# torch_cpu_library is the CPU half of torch. Linking torch would also force
57-
# libtorch_cuda into DT_NEEDED in a CUDA build, and a CPU-only torch could
58-
# then not load this library.
56+
# torch would record libtorch_cuda with a CUDA build of PyTorch, so a CPU-only
57+
# torch could not load this. torch_cpu_library does not.
5958
if(EXECUTORCH_BUILD_SHARED)
6059
set(_pybind_training_dep_libs ${TORCH_PYTHON_LIBRARY} etdump aten_bridge
6160
torch_cpu_library extension_training

‎tools/cmake/Codegen.cmake‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,8 @@ function(gen_custom_ops_aot_lib)
334334
set_target_properties(${GEN_LIB_NAME} PROPERTIES CXX_STANDARD 20)
335335
target_compile_definitions(${GEN_LIB_NAME} PRIVATE USE_ATEN_LIB=1)
336336
include_directories(${TORCH_INCLUDE_DIRS})
337-
# torch_cpu_library is the CPU half of torch. Linking torch would also force
338-
# libtorch_cuda into DT_NEEDED in a CUDA build, and a CPU-only torch could
339-
# then not load this library.
337+
# torch would record libtorch_cuda with a CUDA build of PyTorch, so a CPU-only
338+
# torch could not load this. torch_cpu_library does not.
340339
target_link_libraries(${GEN_LIB_NAME} PRIVATE torch_cpu_library)
341340

342341
executorch_target_link_options_shared_lib(${GEN_LIB_NAME})

0 commit comments

Comments
 (0)