Translates Executorch DSL dialect to use the same syntax as native_functions.yaml. The major difference is that Executorch DSL dialect supports "op" key, where it refers to the operator name in native_functions.yaml. For example, a functions.yaml may have the following entry: - op:
(
tags_yaml_path: str,
aten_yaml_path: str,
native_yaml_path: str | None,
use_aten_lib: bool,
out_file: TextIO,
)
| 640 | |
| 641 | |
| 642 | def translate_native_yaml( |
| 643 | tags_yaml_path: str, |
| 644 | aten_yaml_path: str, |
| 645 | native_yaml_path: str | None, |
| 646 | use_aten_lib: bool, |
| 647 | out_file: TextIO, |
| 648 | ) -> None: |
| 649 | """Translates Executorch DSL dialect to use the same syntax as |
| 650 | native_functions.yaml. The major difference is that Executorch DSL dialect |
| 651 | supports "op" key, where it refers to the operator name in native_functions.yaml. |
| 652 | |
| 653 | For example, a functions.yaml may have the following entry: |
| 654 | |
| 655 | - op: add.out |
| 656 | ... |
| 657 | |
| 658 | It needs to be translated to the following: |
| 659 | |
| 660 | - func: add.out(Tensor self, Tensor other, *, Scalar alpha=1, Tensor(a!) out) -> Tensor(a!) |
| 661 | ... |
| 662 | |
| 663 | We go in aten_yaml_path and find the operator schema for "add.out" and add it |
| 664 | to the original functions.yaml. We also add required field "variants", where for |
| 665 | Executorch it will always be "function". |
| 666 | |
| 667 | For ATen mode we don't have to do the translation because native_yaml_path is |
| 668 | the same as native_functions.yaml. |
| 669 | |
| 670 | Args: |
| 671 | tags_yaml_path: Path to a tags.yaml file to satisfy codegen parsing. |
| 672 | It is not optional. |
| 673 | aten_yaml_path: Path to ATen operator yaml file native_functions.yaml. |
| 674 | native_yaml_path: Path to a functions.yaml file to parse. |
| 675 | If the path does not exist in the filesystem, it is treated as an |
| 676 | empty file. If `custom_ops_yaml_path` exists, the contents of that |
| 677 | file are appended to the yaml input to be parsed. |
| 678 | use_aten_lib: We use this flag to determine if we want to generate native |
| 679 | functions. In ATen mode we should generate out= variants. |
| 680 | out_file: The IO object that we are writing into. |
| 681 | Returns: |
| 682 | None |
| 683 | """ |
| 684 | if use_aten_lib: |
| 685 | with open(aten_yaml_path) as aten_yaml: |
| 686 | out_file.writelines(aten_yaml.readlines()) |
| 687 | return |
| 688 | |
| 689 | native_functions, persisted_fields = parse_et_yaml( |
| 690 | aten_yaml_path, |
| 691 | tags_yaml_path, |
| 692 | None, |
| 693 | skip_native_fns_gen=False, |
| 694 | ) |
| 695 | |
| 696 | func_to_scoped_name: dict[FunctionSchema, str] = { |
| 697 | f.func: f"{f.namespace}::{f.func.name}" for f in native_functions |
| 698 | } |
| 699 | op_to_scoped_name: dict[OperatorName, str] = { |