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)
614
614
endif ()
615
615
616
616
if (EXECUTORCH_BUILD_KERNELS_OPTIMIZED )
617
+ # find pytorch lib here to make it available to all sub-directories
618
+ find_package_torch_headers ()
617
619
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /kernels/optimized )
618
620
endif ()
619
621
@@ -750,7 +752,9 @@ if(EXECUTORCH_BUILD_PYBIND)
750
752
endif ()
751
753
752
754
# 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 ()
754
758
find_library (
755
759
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX} /lib"
756
760
)
Original file line number Diff line number Diff line change @@ -146,7 +146,9 @@ function(gen_custom_ops_aot_lib)
146
146
${_out_dir} /CustomOpsNativeFunctions.h "${GEN_KERNEL_SOURCES} "
147
147
)
148
148
# Find `Torch`.
149
- find_package (Torch REQUIRED )
149
+ if (NOT TARGET torch )
150
+ find_package (Torch REQUIRED )
151
+ endif ()
150
152
# This lib uses ATen lib, so we explicitly enable rtti and exceptions.
151
153
target_compile_options (${GEN_LIB_NAME} PRIVATE -frtti -fexceptions )
152
154
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)
336
336
set (OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}} )
337
337
set (CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} BOTH )
338
338
endforeach ()
339
- find_package (Torch CONFIG REQUIRED )
339
+ if (NOT TARGET torch )
340
+ find_package (Torch CONFIG REQUIRED )
341
+ endif ()
340
342
foreach (mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE )
341
343
set (CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind}} )
342
344
endforeach ()
Original file line number Diff line number Diff line change @@ -69,7 +69,9 @@ install(TARGETS custom_ops DESTINATION lib)
69
69
70
70
if (EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT )
71
71
# Add a AOT library
72
- find_package (Torch CONFIG REQUIRED )
72
+ if (NOT TARGET torch )
73
+ find_package (Torch CONFIG REQUIRED )
74
+ endif ()
73
75
add_library (
74
76
custom_ops_aot_lib SHARED
75
77
${_custom_ops__srcs}
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ message("Generated files ${gen_command_sources}")
61
61
62
62
list (TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT} /" )
63
63
add_library (optimized_kernels ${_optimized_kernels__srcs} )
64
- find_package_torch_headers ()
65
64
target_include_directories (optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT} /third-party/pocketfft" )
66
65
target_link_libraries (
67
66
optimized_kernels PRIVATE executorch_core cpublas extension_threadpool
You can’t perform that action at this time.
0 commit comments