| 52 | |
| 53 | @dataclass(frozen=True) |
| 54 | class 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 |
no outgoing calls