MCPcopy Create free account
hub / github.com/pytorch/executorch / ETKernelKey

Class ETKernelKey

codegen/model.py:54–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52
53@dataclass(frozen=True)
54class ETKernelKey:
55 # Field undefined is default = True
56 arg_meta: tuple[ETKernelKeyOpArgMeta, ...] = ()
57
58 # Indicator for this kernel being used as a catch all
59 default: bool = False
60
61 version: int = KERNEL_KEY_VERSION
62
63 @staticmethod
64 def gen_from_yaml(
65 args: dict[str, tuple[str, str]],
66 type_alias_map: dict[str, list[str]], # TODO: Support unwrapped str val
67 dim_order_alias_map: dict[str, list[int]],
68 ) -> list[ETKernelKey]:
69 """Generate ETKernelKeys from arg kernel specs
70 Multiple ETKernelKeys are returned due to dtype permutations from utilizing
71 type_alias_map (actualizing each potential type permutation as a KernelKey)
72
73 Args:
74 args: Mapping from argument name to kernel specs
75 Kernel specs are a tuple of (dtype, dim_order).
76 Currently tuple entries must be aliased via the alias map arguments
77 type_alias_map: Mapping from type alias to potential type enums
78 i.e { T0 : [Double, Int] } means T0 can be either Double or Int
79 Used for lookup by args
80 dim_order_alias_map: Mapping from alias to a list of dimension orders
81 Used for lookup by args
82 """
83 # Cast to dim order to int
84 dim_order_alias_map = {
85 k: [int(alias) for alias in v] for k, v in dim_order_alias_map.items()
86 }
87 kernel_keys = []
88
89 # Get all used Dtype Alias
90 dtype_alias_used = set()
91 for type_alias, dim_order in args.values():
92 # Enforce usage of alias initially
93 # TODO: Support inlined arguments
94 assert type_alias in type_alias_map, "Undefined type alias: " + str(
95 type_alias
96 )
97 assert (
98 dim_order in dim_order_alias_map
99 ), f"Undefined dim_order alias: {dim_order}"
100 dtype_alias_used.add(type_alias)
101
102 # Generate all permutations of dtype alias values
103 alias_dtypes = [
104 [(alias, dtype) for dtype in type_alias_map[alias]]
105 for alias in dtype_alias_used
106 ]
107 alias_permutations = [
108 dict(permutation) for permutation in list(itertools.product(*alias_dtypes))
109 ]
110
111 # Using each alias value permutation, generate kernel keys

Callers 5

setUpMethod · 0.90
parse_from_yamlFunction · 0.85
gen_from_yamlMethod · 0.85
_to_backend_indexMethod · 0.85

Calls

no outgoing calls

Tested by 1

setUpMethod · 0.72