Skip to content

Commit d660dce

Browse files
authored
Add ARM embedded platform compatibility to all operators
Differential Revision: D93254992 Pull Request resolved: #17457
1 parent c3a140f commit d660dce

2 files changed

Lines changed: 67 additions & 2 deletions

File tree

backends/cortex_m/ops/targets.bzl

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,66 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
99
load("@fbsource//xplat/executorch/codegen:codegen.bzl", "et_operator_library", "executorch_generated_lib")
1010
load("@fbcode_macros//build_defs:export_files.bzl", "export_file")
1111

12+
_ARM_EMBEDDED_PLATFORMS = ["ovr_config//cpu:arm32-embedded", "ovr_config//cpu:arm32-embedded-fpu"]
13+
14+
# Operators that compile without CMSIS-NN (portable scalar + optional Helium/MVE).
15+
# These can be built and tested on any platform (including x86_64 CI).
16+
_PORTABLE_OPERATORS = [
17+
"quantize_per_tensor",
18+
"dequantize_per_tensor",
19+
]
20+
21+
1222
def define_operator_target(name: str):
23+
needs_cmsis = name not in _PORTABLE_OPERATORS
24+
25+
cmsis_deps = [
26+
"//executorch/kernels/portable/cpu:scalar_utils",
27+
"//executorch/kernels/portable/cpu/util:broadcast_util",
28+
"//executorch/kernels/portable/cpu/util:elementwise_util",
29+
"//executorch/kernels/portable/cpu/util:kernel_ops_util",
30+
"//executorch/kernels/portable/cpu/util:copy_ops_util",
31+
"//executorch/kernels/portable/cpu/util:padding_util",
32+
"fbsource//third-party/cmsis-nn:cmsis_header",
33+
"fbsource//third-party/cmsis-nn:cmsis_nn",
34+
] if needs_cmsis else []
35+
36+
cmsis_headers = ["cortex_m_ops_common.h"] if needs_cmsis else []
37+
38+
_compat_kwargs = {}
39+
if needs_cmsis:
40+
_compat_kwargs["compatible_with"] = _ARM_EMBEDDED_PLATFORMS
41+
1342
runtime.cxx_library(
1443
name = "op_{}".format(name),
1544
srcs = [
1645
"op_{}.cpp".format(name),
1746
],
47+
headers = cmsis_headers,
1848
platforms = CXX,
1949
deps = [
20-
"//executorch/runtime/kernel:kernel_includes"
21-
],
50+
"//executorch/runtime/kernel:kernel_includes",
51+
] + cmsis_deps,
2252
link_whole = True,
53+
**_compat_kwargs
2354
)
2455

2556
OPERATORS = [
2657
"quantize_per_tensor",
2758
"dequantize_per_tensor",
59+
"quantized_add",
60+
"quantized_mul",
61+
"minimum",
62+
"maximum",
63+
"quantized_linear",
64+
"softmax",
65+
"transpose",
66+
"pad",
67+
"quantized_conv2d",
68+
"quantized_depthwise_conv2d",
69+
"quantized_transpose_conv2d",
70+
"quantized_avg_pool2d",
71+
"quantized_max_pool2d",
2872
]
2973

3074
def define_common_targets():
@@ -44,6 +88,7 @@ def define_common_targets():
4488
visibility = ["PUBLIC"],
4589
platforms = CXX,
4690
exported_deps = all_op_targets,
91+
compatible_with = _ARM_EMBEDDED_PLATFORMS,
4792
)
4893

4994
export_file(name = "operators.yaml")
@@ -58,23 +103,29 @@ def define_common_targets():
58103
name = "cortex_m_generated_lib",
59104
deps = [
60105
":ops_lib",
106+
],
107+
kernel_deps = [
61108
":cortex_m_operators",
62109
],
63110
functions_yaml_target = ":operators.yaml",
64111
platforms = CXX,
65112
visibility = ["PUBLIC"],
66113
define_static_targets = True,
114+
compatible_with = _ARM_EMBEDDED_PLATFORMS,
67115
)
68116

69117
executorch_generated_lib(
70118
name = "cortex_m_no_except_generated_lib",
71119
deps = [
72120
":ops_lib",
121+
],
122+
kernel_deps = [
73123
":cortex_m_operators",
74124
],
75125
functions_yaml_target = ":operators.yaml",
76126
platforms = CXX,
77127
visibility = ["PUBLIC"],
78128
define_static_targets = True,
79129
support_exceptions = False,
130+
compatible_with = _ARM_EMBEDDED_PLATFORMS,
80131
)

shim_et/xplat/executorch/codegen/codegen.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ def executorch_generated_lib(
820820
kernel_deps = [],
821821
dtype_selective_build = False,
822822
feature = None,
823+
compatible_with = None,
823824
expose_operator_symbols = False,
824825
support_exceptions = True,
825826
include_all_prim_ops = True):
@@ -883,10 +884,19 @@ def executorch_generated_lib(
883884
support_exceptions: enable try/catch wrapper around operator implementations
884885
to make sure exceptions thrown will not bring down the process. Disable if your
885886
use case disables exceptions in the build.
887+
compatible_with: An optional list of platform constraints (e.g.
888+
["ovr_config//cpu:arm32-embedded"]). When set, the constraint is
889+
applied to the compiled registration library (`<name>`) but NOT to
890+
the header-only library (`<name>_headers`), so that host-side
891+
consumers such as unit tests can still depend on the headers.
886892
include_all_prim_ops: If true, include all prim ops in the generated library. This option
887893
allows for selecting only some prim ops to reduce code size for extremely constrained
888894
environments. For selecting only some prim ops, see examples in //executorch/examples/selective_build
889895
"""
896+
_compat_kwargs = {}
897+
if compatible_with != None:
898+
_compat_kwargs["compatible_with"] = compatible_with
899+
890900
if functions_yaml_target and aten_mode:
891901
fail("{} is providing functions_yaml_target in ATen mode, it will be ignored. `native_functions.yaml` will be the source of truth.".format(name))
892902

@@ -1046,6 +1056,9 @@ def executorch_generated_lib(
10461056
"//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix,
10471057
],
10481058
feature = feature,
1059+
# Note: compatible_with is intentionally NOT applied to the
1060+
# headers-only target so that host-side consumers (e.g. unit tests
1061+
# on x86_64) can still depend on the generated headers.
10491062
)
10501063

10511064
if name in libs:
@@ -1098,6 +1111,7 @@ def executorch_generated_lib(
10981111
_is_external_target = True,
10991112
platforms = platforms,
11001113
feature = feature,
1114+
**_compat_kwargs
11011115
)
11021116

11031117
if custom_ops_yaml_target and custom_ops_requires_aot_registration:

0 commit comments

Comments
 (0)