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:
Since we now have 2 APIs for custom ops, we need to guide users on which one to use.
Pull Request resolved: #3956
Reviewed By: lucylq
Differential Revision: D58476748
Pulled By: larryliu0820
fbshipit-source-id: 3bea12af3a6c73b309337b95277840aa6ed18818
Copy file name to clipboardExpand all lines: docs/source/kernel-library-custom-aten-kernel.md
+28-2Lines changed: 28 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,8 +89,10 @@ ATen operator with a dtype/dim order specialized kernel (works for `Double` dtyp
89
89
### Custom Ops C++ API
90
90
91
91
For a custom kernel that implements a custom operator, we provides 2 ways to register it into ExecuTorch runtime:
92
-
1. Using `EXECUTORCH_LIBRARY` and `WRAP_TO_ATEN` C++ macros.
93
-
2. Using `functions.yaml` and codegen'd C++ libraries.
92
+
1. Using `EXECUTORCH_LIBRARY` and `WRAP_TO_ATEN` C++ macros, covered by this section.
93
+
2. Using `functions.yaml` and codegen'd C++ libraries, covered by [next section](#custom-ops-yaml-entry).
94
+
95
+
Please refer to [Custom Ops Best Practices](#custom-ops-api-best-practices) on which API to use.
94
96
95
97
The first option requires C++17 and doesn't have selective build support yet, but it's faster than the second option where we have to go through yaml authoring and build system tweaking.
96
98
@@ -301,3 +303,27 @@ cxx_binary(
301
303
)
302
304
303
305
```
306
+
307
+
### Custom Ops API Best Practices
308
+
309
+
Given that we have 2 kernel registration APIs for custom ops, which API should we use? Here are some pros and cons for each API:
310
+
311
+
* C++ API:
312
+
- Pros:
313
+
* Only C++ code changes are needed
314
+
* Resembles PyTorch custom ops C++ API
315
+
* Low maintenance cost
316
+
- Cons:
317
+
* No selective build support
318
+
* No centralized bookkeepping
319
+
320
+
* Yaml entry API:
321
+
- Pros:
322
+
* Has selective build support
323
+
* Provides a centralized place for custom ops
324
+
- It shows what ops are being registered and what kernels are bound to these ops, for an application
325
+
- Cons:
326
+
* User needs to create and maintain yaml files
327
+
* Relatively inflexible to change the op definition
328
+
329
+
Overall if we are building an application and it uses custom ops, during the development phase it's recommended to use the C++ API since it's low-cost to use and flexible to change. Once the application moves to production phase where the custom ops definitions and the build systems are quite stable and binary size is to be considered, it is recommended to use the Yaml entry API.
0 commit comments