File tree Expand file tree Collapse file tree 5 files changed +14
-5
lines changed Expand file tree Collapse file tree 5 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -614,6 +614,8 @@ if(BUILD_EXECUTORCH_PORTABLE_OPS)
614614endif ()
615615
616616if (EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
617+ # find pytorch lib here to make it available to all sub-directories
618+ find_package_torch_headers()
617619 add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /kernels/optimized)
618620endif ()
619621
@@ -750,7 +752,9 @@ if(EXECUTORCH_BUILD_PYBIND)
750752 endif ()
751753
752754 # find pytorch lib, to allow pybind to take at::Tensor as input/output
753- find_package (Torch CONFIG REQUIRED)
755+ if (NOT TARGET torch)
756+ find_package (Torch CONFIG REQUIRED)
757+ endif ()
754758 find_library (
755759 TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX} /lib"
756760 )
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}
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ message("Generated files ${gen_command_sources}")
6161
6262list (TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT} /" )
6363add_library (optimized_kernels ${_optimized_kernels__srcs} )
64- find_package_torch_headers()
6564target_include_directories (optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT} /third-party/pocketfft" )
6665target_link_libraries (
6766 optimized_kernels PRIVATE executorch_core cpublas extension_threadpool
You can’t perform that action at this time.
0 commit comments