|
4 | 4 | # This source code is licensed under the BSD-style license found in the |
5 | 5 | # LICENSE file in the root directory of this source tree. |
6 | 6 |
|
7 | | -add_library( |
8 | | - cpu_runtime runtime/KernelProvider.cpp runtime/CPUPlan.cpp |
9 | | - runtime/op_helpers/Convolution.cpp |
10 | | -) |
11 | | -target_link_libraries( |
12 | | - cpu_runtime |
13 | | - PUBLIC native_runtime |
14 | | - PRIVATE extension_threadpool |
| 7 | +cmake_minimum_required(VERSION 3.24) |
| 8 | + |
| 9 | +if(NOT EXECUTORCH_ROOT) |
| 10 | + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) |
| 11 | +endif() |
| 12 | + |
| 13 | +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) |
| 14 | + |
| 15 | +if(EXECUTORCH_BUILD_NATIVE_CPU) |
| 16 | + add_library( |
| 17 | + cpu_runtime runtime/KernelProvider.cpp runtime/CPUPlan.cpp |
| 18 | + runtime/op_helpers/Convolution.cpp |
| 19 | + ) |
| 20 | + target_link_libraries( |
| 21 | + cpu_runtime |
| 22 | + PUBLIC native_runtime |
| 23 | + PRIVATE extension_threadpool |
| 24 | + ) |
| 25 | + if(EXECUTORCH_BUILD_SHARED) |
| 26 | + target_link_libraries(cpu_runtime PUBLIC executorch_shared) |
| 27 | + else() |
| 28 | + target_link_libraries(cpu_runtime PUBLIC executorch_core) |
| 29 | + endif() |
| 30 | + |
| 31 | + add_library(cpu_reference runtime/providers/reference/ReferenceProvider.cpp) |
| 32 | + target_link_libraries(cpu_reference PUBLIC cpu_runtime) |
| 33 | + |
| 34 | + add_library(cpu_xnnpack runtime/providers/xnnpack/XNNPACKProvider.cpp) |
| 35 | + target_link_libraries( |
| 36 | + cpu_xnnpack |
| 37 | + PUBLIC cpu_runtime |
| 38 | + PRIVATE extension_threadpool |
| 39 | + ) |
| 40 | + if(EXECUTORCH_BUILD_SHARED) |
| 41 | + target_link_libraries(cpu_xnnpack PRIVATE xnnpack_shared) |
| 42 | + else() |
| 43 | + target_link_libraries(cpu_xnnpack PRIVATE XNNPACK) |
| 44 | + endif() |
| 45 | + |
| 46 | + foreach(target cpu_runtime cpu_reference cpu_xnnpack) |
| 47 | + add_library(executorch::${target} ALIAS ${target}) |
| 48 | + target_compile_features(${target} PUBLIC cxx_std_20) |
| 49 | + target_compile_options( |
| 50 | + ${target} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/EHsc> |
| 51 | + $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fexceptions> |
| 52 | + ) |
| 53 | + endforeach() |
| 54 | + |
| 55 | + install( |
| 56 | + TARGETS cpu_runtime cpu_reference cpu_xnnpack |
| 57 | + EXPORT ExecuTorchTargets |
| 58 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 59 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 60 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 61 | + ) |
| 62 | + install( |
| 63 | + DIRECTORY runtime/ |
| 64 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/backends/cpu/runtime |
| 65 | + FILES_MATCHING |
| 66 | + PATTERN "*.h" |
| 67 | + PATTERN "test" EXCLUDE |
| 68 | + ) |
| 69 | +endif() |
| 70 | + |
| 71 | +if(NOT EXECUTORCH_BUILD_CPU) |
| 72 | + return() |
| 73 | +endif() |
| 74 | + |
| 75 | +# The provider composition that cpu_backend() in targets.bzl generates for the |
| 76 | +# default :cpu_backend target. |
| 77 | +set(_cpu_provider_registry ${CMAKE_CURRENT_BINARY_DIR}/provider_registry.cpp) |
| 78 | +file( |
| 79 | + GENERATE |
| 80 | + OUTPUT ${_cpu_provider_registry} |
| 81 | + CONTENT |
| 82 | + "#include <executorch/backends/cpu/runtime/KernelProvider.h> |
| 83 | +#include <executorch/backends/cpu/runtime/providers/xnnpack/XNNPACKProvider.h> |
| 84 | +#include <executorch/backends/cpu/runtime/providers/reference/ReferenceProvider.h> |
| 85 | +namespace executorch::backends::cpu { |
| 86 | +namespace { |
| 87 | +RuntimeConfiguration runtime_configuration() { |
| 88 | +static const ProviderFactory factories[] = {create_xnnpack_provider,create_reference_provider}; |
| 89 | +return {{factories, sizeof(factories) / sizeof(factories[0])}, {}, false}; |
| 90 | +} |
| 91 | +const bool registered = (register_runtime_configuration(runtime_configuration), true); |
| 92 | +} |
| 93 | +} |
| 94 | +" |
15 | 95 | ) |
| 96 | + |
| 97 | +list(TRANSFORM _cpu_backend__srcs PREPEND "${EXECUTORCH_ROOT}/") |
16 | 98 | if(EXECUTORCH_BUILD_SHARED) |
17 | | - target_link_libraries(cpu_runtime PUBLIC executorch_shared) |
| 99 | + set(_cpu_backend_library_type SHARED) |
18 | 100 | else() |
19 | | - target_link_libraries(cpu_runtime PUBLIC executorch_core) |
| 101 | + set(_cpu_backend_library_type STATIC) |
20 | 102 | endif() |
21 | | - |
22 | | -add_library(cpu_reference runtime/providers/reference/ReferenceProvider.cpp) |
23 | | -target_link_libraries(cpu_reference PUBLIC cpu_runtime) |
24 | | - |
25 | | -add_library(cpu_xnnpack runtime/providers/xnnpack/XNNPACKProvider.cpp) |
| 103 | +add_library( |
| 104 | + cpu_backend ${_cpu_backend_library_type} ${_cpu_backend__srcs} |
| 105 | + ${_cpu_provider_registry} |
| 106 | +) |
26 | 107 | target_link_libraries( |
27 | | - cpu_xnnpack |
28 | | - PUBLIC cpu_runtime |
29 | | - PRIVATE extension_threadpool |
| 108 | + cpu_backend PRIVATE native_program extension_threadpool |
| 109 | + optimized_native_cpu_ops_lib |
30 | 110 | ) |
31 | 111 | if(EXECUTORCH_BUILD_SHARED) |
32 | | - target_link_libraries(cpu_xnnpack PRIVATE xnnpack_shared) |
| 112 | + set_target_properties( |
| 113 | + cpu_backend PROPERTIES OUTPUT_NAME executorch_backend_cpu |
| 114 | + ) |
| 115 | + executorch_target_soname_policy(cpu_backend) |
| 116 | + executorch_target_link_shared_runtime(cpu_backend) |
| 117 | + # The XNNPACK delegate library already bundles XNNPACK, so resolve against it |
| 118 | + # rather than shipping a second copy. |
| 119 | + target_link_libraries( |
| 120 | + cpu_backend |
| 121 | + PUBLIC executorch_shared |
| 122 | + PRIVATE xnnpack_backend |
| 123 | + ) |
| 124 | + target_include_directories( |
| 125 | + cpu_backend |
| 126 | + PRIVATE $<TARGET_PROPERTY:XNNPACK,INTERFACE_INCLUDE_DIRECTORIES> |
| 127 | + ) |
| 128 | + executorch_target_shipped_runtime_path(cpu_backend) |
33 | 129 | else() |
34 | | - target_link_libraries(cpu_xnnpack PRIVATE XNNPACK) |
| 130 | + target_link_libraries( |
| 131 | + cpu_backend |
| 132 | + PUBLIC executorch_core |
| 133 | + PRIVATE XNNPACK xnnpack-microkernels-prod |
| 134 | + ) |
35 | 135 | endif() |
36 | | - |
37 | | -foreach(target cpu_runtime cpu_reference cpu_xnnpack) |
38 | | - add_library(executorch::${target} ALIAS ${target}) |
39 | | - target_compile_features(${target} PUBLIC cxx_std_20) |
40 | | - target_compile_options( |
41 | | - ${target} PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/EHsc> |
| 136 | +target_compile_features(cpu_backend PRIVATE cxx_std_20) |
| 137 | +target_compile_options( |
| 138 | + cpu_backend PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/EHsc> |
42 | 139 | $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fexceptions> |
43 | | - ) |
44 | | -endforeach() |
| 140 | +) |
| 141 | +set_target_properties(cpu_backend PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 142 | +executorch_target_link_options_shared_lib(cpu_backend) |
45 | 143 |
|
46 | 144 | install( |
47 | | - TARGETS cpu_runtime cpu_reference cpu_xnnpack |
| 145 | + TARGETS cpu_backend |
48 | 146 | EXPORT ExecuTorchTargets |
49 | 147 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
50 | 148 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
51 | 149 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
52 | 150 | ) |
53 | | -install( |
54 | | - DIRECTORY runtime/ |
55 | | - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/backends/cpu/runtime |
56 | | - FILES_MATCHING |
57 | | - PATTERN "*.h" |
58 | | - PATTERN "test" EXCLUDE |
59 | | -) |
|
0 commit comments