-
Notifications
You must be signed in to change notification settings - Fork 646
Add top-level CMake kernels target #12806
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
Changes from all commits
7c0481e
d562557
295206e
1a6d403
9a9d56c
9b1cd87
91792fd
c6d1ff2
1f9ab62
533901d
c3a6a73
1816540
046b989
25e18d7
8ae3a4e
09fd5fc
4e244ab
d0e4350
08760b1
b20aa65
d999dc0
317799f
c8783b9
64f4668
1aac01f
fb8c715
d2bdf8b
fab6b9d
73c2cb0
f7d413f
65087f5
9d1824d
b3944b3
56f84cc
42c53a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,8 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) | |
# Instead please use `find_package(executorch REQUIRED)` in the example | ||
# directory and add a new executable in the example `CMakeLists.txt`. | ||
|
||
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
if(NOT EXECUTORCH_ENABLE_LOGGING) | ||
# Avoid pulling in the logging strings, which can be large. Note that this | ||
# will set the compiler flag for all targets in this directory, and for all | ||
|
@@ -386,6 +388,9 @@ set(_executorch_backends "") | |
# A list of all configured extensions. | ||
set(_executorch_extensions "") | ||
|
||
# A list of all configured kernel libraries. | ||
set(_executorch_kernels "") | ||
|
||
target_link_libraries(executorch_core PRIVATE program_schema) | ||
if(ANDROID) | ||
target_link_libraries(executorch_core PUBLIC log) | ||
|
@@ -774,11 +779,13 @@ endif() | |
if(EXECUTORCH_BUILD_KERNELS_LLM) | ||
# TODO: move all custom kernels to ${CMAKE_CURRENT_SOURCE_DIR}/kernels/custom | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/custom_ops) | ||
list(APPEND _executorch_kernels custom_ops_aot_lib) | ||
endif() | ||
|
||
if(EXECUTORCH_BUILD_KERNELS_QUANTIZED) | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/quantized) | ||
executorch_target_link_options_shared_lib(quantized_ops_lib) | ||
list(APPEND _executorch_kernels quantized_ops_lib) | ||
endif() | ||
|
||
if(EXECUTORCH_BUILD_VULKAN) | ||
|
@@ -803,6 +810,60 @@ add_library(executorch_extensions INTERFACE) | |
add_library(executorch::extensions ALIAS executorch_extensions) | ||
target_link_libraries(executorch_extensions INTERFACE ${_executorch_extensions}) | ||
|
||
# A target containing all configured kernels, with selective build, if enabled. | ||
add_library(executorch_kernels INTERFACE) | ||
add_library(executorch::kernels ALIAS executorch_kernels) | ||
if(NOT EXECUTORCH_SELECT_OPS_YAML STREQUAL "" | ||
OR NOT EXECUTORCH_SELECT_OPS_LIST STREQUAL "" | ||
OR NOT EXECUTORCH_SELECT_OPS_MODEL STREQUAL "" | ||
) | ||
gen_selected_ops( | ||
LIB_NAME | ||
"executorch_selected_kernels" | ||
OPS_SCHEMA_YAML | ||
"${EXECUTORCH_SELECT_OPS_LIB}" | ||
ROOT_OPS | ||
"${EXECUTORCH_SELECT_OPS_LIST}" | ||
INCLUDE_ALL_OPS | ||
FALSE | ||
OPS_FROM_MODEL | ||
"${EXECUTORCH_SELECT_OPS_MODEL}" | ||
DTYPE_SELECTIVE_BUILD | ||
"${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}" | ||
) | ||
|
||
generate_bindings_for_kernels( | ||
LIB_NAME | ||
"executorch_selected_kernels" | ||
FUNCTIONS_YAML | ||
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml | ||
CUSTOM_OPS_YAML | ||
"" | ||
DTYPE_SELECTIVE_BUILD | ||
"${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}" | ||
) | ||
|
||
gen_operators_lib( | ||
LIB_NAME | ||
"executorch_selected_kernels" | ||
KERNEL_LIBS | ||
"portable_kernels" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this to top-level cmake! So,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, as a follow-up, I intend to enable optimized (and portable_optimized) kernels. To enable selective build for other libraries (quantized ops, llm ops, etc.), I should just be able to use the merge_yaml functionality to generate a combined op yaml, right? For user's custom op libs, I think they'll probably need to define their own targets, as we can't access their targets from here (unless we re-wrote as a macro/function, but we can look at that separately). Backend op libs are another case that needs more thinking through, as well. But hopefully this should be a good starting point. |
||
DEPS | ||
executorch_core | ||
DTYPE_SELECTIVE_BUILD | ||
"${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}" | ||
) | ||
list(APPEND _executorch_kernels executorch_selected_kernels) | ||
else() | ||
# No selective build - link the full library. | ||
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) | ||
list(APPEND _executorch_kernels optimized_native_cpu_ops_lib) | ||
else() | ||
list(APPEND _executorch_kernels portable_ops_lib) | ||
endif() | ||
endif() | ||
target_link_libraries(executorch_kernels INTERFACE ${_executorch_kernels}) | ||
|
||
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) | ||
# Baseline libraries that executor_runner will link against. | ||
set(_executor_runner_libs executorch extension_evalue_util | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,28 @@ define_overridable_option( | |
EXECUTORCH_USE_CPP_CODE_COVERAGE "Build with code coverage enabled" BOOL OFF | ||
) | ||
|
||
# Selective build options. These affect the executorch_kernels target. | ||
define_overridable_option( | ||
EXECUTORCH_SELECT_OPS_YAML | ||
"Build the executorch_kernels target with YAML selective build config." | ||
STRING "" | ||
) | ||
define_overridable_option( | ||
EXECUTORCH_SELECT_OPS_LIST | ||
"Build the executorch_kernels target with a list of selected operators." | ||
STRING "" | ||
) | ||
define_overridable_option( | ||
EXECUTORCH_SELECT_OPS_MODEL | ||
"Build the executorch_kernels target with only operators from the given model .pte file." | ||
STRING "" | ||
) | ||
define_overridable_option( | ||
EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD | ||
GregoryComer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Build the executorch_kernels target with only operator implementations for selected data types." | ||
BOOL FALSE | ||
) | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Validations | ||
# | ||
|
@@ -284,6 +306,17 @@ check_conflicting_options_on( | |
EXECUTORCH_BUILD_CPUINFO | ||
) | ||
|
||
# Selective build specifiers are mutually exclusive. | ||
check_conflicting_options_on( | ||
IF_ON EXECUTORCH_SELECT_OPS_YAML CONFLICTS_WITH | ||
EXECUTORCH_SELECT_OPS_LIST EXECUTORCH_SELECT_OPS_MODEL | ||
) | ||
Comment on lines
+310
to
+313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean in the future it should be composable. I'm OK with having this for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GregoryComer Should this also check for a conflict with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see it there, later down. |
||
|
||
check_conflicting_options_on( | ||
IF_ON EXECUTORCH_SELECT_OPS_LIST CONFLICTS_WITH | ||
EXECUTORCH_SELECT_OPS_MODEL | ||
) | ||
|
||
if(NOT EXISTS ${EXECUTORCH_PAL_DEFAULT_FILE_PATH}) | ||
message( | ||
FATAL_ERROR | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding this!