Skip to content

Commit f705b01

Browse files
committed
Fix multiple MKL targets
1 parent 169c57d commit f705b01

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ if(BUILD_EXECUTORCH_PORTABLE_OPS)
614614
endif()
615615

616616
if(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)
618620
endif()
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
)

build/Codegen.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

build/Utils.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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()

extension/llm/custom_ops/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ install(TARGETS custom_ops DESTINATION lib)
6969

7070
if(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}

kernels/optimized/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ message("Generated files ${gen_command_sources}")
6161

6262
list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
6363
add_library(optimized_kernels ${_optimized_kernels__srcs})
64-
find_package_torch_headers()
6564
target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT}/third-party/pocketfft")
6665
target_link_libraries(
6766
optimized_kernels PRIVATE executorch_core cpublas extension_threadpool

0 commit comments

Comments
 (0)