You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
Pull Request resolved: #4274
Update kernels readme with Cmake instructions. Major changes are:
1. Instructions to generate the operator function signature with cmake instead of buck.
2. Instructions to build and test the operator with cmake.
3. Update links from buck to cmake, internal to oss
Move existing buck instructions to fb/ directory.
Reviewed By: larryliu0820, kirklandsign
Differential Revision: D59784834
fbshipit-source-id: 4a73c43b57ce3d87fa8e162b2e5417ba068f0c45
(cherry picked from commit 7d6c8fc)
Co-authored-by: Lucy Qiu <[email protected]>
If your operator overload group is ATen-compatible, its `_op_target` entry
231
-
belongs in the `_ATEN_OPS` list, otherwise it belongs in the `_CUSTOM_OPS` list.
232
-
Note that this means that a given `op_<name>` cannot implement both
233
-
ATen-compatible and non-ATen-compatible (i.e., custom) operators. We suggest
234
-
adding the suffix `_custom` if necessary: e.g., `op_add` for ATen-compatible
235
-
overloads of the `add` operator, and `op_add_custom` for non-ATen-compatible
236
-
overloads.
210
+
### Add the operator implementation to CMakeLists.txt
237
211
238
-
By default, this target will depend on the core ExecuTorch types, but you can
239
-
add additional deps if you want to.
212
+
The portable operator files are collected by [`./kernels/portable/CMakeLists.txt`](https://github.com/pytorch/executorch/blob/main/kernels/portable/CMakeLists.txt) with a glob on `./kernels/portable/cpu/*.cpp`. Ensure your operator file is in that directory.
240
213
241
-
NOTE: An `op_<name>` target may not depend on another `op_<name>` target. If two
242
-
`op_` targets need to share code, define a separate `runtime.cxx_library` target
243
-
under `//executorch/kernels/portable/cpu/lib` that they both depend on. This
244
-
keeps the dependencies more managable, especially for selective builds where
245
-
only a subset of operators are used.
214
+
NOTE: a given `op_<name>` cannot implement both ATen-compatible and
215
+
non-ATen-compatible (i.e., custom) operators. We suggest adding the suffix
216
+
`_custom` if necessary: e.g., `op_add` for ATen-compatible overloads of
217
+
the `add` operator, and `op_add_custom` for non-ATen-compatible overloads.
246
218
247
-
NOTE: An `op_<name>`target may not depend on targets outside of `//executorch`.
219
+
NOTE: An `op_<name>` may not have dependencies outside of `//executorch`.
248
220
This library is intended to be portable, open-sourceable, and self-contained.
249
221
250
222
### Create a skeleton .cpp file for the operator implementation
251
223
252
224
If not already present, create the file
253
-
`//executorch/kernels/portable/cpu/op_<name>.cpp`, which should follow the
225
+
`executorch/kernels/portable/cpu/op_<name>.cpp`, which should follow the
254
226
pattern:
255
227
```
256
228
// Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -271,39 +243,30 @@ namespace {
271
243
} // namespace torch
272
244
```
273
245
274
-
With the target and cpp file in place, you should be able to build it:
buck test fbcode//executorch/kernels/test:op_<name>_test
390
-
```
328
+
### Add operator test to CMakeLists.txt
329
+
330
+
Now, we have to add this to [executorch/kernels/tests/CMakeLists.txt](https://github.com/pytorch/executorch/blob/main/kernels/test/CMakeLists.txt). Note that this builds all the kernel tests.
331
+
332
+
For portable kernels, add your test file to [`all_test_sources`](https://github.com/pytorch/executorch/blob/main/kernels/test/CMakeLists.txt#L69).
333
+
334
+
For optimized kernels, add your test file to [`_optimized_kernels_test_sources](https://github.com/pytorch/executorch/blob/main/kernels/test/CMakeLists.txt#L230).
391
335
392
336
### Implement and test the operator
393
337
394
338
You should now be able to implement and test your operator. It's helpful to see
395
339
how other operators do it, so take a look at `op_add`:
0 commit comments