From 862c007ff8637e88ccaac385ae7baab0e7ff5b19 Mon Sep 17 00:00:00 2001 From: Jeremy Johnson Date: Tue, 16 Apr 2024 12:23:44 +0100 Subject: Correct types of int16 and int8 input tensors for tests Fixes input tensors for int16 and int8 tests for MUL, LOGICAL_LEFT/RIGHT_SHIFT, COND_IF, WHILE_LOOP Change tensor generator functions to use type aware randTensor() function. Signed-off-by: Jeremy Johnson Change-Id: If81a783929c29e1fd5e91477dbcdaf79c738f6b0 --- verif/generator/tosa_arg_gen.py | 44 +++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/verif/generator/tosa_arg_gen.py b/verif/generator/tosa_arg_gen.py index 26dd6f9..22b23fe 100644 --- a/verif/generator/tosa_arg_gen.py +++ b/verif/generator/tosa_arg_gen.py @@ -925,8 +925,8 @@ class TosaTensorValuesGen: # range max_val = (1 << 31) - 1 min_val = -max_val - arr = np.int32( - rng.integers(low=min_val, high=(max_val + 1), size=shapeList[0]) + arr = rng.randTensor( + shapeList[0], dtypeList[0], data_range=(min_val, (max_val + 1)) ) tens_ser_list = [] tens_ser_list.append( @@ -1046,9 +1046,13 @@ class TosaTensorValuesGen: tens_ser_list = [] for idx, shape in enumerate(shapeList[:]): if dtypeList[0] == DType.INT32: - arr = rng.randTensor(shapeList[idx], DType.INT16) + # Limit data range to avoid saturation + arr = np.int32(rng.randTensor(shapeList[idx], DType.INT16)) else: - arr = np.int32(rng.integers(low=0, high=32, size=shapeList[idx])) + arr = rng.randTensor( + shapeList[idx], dtypeList[0], data_range=(0, 32) + ) + if pRemain > 0: tens_ser_list.append( testGen.ser.addPlaceholder(shape, dtypeList[idx], arr) @@ -1080,13 +1084,13 @@ class TosaTensorValuesGen: for idx, shape in enumerate(shapeList[:]): if idx == 1: if dtypeList[idx] == DType.INT8: - arr = np.int8(rng.integers(low=0, high=8, size=shape)) + arr = rng.randTensor(shape, dtypeList[idx], data_range=(0, 8)) elif dtypeList[idx] == DType.INT16: - arr = np.int16(rng.integers(low=0, high=16, size=shape)) + arr = rng.randTensor(shape, dtypeList[idx], data_range=(0, 16)) elif dtypeList[idx] == DType.INT32: - arr = np.int32(rng.integers(low=0, high=32, size=shape)) + arr = rng.randTensor(shape, dtypeList[idx], data_range=(0, 32)) elif error_name == ErrorIf.WrongInputType: - arr = np.int32(rng.integers(low=0, high=8, size=shape)) + arr = rng.randTensor(shape, DType.INT32, data_range=(0, 8)) else: raise Exception("OpArithmeticRightShift: invalid input dtype") else: @@ -1261,12 +1265,17 @@ class TosaTensorValuesGen: shift = 0 else: shift = argsDict["shift"] + + np_type = np.int32 if dtypeList[0] == DType.INT8: num_bits = 8 + np_type = np.int8 elif dtypeList[0] == DType.INT16: num_bits = 16 + np_type = np.int16 elif dtypeList[0] in (DType.INT32, DType.SHAPE): num_bits = 32 + # np_type is not used for DType.SHAPE so leave as np.int32 elif error_name == ErrorIf.WrongInputType: num_bits = 8 else: @@ -1282,8 +1291,12 @@ class TosaTensorValuesGen: low = -(2 ** (num_bits - 1)) high = (2 ** (num_bits - 1)) - 1 - a_arr = np.int32(rng.integers(low=low, high=high, size=shapeList[0])) - b_arr = np.int32(rng.integers(low=low, high=high, size=shapeList[1])) + a_arr = rng.randTensor( + shapeList[0], DType.INT32, data_range=(low, high) + ) + b_arr = rng.randTensor( + shapeList[1], DType.INT32, data_range=(low, high) + ) i = 0 while True: @@ -1318,12 +1331,12 @@ class TosaTensorValuesGen: # MUL with 3 inputs (3rd is shift) tens_ser_list.append( testGen.ser.addPlaceholder( - shapeList[0], dtypeList[0], a_arr.astype(np.int32) + shapeList[0], dtypeList[0], a_arr.astype(np_type) ) ) tens_ser_list.append( testGen.ser.addPlaceholder( - shapeList[1], dtypeList[1], b_arr.astype(np.int32) + shapeList[1], dtypeList[1], b_arr.astype(np_type) ) ) tens_ser_list.append( @@ -1369,7 +1382,8 @@ class TosaTensorValuesGen: pCount == 2 and cCount == 0 ), "Op.LOGICAL_LEFT_SHIFT or Op.LOGICAL_RIGHT_SHIFT must have 2 placeholders, 0 consts" values_arr = rng.randTensor(shapeList[0], dtypeList[0]) - shift_arr = np.int32(rng.integers(low=0, high=32, size=shapeList[1])) + shift_arr = rng.randTensor(shapeList[1], dtypeList[0], data_range=(0, 32)) + tens_ser_list = [] tens_ser_list.append( testGen.ser.addPlaceholder(shapeList[0], dtypeList[0], values_arr) @@ -1439,8 +1453,8 @@ class TosaTensorValuesGen: # Limit values so that the sum cannot exceed the range of an int32 during # summation of any axis range_val = int((1 << 31) / max(shapeList[0])) - values_arr = np.int32( - rng.integers(low=-range_val, high=range_val, size=shapeList[0]) + values_arr = rng.randTensor( + shapeList[0], dtype, data_range=(-range_val, range_val) ) tens_ser_list = [] tens_ser_list.append( -- cgit v1.2.1