Skip to content

Commit 2ba0ae5

Browse files
committed
Update base for 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]
1 parent fd0f790 commit 2ba0ae5

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
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()

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)