diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d292c209a6..fe22d7dc643 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -638,6 +638,8 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) find_package_torch_headers() endif() +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable/cpu/util) + if(BUILD_EXECUTORCH_PORTABLE_OPS) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable) endif() diff --git a/extension/llm/custom_ops/CMakeLists.txt b/extension/llm/custom_ops/CMakeLists.txt index 42e82dc360f..cf915054ad7 100644 --- a/extension/llm/custom_ops/CMakeLists.txt +++ b/extension/llm/custom_ops/CMakeLists.txt @@ -119,7 +119,7 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT) else() # If no portable_lib, custom_ops_aot_lib still gives the ability to use the # ops in PyTorch - target_link_libraries(custom_ops_aot_lib PUBLIC executorch_core) + target_link_libraries(custom_ops_aot_lib PUBLIC executorch_core kernels_util_all_deps) endif() target_link_libraries( diff --git a/extension/training/CMakeLists.txt b/extension/training/CMakeLists.txt index ee496a7e577..21d4f496978 100644 --- a/extension/training/CMakeLists.txt +++ b/extension/training/CMakeLists.txt @@ -25,8 +25,8 @@ target_include_directories( target_include_directories(extension_training PUBLIC ${EXECUTORCH_ROOT}/..) target_compile_options(extension_training PUBLIC ${_common_compile_options}) -target_link_libraries(extension_training executorch_core - extension_data_loader extension_module_static extension_tensor extension_flat_tensor) +target_link_libraries(extension_training executorch_core kernels_util_all_deps + extension_data_loader extension_module_static extension_tensor extension_flat_tensor ) list(TRANSFORM _train_xor__srcs PREPEND "${EXECUTORCH_ROOT}/") diff --git a/kernels/optimized/CMakeLists.txt b/kernels/optimized/CMakeLists.txt index 85c829469be..ae6d8e6fcd3 100644 --- a/kernels/optimized/CMakeLists.txt +++ b/kernels/optimized/CMakeLists.txt @@ -64,7 +64,7 @@ add_library(optimized_kernels ${_optimized_kernels__srcs}) target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT}/third-party/pocketfft") target_compile_definitions(optimized_kernels PRIVATE ET_USE_PYTORCH_HEADERS) target_link_libraries( - optimized_kernels PUBLIC executorch_core cpublas extension_threadpool + optimized_kernels PUBLIC executorch_core cpublas extension_threadpool kernels_util_all_deps ) target_compile_options(optimized_kernels PUBLIC ${_common_compile_options}) # Build a library for _optimized_kernels_srcs diff --git a/kernels/portable/CMakeLists.txt b/kernels/portable/CMakeLists.txt index db0f6b710c6..4094225c3db 100644 --- a/kernels/portable/CMakeLists.txt +++ b/kernels/portable/CMakeLists.txt @@ -52,7 +52,7 @@ message("Generated files ${gen_command_sources}") # Focused on portability and understandability rather than speed. # add_library(portable_kernels ${_portable_kernels__srcs}) -target_link_libraries(portable_kernels PRIVATE executorch_core) +target_link_libraries(portable_kernels PRIVATE executorch_core kernels_util_all_deps) target_compile_options(portable_kernels PUBLIC ${_common_compile_options}) # Build a library for _portable_kernels__srcs diff --git a/kernels/portable/cpu/util/CMakeLists.txt b/kernels/portable/cpu/util/CMakeLists.txt new file mode 100644 index 00000000000..8a2da87936d --- /dev/null +++ b/kernels/portable/cpu/util/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# Kernel library for portable kernels. Please this file formatted by running: +# ~~~ +# cmake-format -i CMakeLists.txt +# ~~~ + +cmake_minimum_required(VERSION 3.19) + +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() + +if(NOT EXECUTORCH_ROOT) + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +endif() + +list(TRANSFORM _kernels_util_all_deps__srcs PREPEND "${EXECUTORCH_ROOT}/") + +set(_common_compile_options -Wno-deprecated-declarations) + +add_library(kernels_util_all_deps ${_kernels_util_all_deps__srcs}) +target_link_libraries(kernels_util_all_deps PRIVATE executorch_core) +target_include_directories(kernels_util_all_deps PUBLIC ${_common_include_directories}) +target_compile_definitions(kernels_util_all_deps PUBLIC C10_USING_CUSTOM_GENERATED_MACROS) +target_compile_options(kernels_util_all_deps PUBLIC ${_common_compile_options}) diff --git a/kernels/quantized/CMakeLists.txt b/kernels/quantized/CMakeLists.txt index 149db0c17f6..1c4e952b6ae 100644 --- a/kernels/quantized/CMakeLists.txt +++ b/kernels/quantized/CMakeLists.txt @@ -142,7 +142,7 @@ if(NOT CMAKE_GENERATOR STREQUAL "Xcode" endif() add_library(quantized_kernels ${_quantized_kernels__srcs}) -target_link_libraries(quantized_kernels PRIVATE executorch_core) +target_link_libraries(quantized_kernels PRIVATE executorch_core kernels_util_all_deps) target_compile_options(quantized_kernels PUBLIC ${_common_compile_options}) # Build a library for _quantized_kernels_srcs # diff --git a/tools/cmake/cmake_deps.toml b/tools/cmake/cmake_deps.toml index 78befd62aac..6f12c9d4413 100644 --- a/tools/cmake/cmake_deps.toml +++ b/tools/cmake/cmake_deps.toml @@ -56,6 +56,20 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_threadpool", + "kernels_util_all_deps", +] + +[targets.kernels_util_all_deps] +buck_targets = [ + "//kernels/portable/cpu/util:all_deps", +] +filters = [ + ".cpp$", +] +deps = [ + "executorch_core", + "extension_threadpool", ] # HACK: prevent reduce_util from also showing up in custom_ops. The @@ -89,6 +103,7 @@ deps = [ "executorch", "executorch_core", "extension_threadpool", + "kernels_util_all_deps", "optimized_cpublas", "portable_kernels", ] @@ -108,6 +123,8 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_threadpool", + "kernels_util_all_deps", "portable_kernels", ] @@ -147,6 +164,7 @@ deps = [ "executorch_core", "executorch", "extension_threadpool", + "kernels_util_all_deps", "optimized_cpublas", "portable_kernels", ] @@ -288,6 +306,8 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_threadpool", + "kernels_util_all_deps", "portable_kernels", ] # ---------------------------------- extension end ---------------------------------- @@ -306,6 +326,8 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_threadpool", + "kernels_util_all_deps", "portable_kernels", "quantized_kernels", "etdump_flatcc", @@ -340,6 +362,8 @@ excludes = [ deps = [ "executorch", "executorch_core", + "extension_threadpool", + "kernels_util_all_deps", "portable_kernels", ] @@ -380,6 +404,7 @@ deps = [ "executorch", "executorch_core", "extension_threadpool", + "kernels_util_all_deps", "xnnpack_backend", "portable_kernels", "etdump_flatcc", @@ -455,6 +480,7 @@ deps = [ "extension_module", "extension_tensor", "extension_threadpool", + "kernels_util_all_deps", "optimized_cpublas", "portable_kernels", "quantized_kernels",