Skip to content

Commit 3a21f4d

Browse files
committed
Shorten the torch_cpu_library comments and give aten_bridge its real reason
The same three-line comment sat at five link sites. It explained why the line does not link torch, but not why it does not link plain torch_cpu, and "in a CUDA build" read as our own CUDA option rather than how PyTorch was built. Replace it with one line at each site that names both reasons: torch adds libtorch_cuda with a CUDA build of PyTorch, and torch_cpu adds MKL to the link. At aten_bridge the old wording was also misleading. That target is a static library, so it is never loaded on its own. The link matters because a static library passes it on to _training_lib, so the comment now says that.
1 parent adb1236 commit 3a21f4d

5 files changed

Lines changed: 6 additions & 15 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 this link reaches _training_lib, where torch
1454+
# adds libtorch_cuda with a CUDA build of PyTorch and torch_cpu adds MKL.
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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ 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 adds libtorch_cuda with a CUDA build of PyTorch; torch_cpu adds MKL.
236234
target_link_libraries(
237235
custom_ops_aot_lib PUBLIC cpublas torch_cpu_library extension_tensor
238236
extension_threadpool

‎extension/llm/runner/CMakeLists.txt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ 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 adds libtorch_cuda with a CUDA build of PyTorch; torch_cpu adds MKL.
128126
target_link_libraries(
129127
_llm_runner PRIVATE extension_llm_runner tokenizers::tokenizers
130128
portable_lib ${TORCH_PYTHON_LIBRARY} torch_cpu_library

‎extension/training/CMakeLists.txt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ 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 adds libtorch_cuda with a CUDA build of PyTorch; torch_cpu adds MKL.
5957
if(EXECUTORCH_BUILD_SHARED)
6058
set(_pybind_training_dep_libs ${TORCH_PYTHON_LIBRARY} etdump aten_bridge
6159
torch_cpu_library extension_training

‎tools/cmake/Codegen.cmake‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ 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 adds libtorch_cuda with a CUDA build of PyTorch; torch_cpu adds MKL.
340338
target_link_libraries(${GEN_LIB_NAME} PRIVATE torch_cpu_library)
341339

342340
executorch_target_link_options_shared_lib(${GEN_LIB_NAME})

0 commit comments

Comments
 (0)