diff options
author | Jerry Ge <jerry.ge@arm.com> | 2024-01-02 22:29:08 +0000 |
---|---|---|
committer | Jerry Ge <jerry.ge@arm.com> | 2024-01-25 17:42:12 +0000 |
commit | c5291695f04901e8abbc26dad6cba10e2c7685f8 (patch) | |
tree | 6ba3ea7399e9e5ee679ca2ef4bf9770c8e5046dc /verif/generator/tosa_test_gen.py | |
parent | 74342e522ec61e85fde64fe801da9e750b3e2d86 (diff) | |
download | reference_model-c5291695f04901e8abbc26dad6cba10e2c7685f8.tar.gz |
Save Int8/UInt8 reference outputs to native dtypes
* Int8/UInt8 reference outputs were previously saved to INT32
* Save those in their native dtypes and updated other affected code
Signed-off-by: Jerry Ge <jerry.ge@arm.com>
Georgios Pinitas <georgios.pinitas@arm.com>
Change-Id: Id65fc8773150d3c56bc2c72789a6a0d3c78cd363
Diffstat (limited to 'verif/generator/tosa_test_gen.py')
-rw-r--r-- | verif/generator/tosa_test_gen.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/verif/generator/tosa_test_gen.py b/verif/generator/tosa_test_gen.py index b9352ac..28cf392 100644 --- a/verif/generator/tosa_test_gen.py +++ b/verif/generator/tosa_test_gen.py @@ -191,6 +191,10 @@ class TosaTestGen: if dtype == DType.BOOL: return np.bool_(self.rng.choice(a=[False, True], size=shape)) + elif dtype == DType.INT8: + return np.int8(self.rng.integers(low=low, high=high, size=shape)) + elif dtype == DType.UINT8: + return np.uint8(self.rng.integers(low=low, high=high, size=shape)) elif dtype in (DType.INT48, DType.SHAPE): return np.int64(self.rng.integers(low=low, high=high, size=shape)) elif dtype in (DType.FP16, DType.BF16, DType.FP32): @@ -2079,7 +2083,16 @@ class TosaTestGen: val_adj = np.subtract(values, input_zp, dtype=np.int64) val_adj = np.maximum(val_adj, min_shift_value_arr, dtype=np.int64) val_adj = np.minimum(val_adj, max_shift_value_arr, dtype=np.int64) - val_adj = np.add(val_adj, input_zp, dtype=values.dtype) + val_adj = np.add(val_adj, input_zp, dtype=np.int64) + # Check we can safely convert to the expected dtype + assert ( + val_adj.all() >= np.iinfo(values.dtype).min + and val_adj.all() <= np.iinfo(values.dtype).max + ) + + # Force casting to output datatype + val_adj = val_adj.astype(values.dtype, casting="unsafe") + if not np.all(np.array_equal(values, val_adj)): # Values changed so overwrite file with new values np.save( |