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 | |
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')
-rwxr-xr-x | verif/frameworks/tosa_verif_framework_compiler_runner.py | 11 | ||||
-rw-r--r-- | verif/generator/tosa_test_gen.py | 15 |
2 files changed, 19 insertions, 7 deletions
diff --git a/verif/frameworks/tosa_verif_framework_compiler_runner.py b/verif/frameworks/tosa_verif_framework_compiler_runner.py index ab3db90..ce9b253 100755 --- a/verif/frameworks/tosa_verif_framework_compiler_runner.py +++ b/verif/frameworks/tosa_verif_framework_compiler_runner.py @@ -691,12 +691,11 @@ def run_test(args, test_path, framework): tf_result = tf_result.astype(np.float64) elif tf_result.dtype == np.float16: tf_result = tf_result.astype(np.float32) - elif ( - tf_result.dtype == np.uint8 - or tf_result.dtype == np.int8 - or tf_result.dtype == np.int16 - or tf_result.dtype == np.int64 - ): + elif tf_result.dtype == np.int8: + tf_result = tf_result.astype(np.int8) + elif tf_result.dtype == np.uint8: + tf_result = tf_result.astype(np.uint8) + elif tf_result.dtype == np.int16 or tf_result.dtype == np.int64: tf_result = tf_result.astype(np.int32) # For now, search for the first output from ref_model 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( |