Apply pattern matching to each function in the given module, and group matched expressions into a new function. The end result is similar to FuseOps, but fusion is driven completely by the provided patterns. Note: Only operates within dataflow blocks. ConvertToDataflow may need to be c
(
patterns: list[FusionPattern | tuple],
bind_constants: bool = True,
annotate_codegen: bool = False,
entry_functions: list[str] | None = None,
)
| 903 | |
| 904 | |
| 905 | def FuseOpsByPattern( |
| 906 | patterns: list[FusionPattern | tuple], |
| 907 | bind_constants: bool = True, |
| 908 | annotate_codegen: bool = False, |
| 909 | entry_functions: list[str] | None = None, |
| 910 | ) -> tvm.ir.transform.Pass: |
| 911 | """Apply pattern matching to each function in the given module, and group matched expressions |
| 912 | into a new function. |
| 913 | |
| 914 | The end result is similar to FuseOps, but fusion is driven completely by the provided patterns. |
| 915 | |
| 916 | Note: Only operates within dataflow blocks. ConvertToDataflow may need to be called first. |
| 917 | |
| 918 | Parameters |
| 919 | ---------- |
| 920 | patterns : List[Union[FusionPattern, Tuple]] |
| 921 | A list of patterns to be matched. The order of the patterns determines the order of priority |
| 922 | in which they are matched. Higher-priority patterns should come earlier in the list. |
| 923 | |
| 924 | In addition to FusionPattern, a tuple can be passed as item of this list. The pattern |
| 925 | will be constructed through :code:`FusionPattern(*item)` |
| 926 | |
| 927 | bind_constants : bool |
| 928 | Whether or not to keep bound constants in the grouped function. |
| 929 | |
| 930 | annotate_codegen : bool |
| 931 | If True, wrap each created composite function with another function, whose body consists |
| 932 | only of a call to the composite function, and annotate the outer function with "Codegen" |
| 933 | and "global_symbol" attributes. The "Codegen" attribute is set as the prefix of the |
| 934 | corresponding pattern name. For example, "dnnl" if the pattern name is "dnnl.conv2d_relu". |
| 935 | |
| 936 | This must be True if the created composite functions are intended to be offloaded to |
| 937 | an external backend without using the MergeCompositeFunctions pass. |
| 938 | |
| 939 | entry_functions : Optional[List[str]] |
| 940 | The set of entry functions to start from. |
| 941 | |
| 942 | Returns |
| 943 | ------- |
| 944 | ret : tvm.transform.Pass |
| 945 | The registered pass for pattern-based fusion. |
| 946 | |
| 947 | """ |
| 948 | converted_patterns = [] |
| 949 | for pattern in patterns: |
| 950 | if isinstance(pattern, tuple): |
| 951 | converted_patterns.append(FusionPattern(*pattern)) |
| 952 | elif isinstance(pattern, FusionPattern): |
| 953 | converted_patterns.append(pattern) |
| 954 | else: |
| 955 | raise ValueError(f"Invalid pattern: {pattern}") |
| 956 | |
| 957 | return _ffi_api.FuseOpsByPattern( |
| 958 | converted_patterns, |
| 959 | bind_constants, |
| 960 | annotate_codegen, |
| 961 | entry_functions or [], |
| 962 | ) # type: ignore |
searching dependent graphs…