Skip to content

Add basic parallel_for support to reduce_util #8986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ exclude_patterns = [
'examples/**',
'extension/**',
'kernels/optimized/**',
# Justified <functional> include.
'runtime/kernel/thread_parallel_interface.h',
'scripts/**',
'third-party/**',
'util/**',
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ if(EXECUTORCH_BUILD_PTHREADPOOL
AND EXECUTORCH_BUILD_CPUINFO
)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/threadpool)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/parallel)
endif()

if(EXECUTORCH_BUILD_PYBIND)
Expand Down
1 change: 0 additions & 1 deletion Test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ if(BUILD_TESTING)
add_subdirectory(extension/evalue_util/test)
add_subdirectory(extension/kernel_util/test)
add_subdirectory(extension/memory_allocator/test)
add_subdirectory(extension/parallel/test)
add_subdirectory(extension/pytree/test)
add_subdirectory(kernels/portable/cpu/util/test)
add_subdirectory(kernels/prim_ops/test)
Expand Down
38 changes: 20 additions & 18 deletions build/cmake_deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ deps = [
"executorch_core",
]

# HACK: prevent reduce_util from also showing up in custom_ops. The
# actual medium-term fix is to stop using Buck to drive our CMake
# builds.
[targets.reduce_util]
buck_targets = [
"//kernels/portable/cpu/util:reduce_util",
]
filters = [
".cpp$",
]
deps = [
"executorch",
"executorch_core",
]

[targets.optimized_kernels]
buck_targets = [
"//kernels/optimized:generated_lib",
Expand All @@ -73,7 +88,6 @@ excludes = [
deps = [
"executorch",
"executorch_core",
"extension_parallel",
"extension_threadpool",
"portable_kernels",
]
Expand Down Expand Up @@ -116,7 +130,7 @@ excludes = [
deps = [
"executorch_core",
"executorch",
"extension_parallel",
"extension_threadpool",
]

[targets.optimized_native_cpu_ops]
Expand All @@ -131,7 +145,6 @@ excludes = [
deps = [
"executorch_core",
"executorch",
"extension_parallel",
"extension_threadpool",
"portable_kernels",
]
Expand Down Expand Up @@ -212,19 +225,6 @@ deps = [
"extension_runner_util",
]

[targets.extension_parallel]
buck_targets = [
"//extension/parallel:thread_parallel",
]
filters = [
".cpp$",
]
deps = [
"executorch",
"executorch_core",
"extension_threadpool",
]

[targets.extension_tensor]
buck_targets = [
"//extension/tensor:tensor",
Expand Down Expand Up @@ -364,6 +364,7 @@ excludes = [
deps = [
"executorch",
"executorch_core",
"extension_threadpool",
"xnnpack_backend",
"portable_kernels",
]
Expand All @@ -378,6 +379,7 @@ filters = [
deps = [
"executorch",
"executorch_core",
"extension_threadpool",
]

[targets.xnnpack_schema]
Expand Down Expand Up @@ -412,8 +414,8 @@ deps = [
"executorch",
"executorch_core",
"optimized_kernels",
"extension_parallel",
"extension_threadpool",
"reduce_util",
"xnnpack_backend",
]

Expand Down Expand Up @@ -449,7 +451,7 @@ deps = [
"executorch_core",
"extension_data_loader",
"extension_module",
"extension_parallel",
"extension_threadpool",
"portable_kernels",
"quantized_kernels",
"xnnpack_backend",
Expand Down
44 changes: 27 additions & 17 deletions build/executorch-config.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
Expand All @@ -16,20 +15,23 @@
#
# This will define the following variables:
#
# EXECUTORCH_FOUND -- True if the system has the ExecuTorch library
# EXECUTORCH_INCLUDE_DIRS -- The include directories for ExecuTorch
# EXECUTORCH_LIBRARIES -- Libraries to link against
# EXECUTORCH_FOUND -- True if the system has the ExecuTorch library
# EXECUTORCH_INCLUDE_DIRS -- The include directories for ExecuTorch
# EXECUTORCH_LIBRARIES -- Libraries to link against
#
# The actual values for these variables will be different from what executorch-config.cmake
# in executorch pip package gives, but we wanted to keep the contract of exposing these
# CMake variables.
# The actual values for these variables will be different from what
# executorch-config.cmake in executorch pip package gives, but we wanted to keep
# the contract of exposing these CMake variables.

cmake_minimum_required(VERSION 3.19)

set(_root "${CMAKE_CURRENT_LIST_DIR}/../../..")
set(required_lib_list executorch executorch_core portable_kernels)
set(EXECUTORCH_LIBRARIES)
set(EXECUTORCH_INCLUDE_DIRS ${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10 ${_root}/lib)
set(EXECUTORCH_INCLUDE_DIRS
${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10
${_root}/lib
)
foreach(lib ${required_lib_list})
set(lib_var "LIB_${lib}")
add_library(${lib} STATIC IMPORTED)
Expand All @@ -40,7 +42,12 @@ foreach(lib ${required_lib_list})
)
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
target_compile_definitions(${lib} INTERFACE C10_USING_CUSTOM_GENERATED_MACROS)
target_include_directories(${lib} INTERFACE ${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10 ${_root}/lib)
target_include_directories(
${lib}
INTERFACE ${_root}/include
${_root}/include/executorch/runtime/core/portable_type/c10
${_root}/lib
)
list(APPEND EXECUTORCH_LIBRARIES ${lib})
endforeach()

Expand All @@ -65,9 +72,9 @@ set(lib_list
neuron_backend
qnn_executorch_backend
portable_ops_lib
custom_ops
extension_module
extension_module_static
extension_parallel
extension_runner_util
extension_tensor
extension_threadpool
Expand Down Expand Up @@ -111,20 +118,23 @@ foreach(lib ${lib_list})
add_library(${lib} STATIC IMPORTED)
endif()
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
target_include_directories(${lib} INTERFACE ${_root}/include ${_root}/include/executorch/runtime/core/portable_type/c10 ${_root}/lib)
target_include_directories(
${lib}
INTERFACE ${_root}/include
${_root}/include/executorch/runtime/core/portable_type/c10
${_root}/lib
)
list(APPEND EXECUTORCH_LIBRARIES ${lib})
endif()
endforeach()

# TODO: investigate use of install(EXPORT) to cleanly handle
# target_compile_options/target_compile_definitions for everything.
if(TARGET extension_parallel)
set_target_properties(
extension_parallel PROPERTIES INTERFACE_LINK_LIBRARIES extension_threadpool
)
endif()
if(TARGET cpublas)
set_target_properties(
cpublas PROPERTIES INTERFACE_LINK_LIBRARIES extension_parallel
cpublas PROPERTIES INTERFACE_LINK_LIBRARIES extension_threadpool
)
endif()
if(TARGET extension_threadpool)
target_compile_definitions(extension_threadpool INTERFACE ET_USE_THREADPOOL)
endif()
14 changes: 2 additions & 12 deletions examples/models/llama/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# ~~~
# It should also be cmake-lint clean.
#
cmake_minimum_required(VERSION 3.19)
cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE
project(llama_runner)

# Duplicating options as root CMakeLists.txt
Expand Down Expand Up @@ -84,14 +84,6 @@ if(CMAKE_TOOLCHAIN_IOS OR ANDROID)
target_link_options_shared_lib(executorch)
endif()

# custom ops library
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/../../../extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/custom_ops
)
endif()

# llama_runner library
add_subdirectory(runner)

Expand Down Expand Up @@ -119,8 +111,7 @@ target_link_options_shared_lib(quantized_ops_lib)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries custom_ops)
list(APPEND link_libraries $<LINK_LIBRARY:WHOLE_ARCHIVE,custom_ops>)
endif()

if(EXECUTORCH_BUILD_TORCHAO)
Expand All @@ -140,7 +131,6 @@ endif()
set(XNNPACK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack)
# Extra compile option and include dir for pthreadpool
if(EXECUTORCH_BUILD_PTHREADPOOL)
list(APPEND _common_compile_options -DET_USE_THREADPOOL)
list(APPEND link_libraries extension_threadpool pthreadpool)
list(APPEND _common_include_directories
${XNNPACK_ROOT}/third-party/pthreadpool/include
Expand Down
10 changes: 0 additions & 10 deletions examples/models/llava/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ if(CMAKE_TOOLCHAIN_IOS OR ANDROID)
target_link_options_shared_lib(executorch)
endif()

# custom ops library
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${EXECUTORCH_ROOT}/extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/custom_ops
)
endif()

# llava_runner library
add_subdirectory(runner)

Expand Down Expand Up @@ -132,14 +124,12 @@ target_link_options_shared_lib(quantized_ops_lib)
list(APPEND link_libraries quantized_kernels quantized_ops_lib)

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries custom_ops)
endif()

set(XNNPACK_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../backends/xnnpack)
# Extra compile option and include dir for pthreadpool
if(EXECUTORCH_BUILD_PTHREADPOOL)
list(APPEND _common_compile_options -DET_USE_THREADPOOL)
list(APPEND link_libraries extension_threadpool pthreadpool)
list(APPEND _common_include_directories
${XNNPACK_ROOT}/third-party/pthreadpool/include
Expand Down
3 changes: 0 additions & 3 deletions examples/models/llava/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ def define_common_targets():
"main.cpp",
],
compiler_flags = ["-Wno-global-constructors"],
preprocessor_flags = [
"-DET_USE_THREADPOOL",
],
deps = [
"//executorch/examples/models/llava/runner:runner",
"//executorch/extension/evalue_util:print_evalue",
Expand Down
10 changes: 2 additions & 8 deletions extension/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.19)
cmake_minimum_required(VERSION 3.24) # 3.24 is required for WHOLE_ARCHIVE

project(executorch_jni)

Expand Down Expand Up @@ -115,16 +115,10 @@ if(TARGET vulkan_backend)
endif()

if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
add_subdirectory(
${EXECUTORCH_ROOT}/extension/llm/custom_ops
${CMAKE_CURRENT_BINARY_DIR}/../../extension/llm/custom_ops
)
list(APPEND link_libraries custom_ops)
target_link_options_shared_lib(custom_ops)
list(APPEND link_libraries $<LINK_LIBRARY:WHOLE_ARCHIVE,custom_ops>)
endif()

if(TARGET pthreadpool)
target_compile_definitions(executorch_jni PRIVATE ET_USE_THREADPOOL=1)
target_include_directories(
executorch_jni
PUBLIC
Expand Down
4 changes: 2 additions & 2 deletions extension/llm/custom_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ target_include_directories(
target_link_libraries(custom_ops PUBLIC ${custom_ops_libs} executorch_core)

target_compile_options(
custom_ops PUBLIC ${_common_compile_options} -DET_USE_THREADPOOL
custom_ops PUBLIC ${_common_compile_options}
)

install(TARGETS custom_ops DESTINATION lib)
Expand Down Expand Up @@ -130,7 +130,7 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
target_compile_options(
custom_ops_aot_lib
PUBLIC -Wno-deprecated-declarations -fPIC -frtti -fexceptions
${_common_compile_options} -DET_USE_THREADPOOL
${_common_compile_options}
)

install(TARGETS custom_ops_aot_lib
Expand Down
2 changes: 1 addition & 1 deletion extension/llm/custom_ops/op_sdpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <vector>

#ifdef ET_USE_THREADPOOL
#include <executorch/extension/parallel/thread_parallel.h>
#include <executorch/extension/threadpool/threadpool.h>
#include <executorch/runtime/kernel/thread_parallel_interface.h>
#endif
#include <executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h>

Expand Down
1 change: 0 additions & 1 deletion extension/llm/custom_ops/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def define_common_targets():
"//executorch/kernels/optimized:libblas{}".format(mkl_dep),
"//executorch/kernels/optimized:libvec",
"//executorch/extension/kernel_util:kernel_util",
"//executorch/extension/parallel:thread_parallel",
"//executorch/extension/threadpool:threadpool",
],
deps = [
Expand Down
25 changes: 0 additions & 25 deletions extension/parallel/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions extension/parallel/TARGETS

This file was deleted.

Loading