Skip to content

Commit

Permalink
[Specialized Kernel] Update yaml syntax to use kernel instead of disp…
Browse files Browse the repository at this point in the history
…atch (#104070)

Based on this [code search](https://fburl.com/code/gjcnw8ly) (*.yaml with `dispatch: CPU:`), update all files found to use

```
kernels:
    - arg_meta: None
      kernel_name:
```
instead of
```
dispatch:
    CPU:
```
---
## Code changes:

- `fbcode/executorch/codegen/tools/gen_oplist.py`
  - Strip ET specific fields prior to calling parse_native_yaml_struct
---
## Files edited that are not `*functions.yaml` or `custom_ops.yaml`

- fbcode/executorch/kernels/optimized/optimized.yaml
- fbcode/executorch/kernels/quantized/quantized.yaml
- fbcode/executorch/kernels/test/custom_kernel_example/my_functions.yaml

---
## Found Files that were not edited

**Dispatched to more than just CPU**
- fbcode/caffe2/aten/src/ATen/native/native_functions.yaml
- xplat/caffe2/aten/src/ATen/native/native_functions.yaml
- xros/third-party/caffe2/caffe2/aten/src/ATen/native/native_functions.yaml

**Grouped ops.yaml path**
- fbcode/on_device_ai/Assistant/Jarvis/min_runtime/operators/ops.yaml

---
**Design Doc:** https://docs.google.com/document/d/1gq4Wz2R6verKJ2EFseLyPdAF0wqomnCrVDDJpRkYsRw/edit?kh_source=GDOCS#heading=h.8raqyft9y50

Differential Revision: [D46952067](https://our.internmc.facebook.com/intern/diff/D46952067/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D46952067/)!
Pull Request resolved: #104070
Approved by: https://github.com/larryliu0820
  • Loading branch information
Jack-Khuu authored and pytorchmergebot committed Jun 27, 2023
1 parent 95707ac commit 18dacf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions test/edge/custom_ops.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- func: custom::add_3.out(Tensor a, Tensor b, Tensor c, *, Tensor(a!) out) -> Tensor(a!)
dispatch:
CPU: custom::add_3_out
kernels:
- arg_meta: null
kernel_name: custom::add_3_out
13 changes: 10 additions & 3 deletions torchgen/executorch/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ def parse_et_yaml(
et_kernel = extract_kernel_fields(es)

# Remove ET specific fields from entries for BC compatibility
for entry in es:
for field in ET_FIELDS:
entry.pop(field, None)
strip_et_fields(es)

native_yaml = parse_native_yaml(
path,
Expand All @@ -142,3 +140,12 @@ def parse_et_yaml(
loaded_yaml=es,
)
return native_yaml.native_functions, et_kernel


def strip_et_fields(es: object) -> None:
"""Given a loaded yaml representing a list of operators,
remove ET specific fields from every entries for BC compatibility
"""
for entry in es: # type: ignore[attr-defined]
for field in ET_FIELDS:
entry.pop(field, None)

0 comments on commit 18dacf7

Please sign in to comment.