|
1 | 1 | load("@fbsource//tools/build_defs:platform_defs.bzl", "CXX") |
2 | 2 | load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") |
3 | 3 |
|
4 | | -def define_common_targets(): |
5 | | - """Defines targets that should be shared between fbcode and xplat. |
6 | | -
|
7 | | - The directory containing this targets.bzl file should also contain both |
8 | | - TARGETS and BUCK files that call this function. |
9 | | - """ |
10 | | - |
11 | | - # Define build targets for all operators registered in the tables above. |
12 | 4 |
|
13 | | - runtime.cxx_library( |
14 | | - name = "quantize_per_tensor", |
15 | | - srcs = [ |
16 | | - "quantize_per_tensor.cpp" |
17 | | - ], |
18 | | - platforms = CXX, |
19 | | - deps = [ |
20 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
21 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
22 | | - "//executorch/runtime/kernel:kernel_includes", |
23 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
24 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
25 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
26 | | - ], |
27 | | - visibility = [ |
28 | | - "//executorch/backends/cadence/...", |
29 | | - "@EXECUTORCH_CLIENTS", |
30 | | - ], |
31 | | - ) |
| 5 | +def define_operator(name: str, deps: list[str] | None = None) -> None: |
| 6 | + op_name = "op_{}".format(name) |
32 | 7 |
|
33 | | - runtime.cxx_library( |
34 | | - name = "dequantize_per_tensor", |
35 | | - srcs = [ |
36 | | - "dequantize_per_tensor.cpp" |
37 | | - ], |
38 | | - platforms = CXX, |
39 | | - deps = [ |
40 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
41 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
42 | | - "//executorch/runtime/kernel:kernel_includes", |
43 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
44 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
45 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
46 | | - ], |
47 | | - visibility = [ |
48 | | - "//executorch/backends/cadence/...", |
49 | | - "@EXECUTORCH_CLIENTS", |
50 | | - ], |
51 | | - ) |
| 8 | + # Deps used by all operators. |
| 9 | + common_deps = [ |
| 10 | + "//executorch/kernels/portable/cpu/util:all_deps", |
| 11 | + "//executorch/kernels/portable/cpu/pattern:all_deps", |
| 12 | + "//executorch/runtime/kernel:kernel_includes", |
| 13 | + "//executorch/kernels/portable/cpu:scalar_utils", |
| 14 | + "//executorch/backends/cadence/hifi/kernels:kernels", |
| 15 | + "//executorch/kernels/portable/cpu/util:dtype_util", |
| 16 | + "//executorch/kernels/portable/cpu/util:elementwise_util", |
| 17 | + "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
| 18 | + ] |
| 19 | + if deps == None: |
| 20 | + deps = [] |
52 | 21 |
|
53 | 22 | runtime.cxx_library( |
54 | | - name = "quantized_layer_norm", |
55 | | - srcs = [ |
56 | | - "quantized_layer_norm.cpp" |
57 | | - ], |
58 | | - exported_headers = ["operators.h"], |
| 23 | + name = op_name, |
| 24 | + srcs = [op_name + ".cpp"], |
59 | 25 | platforms = CXX, |
60 | | - deps = [ |
61 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
62 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
63 | | - "//executorch/runtime/kernel:kernel_includes", |
64 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
65 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
66 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
67 | | - ], |
68 | 26 | visibility = [ |
69 | 27 | "//executorch/backends/cadence/...", |
70 | 28 | "@EXECUTORCH_CLIENTS", |
71 | 29 | ], |
72 | | - ) |
73 | | - |
74 | | - runtime.cxx_library( |
75 | | - name = "quantized_linear_out", |
76 | | - srcs = [ |
77 | | - "quantized_linear_out.cpp" |
78 | | - ], |
| 30 | + deps = deps + common_deps, |
79 | 31 | exported_headers = ["operators.h"], |
80 | | - platforms = CXX, |
81 | | - deps = [ |
82 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
83 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
84 | | - "//executorch/runtime/kernel:kernel_includes", |
85 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
86 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
87 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
88 | | - ], |
89 | | - visibility = [ |
90 | | - "//executorch/backends/cadence/...", |
91 | | - "@EXECUTORCH_CLIENTS", |
92 | | - ], |
93 | | - ) |
94 | | - |
95 | | - runtime.cxx_library( |
96 | | - name = "op_add", |
97 | | - srcs = [ |
98 | | - "op_add.cpp", |
99 | | - ], |
100 | | - platforms = CXX, |
101 | | - deps = [ |
102 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
103 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
104 | | - "//executorch/runtime/kernel:kernel_includes", |
105 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
106 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
107 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions", |
108 | | - "//executorch/kernels/portable/cpu/util:dtype_util", |
109 | | - "//executorch/kernels/portable/cpu/util:elementwise_util", |
110 | | - ], |
111 | | - visibility = [ |
112 | | - "//executorch/backends/cadence/...", |
113 | | - "@EXECUTORCH_CLIENTS", |
114 | | - ], |
115 | | - ) |
116 | | - |
117 | | - |
118 | | - runtime.cxx_library( |
119 | | - name = "op_mul", |
120 | | - srcs = [ |
121 | | - "op_mul.cpp", |
122 | | - ], |
123 | | - platforms = CXX, |
124 | | - deps = [ |
125 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
126 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
127 | | - "//executorch/runtime/kernel:kernel_includes", |
128 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
129 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
130 | | - "//executorch/kernels/portable/cpu/util:dtype_util", |
131 | | - "//executorch/kernels/portable/cpu/util:elementwise_util", |
132 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
133 | | - ], |
134 | | - visibility = [ |
135 | | - "//executorch/backends/cadence/...", |
136 | | - "@EXECUTORCH_CLIENTS", |
137 | | - ], |
138 | | - ) |
139 | | - |
140 | | - runtime.cxx_library( |
141 | | - name = "op_sub", |
142 | | - srcs = [ |
143 | | - "op_sub.cpp", |
144 | | - ], |
145 | | - platforms = CXX, |
146 | | - deps = [ |
147 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
148 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
149 | | - "//executorch/runtime/kernel:kernel_includes", |
150 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
151 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
152 | | - "//executorch/kernels/portable/cpu/util:dtype_util", |
153 | | - "//executorch/kernels/portable/cpu/util:elementwise_util", |
154 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
155 | | - ], |
156 | | - visibility = [ |
157 | | - "//executorch/backends/cadence/...", |
158 | | - "@EXECUTORCH_CLIENTS", |
159 | | - ], |
160 | 32 | ) |
161 | 33 |
|
162 | | - runtime.cxx_library( |
163 | | - name = "op_div", |
164 | | - srcs = [ |
165 | | - "op_div.cpp", |
166 | | - ], |
167 | | - platforms = CXX, |
168 | | - deps = [ |
169 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
170 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
171 | | - "//executorch/runtime/kernel:kernel_includes", |
172 | | - "//executorch/kernels/portable/cpu:scalar_utils", |
173 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
174 | | - "//executorch/kernels/portable/cpu/util:dtype_util", |
175 | | - "//executorch/kernels/portable/cpu/util:elementwise_util", |
176 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
177 | | - ], |
178 | | - visibility = [ |
179 | | - "//executorch/backends/cadence/...", |
180 | | - "@EXECUTORCH_CLIENTS", |
181 | | - ], |
182 | | - ) |
| 34 | +OPERATORS = [ |
| 35 | + "add", |
| 36 | + "atan2", |
| 37 | + "cat", |
| 38 | + "clamp", |
| 39 | + "dequantize_per_tensor", |
| 40 | + "div", |
| 41 | + "full", |
| 42 | + "maximum", |
| 43 | + "mean", |
| 44 | + "minimum", |
| 45 | + "mul", |
| 46 | + "permute_copy", |
| 47 | + "pow", |
| 48 | + "quantize_per_tensor", |
| 49 | + "quantized_layer_norm", |
| 50 | + "quantized_linear_out", |
| 51 | + "quantized_relu_out", |
| 52 | + "remainder", |
| 53 | + "rsqrt", |
| 54 | + "sigmoid", |
| 55 | + "softmax", |
| 56 | + "sub", |
| 57 | + "tanh", |
| 58 | + "where" |
| 59 | +] |
183 | 60 |
|
184 | | - runtime.cxx_library( |
185 | | - name = "op_sigmoid", |
186 | | - srcs = [ |
187 | | - "op_sigmoid.cpp", |
188 | | - ], |
189 | | - platforms = CXX, |
190 | | - deps = [ |
191 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
192 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
193 | | - "//executorch/runtime/kernel:kernel_includes", |
194 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
195 | | - "//executorch/kernels/portable/cpu/util:dtype_util", |
196 | | - "//executorch/kernels/portable/cpu/util:elementwise_util", |
197 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
198 | | - ], |
199 | | - visibility = [ |
200 | | - "//executorch/backends/cadence/...", |
201 | | - "@EXECUTORCH_CLIENTS", |
202 | | - ], |
203 | | - ) |
| 61 | +def define_common_targets(): |
| 62 | + """Defines targets that should be shared between fbcode and xplat. |
204 | 63 |
|
205 | | - runtime.cxx_library( |
206 | | - name = "op_tanh", |
207 | | - srcs = [ |
208 | | - "op_tanh.cpp", |
209 | | - ], |
210 | | - platforms = CXX, |
211 | | - deps = [ |
212 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
213 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
214 | | - "//executorch/runtime/kernel:kernel_includes", |
215 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
216 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
217 | | - ], |
218 | | - visibility = [ |
219 | | - "//executorch/backends/cadence/...", |
220 | | - "@EXECUTORCH_CLIENTS", |
221 | | - ], |
222 | | - ) |
| 64 | + The directory containing this targets.bzl file should also contain both |
| 65 | + TARGETS and BUCK files that call this function. |
| 66 | + """ |
223 | 67 |
|
224 | | - |
225 | | - runtime.cxx_library( |
226 | | - name = "op_where", |
227 | | - srcs = [ |
228 | | - "op_where.cpp", |
229 | | - ], |
230 | | - platforms = CXX, |
231 | | - deps = [ |
232 | | - "//executorch/kernels/portable/cpu/util:all_deps", |
233 | | - "//executorch/kernels/portable/cpu/pattern:all_deps", |
234 | | - "//executorch/runtime/kernel:kernel_includes", |
235 | | - "//executorch/backends/cadence/hifi/kernels:kernels", |
236 | | - "//executorch/kernels/portable/cpu/util:elementwise_util", |
237 | | - "//executorch/backends/cadence/hifi/third-party/nnlib:nnlib-extensions" |
238 | | - ], |
239 | | - visibility = [ |
240 | | - "//executorch/backends/cadence/...", |
241 | | - "@EXECUTORCH_CLIENTS", |
242 | | - ], |
243 | | - ) |
| 68 | + # Define build targets for all operators registered in the tables above. |
| 69 | + for op in OPERATORS: |
| 70 | + define_operator(op) |
0 commit comments