Skip to content

Commit 4a3726e

Browse files
committed
Update on "Remove ExecuTorch copy of Vectorized"
All uses are outside ExecuTorch core, so we can just use ATen Vectorized. Differential Revision: [D66396016](https://our.internmc.facebook.com/intern/diff/D66396016/) [ghstack-poisoned]
2 parents ccafe18 + 2ba0ae5 commit 4a3726e

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

build/Utils.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,20 @@ function(resolve_python_executable)
321321
)
322322
endif()
323323
endfunction()
324+
325+
# find_package(Torch CONFIG REQUIRED) replacement for targets that
326+
# have a header-only Torch dependency. Because find_package sets
327+
# variables in the parent scope, we use a macro to preserve this
328+
# rather than maintaining our own list of those variables.
329+
macro(find_package_torch_headers)
330+
# We cannot simply use CMAKE_FIND_ROOT_PATH_BOTH, because that does
331+
# not propagate into TorchConfig.cmake.
332+
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
333+
set(OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}})
334+
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} BOTH)
335+
endforeach()
336+
find_package(Torch CONFIG REQUIRED)
337+
foreach(mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE)
338+
set(CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}})
339+
endforeach()
340+
endmacro()

extension/llm/custom_ops/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ target_compile_options(
6868
install(TARGETS custom_ops DESTINATION lib)
6969

7070
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
71-
# Use NO_CMAKE_FIND_ROOT_PATH to make sure this works even if cross-compiling.
72-
# See note in kernels/optimized/CMakeLists.txt.
73-
find_package(Torch CONFIG REQUIRED NO_CMAKE_FIND_ROOT_PATH)
71+
find_package_torch_headers()
7472
add_library(
7573
custom_ops_aot_lib SHARED
7674
${_custom_ops__srcs}

kernels/optimized/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,7 @@ message("Generated files ${gen_command_sources}")
6363

6464
list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
6565
add_library(optimized_kernels ${_optimized_kernels__srcs})
66-
# We require Torch headers, which setup.py puts in CMAKE_PREFIX_PATH
67-
# for us. Toolchains that we might be using for cross-compiling could
68-
# set CMAKE_FIND_ROOT_PATH, which prevents find_package from finding
69-
# headers not rooted under CMAKE_FIND_ROOT_PATH. This is reasonable
70-
# for binary dependencies because they probably aren't built for the
71-
# target platform, but for our header-only use case, we should just
72-
# ignore CMAKE_FIND_ROOT_PATH.
73-
find_package(Torch CONFIG REQUIRED NO_CMAKE_FIND_ROOT_PATH)
66+
find_package_torch_headers()
7467
target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS})
7568
target_link_libraries(
7669
optimized_kernels PRIVATE executorch_core cpublas extension_threadpool

0 commit comments

Comments
 (0)