File tree Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Expand file tree Collapse file tree 4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -602,6 +602,13 @@ target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
602602target_compile_options (executorch PUBLIC ${_common_compile_options} )
603603target_link_options_shared_lib(executorch)
604604
605+ #
606+ # find pytorch lib here to make it available to all sub-directories, trying to
607+ # call find_package(Torch) multiple times doesn't work because it brings in MKL
608+ # which is defined once globally
609+ #
610+ find_package (Torch CONFIG REQUIRED)
611+
605612#
606613# portable_ops_lib: A library to register core ATen ops using portable kernels,
607614# see kernels/portable/CMakeLists.txt.
@@ -749,8 +756,7 @@ if(EXECUTORCH_BUILD_PYBIND)
749756 add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /devtools)
750757 endif ()
751758
752- # find pytorch lib, to allow pybind to take at::Tensor as input/output
753- find_package (Torch CONFIG REQUIRED)
759+ # to allow pybind to take at::Tensor as input/output
754760 find_library (
755761 TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX} /lib"
756762 )
Original file line number Diff line number Diff line change @@ -146,7 +146,9 @@ function(gen_custom_ops_aot_lib)
146146 ${_out_dir} /CustomOpsNativeFunctions.h "${GEN_KERNEL_SOURCES} "
147147 )
148148 # Find `Torch`.
149- find_package (Torch REQUIRED)
149+ if (NOT TARGET torch)
150+ find_package (Torch REQUIRED)
151+ endif ()
150152 # This lib uses ATen lib, so we explicitly enable rtti and exceptions.
151153 target_compile_options (${GEN_LIB_NAME} PRIVATE -frtti -fexceptions)
152154 target_compile_definitions (${GEN_LIB_NAME} PRIVATE USE_ATEN_LIB=1)
Original file line number Diff line number Diff line change @@ -336,7 +336,9 @@ macro(find_package_torch_headers)
336336 set (OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} })
337337 set (CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} BOTH)
338338 endforeach ()
339- find_package (Torch CONFIG REQUIRED)
339+ if (NOT TARGET torch)
340+ find_package (Torch CONFIG REQUIRED)
341+ endif ()
340342 foreach (mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE )
341343 set (CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} })
342344 endforeach ()
Original file line number Diff line number Diff line change @@ -69,7 +69,9 @@ install(TARGETS custom_ops DESTINATION lib)
6969
7070if (EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
7171 # Add a AOT library
72- find_package (Torch CONFIG REQUIRED)
72+ if (NOT TARGET torch)
73+ find_package (Torch CONFIG REQUIRED)
74+ endif ()
7375 add_library (
7476 custom_ops_aot_lib SHARED
7577 ${_custom_ops__srcs}
You can’t perform that action at this time.
0 commit comments