diff options
author | Won Jeon <won.jeon@arm.com> | 2023-08-10 10:33:01 +0000 |
---|---|---|
committer | Won Jeon <won.jeon@arm.com> | 2023-08-18 15:21:15 -0700 |
commit | a21b2e88d19d8cb11a9120d40bacbb594d600565 (patch) | |
tree | 3bc8a40db72a31c1e552a3bd6339627a1175686e /verif | |
parent | e0247481eb1f83f6eb7161d3f7ac2690b180952a (diff) | |
download | reference_model-a21b2e88d19d8cb11a9120d40bacbb594d600565.tar.gz |
Add DIM operator to reference model
Signed-off-by: Won Jeon <won.jeon@arm.com>
Change-Id: Iea11ee5d3d98773e9c5e9b827593c05afb41ce3b
Diffstat (limited to 'verif')
-rw-r--r-- | verif/conformance/test_select.py | 7 | ||||
-rw-r--r-- | verif/conformance/tosa_base_profile_ops_info.json | 54 | ||||
-rw-r--r-- | verif/conformance/tosa_main_profile_ops_info.json | 39 | ||||
-rw-r--r-- | verif/generator/tosa_test_gen.py | 91 | ||||
-rw-r--r-- | verif/generator/tosa_utils.py | 1 |
5 files changed, 190 insertions, 2 deletions
diff --git a/verif/conformance/test_select.py b/verif/conformance/test_select.py index f4e2a61..b7bbfc3 100644 --- a/verif/conformance/test_select.py +++ b/verif/conformance/test_select.py @@ -506,6 +506,13 @@ class DepthwiseConv2dOperator(Operator): param_names = ["kernel", "shape", "type", "accum_type", "stride", "pad", "dilation"] +class DimOeprator(Operator): + """Test selector for the DIM operator.""" + + name = "dim" + param_names = ["shape", "type", "axis"] + + class EqualOperator(Operator): """Test selector for the EQUAL operator.""" diff --git a/verif/conformance/tosa_base_profile_ops_info.json b/verif/conformance/tosa_base_profile_ops_info.json index 4e3cd03..772602b 100644 --- a/verif/conformance/tosa_base_profile_ops_info.json +++ b/verif/conformance/tosa_base_profile_ops_info.json @@ -1317,6 +1317,60 @@ } } }, + "dim": { + "group": "data_layout", + "profile": [ + "tosa-bi", + "tosa-mi" + ], + "generation": { + "standard": { + "generator_args": [ + [ + "--target-dtype", + "int8", + "--target-dtype", + "int16", + "--target-dtype", + "int32", + "--target-dtype", + "bool", + "--tensor-dim-range", + "1,64", + "--target-rank", + "1", + "--target-rank", + "2", + "--target-rank", + "3" + ] + ] + }, + "8k_level": { + "no_negative_tests": "true", + "selector": "8k_level", + "generator_args": [ + [ + "--target-dtype", + "int8", + "--tensor-dim-range", + "1,10", + "--target-rank", + "6" + ] + ] + } + }, + "selection": { + "default": { + "params": {}, + "permutes": [ + "shape", + "type" + ] + } + } + }, "equal": { "group": "comparison", "profile": [ diff --git a/verif/conformance/tosa_main_profile_ops_info.json b/verif/conformance/tosa_main_profile_ops_info.json index 07b6af3..7388835 100644 --- a/verif/conformance/tosa_main_profile_ops_info.json +++ b/verif/conformance/tosa_main_profile_ops_info.json @@ -787,6 +787,45 @@ } } }, + "dim": { + "group": "data_layout", + "profile": [ + "tosa-mi" + ], + "generation": { + "standard": { + "generator_args": [ + [ + "--target-dtype", + "fp32", + "--target-dtype", + "fp16", + "--target-dtype", + "bf16", + "--fp-values-range", + "-2.0,2.0", + "--tensor-dim-range", + "1,65", + "--target-rank", + "1", + "--target-rank", + "2", + "--target-rank", + "3" + ] + ] + } + }, + "selection": { + "default": { + "params": {}, + "permutes": [ + "shape", + "type" + ] + } + } + }, "equal": { "group": "comparison", "profile": [ diff --git a/verif/generator/tosa_test_gen.py b/verif/generator/tosa_test_gen.py index b5e71ac..8c18e67 100644 --- a/verif/generator/tosa_test_gen.py +++ b/verif/generator/tosa_test_gen.py @@ -88,7 +88,9 @@ class TosaTestGen: return np.int32(self.rng.integers(low=-32768, high=32768, size=shape)) elif dtype == DType.UINT16: return np.int32(self.rng.integers(low=0, high=65536, size=shape)) - elif dtype == DType.INT32: + elif ( + dtype == DType.INT32 or dtype == DType.SHAPE + ): # restricting too large value for SHAPE return np.int32( self.rng.integers(low=-(1 << 31), high=(1 << 31), size=shape) ) @@ -181,7 +183,9 @@ class TosaTestGen: low, high = (-128, 128) elif dtype == DType.INT16: low, high = (-32768, 32768) - elif dtype == DType.INT32: + elif ( + dtype == DType.INT32 or dtype == DType.SHAPE + ): # restricting too large value for SHAPE low, high = (-(1 << 31), (1 << 31)) elif dtype == DType.INT48: low, high = (-(1 << 47), (1 << 47)) @@ -1310,6 +1314,49 @@ class TosaTestGen: self.ser.addOperator(op["op"], input_list, output_list, attr) return result_tens + def build_dim( + self, + op, + a, + axis, + validator_fcns=None, + error_name=None, + qinfo=None, + ): + result_tens = OutputShaper.dimOp(self.ser, self.rng, a, axis, error_name) + + # Invalidate Input/Output list for error if checks. + input_list = [a.name] + output_list = [result_tens.name] + pCount, cCount = op["operands"] + num_operands = pCount + cCount + input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList( + self, error_name, input_list, output_list + ) + + if not TosaErrorValidator.evValidateErrorIfs( + self.ser, + validator_fcns, + error_name, + op=op, + axis=axis, + input_shape=a.shape, + input_dtype=a.dtype, + output_shape=result_tens.shape, + output_dtype=result_tens.dtype, + result_tensors=[result_tens], + input_list=input_list, + output_list=output_list, + num_operands=num_operands, + ): + return None + + attr = ts.TosaSerializerAttribute() + attr.AxisAttribute(axis) + + self.ser.addOperator(op["op"], input_list, output_list, attr) + return result_tens + def build_reshape(self, op, a, newShape, validator_fcns=None, error_name=None): result_tens = OutputShaper.reshapeOp( self.ser, self.rng, a, newShape, error_name @@ -3749,6 +3796,25 @@ class TosaTestGen: TosaErrorValidator.evWrongRank, ), }, + "dim": { + "op": Op.DIM, + "operands": (1, 0), + "build_fcn": ( + build_dim, + TosaTensorGen.tgBasic, + TosaTensorValuesGen.tvgDefault, + TosaArgGen.agAxis, + ), + "types": TYPE_FIB, + "error_if_validators": ( + TosaErrorValidator.evAxisLargerRank, + TosaErrorValidator.evAxisSmallerZero, + TosaErrorValidator.evWrongInputType, + TosaErrorValidator.evWrongInputList, + TosaErrorValidator.evWrongOutputList, + TosaErrorValidator.evWrongRank, + ), + }, "reshape": { "op": Op.RESHAPE, "operands": (1, 0), @@ -4665,6 +4731,27 @@ class OutputShaper: return ser.addOutput(output_shape, outputDType) @staticmethod + def dimOp(ser, rng, a, axis, error_name=None): + output_shape = [1] + + if error_name == ErrorIf.WrongOutputType: + all_dtypes = [ + DType.INT8, + DType.INT16, + DType.INT32, + DType.INT48, + DType.FP32, + DType.FP16, + DType.BF16, + ] + wrong_dtypes = list(set(all_dtypes)) + outputDType = rng.choice(wrong_dtypes) + else: + outputDType = DType.SHAPE + + return ser.addOutput(output_shape, outputDType) + + @staticmethod def reshapeOp(ser, rng, a, shape, error_name=None): output_shape = shape.copy() diff --git a/verif/generator/tosa_utils.py b/verif/generator/tosa_utils.py index 8ff62f1..f9df8d5 100644 --- a/verif/generator/tosa_utils.py +++ b/verif/generator/tosa_utils.py @@ -18,6 +18,7 @@ DTYPE_ATTRIBUTES = { DType.UINT16: {"str": "u16", "width": 16}, DType.INT32: {"str": "i32", "width": 32}, DType.INT48: {"str": "i48", "width": 48}, + DType.SHAPE: {"str": "i64", "width": 64}, DType.FP16: {"str": "f16", "width": 16}, DType.BF16: {"str": "bf16", "width": 16}, DType.FP32: {"str": "f32", "width": 32}, |