|
12 | 12 | from typing import Any, List, Optional |
13 | 13 |
|
14 | 14 | import torch |
| 15 | +import tosa_serializer as ts |
15 | 16 |
|
16 | 17 | from executorch.backends.arm.tosa.specification import Tosa_1_00, TosaSpecification |
17 | 18 |
|
18 | 19 |
|
| 20 | +def supported_data_layout_dtypes( |
| 21 | + tosa_spec: TosaSpecification, |
| 22 | + *, |
| 23 | + include_bool: bool = True, |
| 24 | + allow_int16_without_extension: bool = True, |
| 25 | + include_mxfp: bool = False, |
| 26 | +) -> List[Any]: |
| 27 | + """Return serializer dtypes supported by TOSA data-layout ops.""" |
| 28 | + supported_dtypes = [] |
| 29 | + if include_bool: |
| 30 | + supported_dtypes.append(ts.DType.BOOL) |
| 31 | + if tosa_spec.support_integer(): |
| 32 | + if allow_int16_without_extension: |
| 33 | + supported_dtypes.extend([ts.DType.INT8, ts.DType.INT16, ts.DType.INT32]) |
| 34 | + else: |
| 35 | + supported_dtypes.extend([ts.DType.INT8, ts.DType.INT32]) |
| 36 | + if tosa_spec.support_extension("int16"): |
| 37 | + supported_dtypes.append(ts.DType.INT16) |
| 38 | + if tosa_spec.support_float(): |
| 39 | + supported_dtypes.extend([ts.DType.FP16, ts.DType.FP32]) |
| 40 | + if tosa_spec.support_extension("bf16"): |
| 41 | + supported_dtypes.append(ts.DType.BF16) |
| 42 | + if tosa_spec.support_extension("fp8e4m3"): |
| 43 | + supported_dtypes.append(ts.DType.FP8E4M3) |
| 44 | + if tosa_spec.support_extension("fp8e5m2"): |
| 45 | + supported_dtypes.append(ts.DType.FP8E5M2) |
| 46 | + if include_mxfp and tosa_spec.support_extension("mxfp"): |
| 47 | + for dtype in (ts.DType.FP8E4M3, ts.DType.FP8E5M2): |
| 48 | + if dtype not in supported_dtypes: |
| 49 | + supported_dtypes.append(dtype) |
| 50 | + return supported_dtypes |
| 51 | + |
| 52 | + |
19 | 53 | def validate_num_inputs(op_name: str, inputs: List[Any], expected: int | List[int]): |
20 | 54 | """Validate the number of inputs against expected values. |
21 | 55 |
|
|
0 commit comments