blob: 38ab3f4b35aa3e02f271c0a7ce435d4bee2676c3 [file] [log] [blame]
Jeremy Johnsond80ea5e2024-01-03 10:54:12 +00001# Copyright (c) 2020-2024, ARM Limited.
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002# SPDX-License-Identifier: Apache-2.0
Jeremy Johnson1271c442023-09-05 11:39:26 +01003import json
Jeremy Johnsonaf090182024-02-13 18:25:39 +00004import logging
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005import os
Matthew Haddon630c17c2021-10-14 15:05:41 +01006from copy import deepcopy
Jeremy Johnson1271c442023-09-05 11:39:26 +01007from datetime import datetime
8from pathlib import Path
Eric Kunzee5e26762020-10-13 16:11:07 -07009
Jeremy Johnson1271c442023-09-05 11:39:26 +010010import generator.tosa_utils as gtu
Jeremy Johnson5c1364c2022-01-13 15:04:21 +000011import numpy as np
Jeremy Johnson2ec34942021-12-14 16:34:05 +000012import serializer.tosa_serializer as ts
Jeremy Johnson65ba8092023-10-09 16:31:13 +010013from generator.datagenerator import GenerateLibrary
Jeremy Johnson9a66abb2022-04-07 11:29:20 +010014from generator.tosa_arg_gen import TosaArgGen
15from generator.tosa_arg_gen import TosaQuantGen
16from generator.tosa_arg_gen import TosaTensorGen
17from generator.tosa_arg_gen import TosaTensorValuesGen
Jeremy Johnson2ec34942021-12-14 16:34:05 +000018from generator.tosa_error_if import ErrorIf
Jeremy Johnson9a66abb2022-04-07 11:29:20 +010019from generator.tosa_error_if import TosaErrorIfArgGen
20from generator.tosa_error_if import TosaErrorValidator
21from generator.tosa_error_if import TosaInvalidValidator
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +010022from generator.tosa_random_gen import TosaHashRandomGenerator
23from generator.tosa_random_gen import TosaRandomGenerator
Jeremy Johnson1271c442023-09-05 11:39:26 +010024from schemavalidation.schemavalidation import TestDescSchemaValidator
Les Bell0e027d42021-11-09 14:42:14 +000025from tosa.DType import DType
26from tosa.Op import Op
Matthew Haddonb724efc2021-08-25 16:40:29 +010027
Jeremy Johnson1271c442023-09-05 11:39:26 +010028TOSA_AUTOGENERATED_HEADER = f"""// Copyright (c) {datetime.today().year}, ARM Limited
29// SPDX-License-Identifier: Apache-2.0
30// AUTO-GENERATED FILE CREATED BY tosa_verif_build_tests
31"""
32
Jeremy Johnsonaf090182024-02-13 18:25:39 +000033logging.basicConfig()
34logger = logging.getLogger("tosa_verif_build_tests")
35
Matthew Haddonb724efc2021-08-25 16:40:29 +010036
Eric Kunzee5e26762020-10-13 16:11:07 -070037class TosaTestGen:
Jeremy Johnsonfd05bb32023-02-07 16:39:24 +000038 # This currently matches the 8K level defined in the specification.
Jeremy Johnsonb2099702023-04-12 15:59:01 +010039 TOSA_8K_LEVEL_MAX_SCALE = 64
Jeremy Johnson0c716862023-04-13 17:18:19 +010040 TOSA_8K_LEVEL_MAX_KERNEL = 8192
41 TOSA_8K_LEVEL_MAX_STRIDE = 8192
Jeremy Johnson97eb75f2021-07-08 11:58:02 +010042
Jeremy Johnson1271c442023-09-05 11:39:26 +010043 # Main compliance dot product statistical test range
Jeremy Johnson30476252023-11-20 16:15:30 +000044 TOSA_MI_DOT_PRODUCT_TEST_SETS = 6
Jeremy Johnson1271c442023-09-05 11:39:26 +010045 TOSA_MI_DOT_PRODUCT_MIN = 1000
46
Eric Kunzee5e26762020-10-13 16:11:07 -070047 def __init__(self, args):
48 self.args = args
49 self.basePath = args.output_dir
50 self.random_seed = args.random_seed
51 self.ser = None
Eric Kunzee5e26762020-10-13 16:11:07 -070052 self.createDynamicOpLists()
53 self.initOpListDefaults()
54 self.quantGen = TosaQuantGen()
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +010055 self.global_rng = None
Eric Kunzee5e26762020-10-13 16:11:07 -070056 # Force makeShape to do a specific starting shape
57 self.targetted_shape = None
Jeremy Johnson1271c442023-09-05 11:39:26 +010058 # JSON schema validation
59 self.descSchemaValidator = TestDescSchemaValidator()
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +010060 # Data generator library is sometimes needed for compliance set up
61 # even if we are generating the data later (lazy_data_generation)
62 self.dgl = GenerateLibrary(args.generate_lib_path)
Eric Kunzee5e26762020-10-13 16:11:07 -070063
Jeremy Johnsona4d907e2023-10-26 13:53:14 +010064 # Work out floating point range
65 def convertFPRange(rangeFP, maxFP):
66 # Converts program arguments of max/-max to FP max
67 vals = []
68 for v in rangeFP:
69 if v == "max":
70 v = maxFP
71 elif v == "-max":
72 v = -maxFP
Jeremy Johnsona8420ad2023-12-07 16:35:28 +000073 elif v < 0:
74 # Trim to minimum data type value
75 v = max(v, -maxFP)
76 elif v > 0:
77 # Trim to maximum data type value
78 v = min(v, maxFP)
Jeremy Johnsona4d907e2023-10-26 13:53:14 +010079 vals.append(v)
80 return tuple(sorted(vals))
81
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +010082 self.random_dtype_range = {
83 DType.SHAPE: tuple(self.args.tensor_shape_range[0:2])
84 }
Won Jeon2c34b462024-02-06 18:37:00 +000085 for dtype in (DType.FP32, DType.FP16, DType.BF16, DType.FP8E4M3, DType.FP8E5M2):
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +010086 self.random_dtype_range[dtype] = convertFPRange(
Jeremy Johnsona4d907e2023-10-26 13:53:14 +010087 args.tensor_fp_value_range,
88 TosaTensorValuesGen.TVG_FLOAT_HIGH_VALUE[dtype],
89 )
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +010090 self.resetGlobalRNG()
91
92 def resetGlobalRNG(self):
93 self.global_rng = TosaRandomGenerator(self.random_seed, self.random_dtype_range)
Jeremy Johnsona4d907e2023-10-26 13:53:14 +010094
Eric Kunzee5e26762020-10-13 16:11:07 -070095 def createSerializer(self, opName, testPath):
96 self.testPath = os.path.join(opName, testPath)
97
98 fullPath = os.path.join(self.basePath, self.testPath)
99 os.makedirs(fullPath, exist_ok=True)
Jeremy Johnson55363fd2023-07-25 14:10:50 +0100100 # Embed const data in the flatbuffer
101 constMode = ts.ConstMode.EMBED
Jeremy Johnson1271c442023-09-05 11:39:26 +0100102 if self.args.lazy_data_gen:
103 # Lazy data generation - so make constants files
104 constMode = ts.ConstMode.INPUTS
105 elif self.args.dump_consts:
Jeremy Johnson55363fd2023-07-25 14:10:50 +0100106 constMode = ts.ConstMode.EMBED_DUMP
107 self.ser = ts.TosaSerializer(fullPath, constMode)
Eric Kunzee5e26762020-10-13 16:11:07 -0700108
109 def getSerializer(self):
110 return self.ser
111
evacha01ad8e1e22024-03-19 12:42:17 +0000112 def serialize(self, testName, metaData=None, tags=None):
Jeremy Johnson1271c442023-09-05 11:39:26 +0100113 path = Path(self.basePath) / self.testPath
114
115 # Write out TOSA flatbuffer binary
116 path_fb = path / f"{testName}.tosa"
117 with path_fb.open("wb") as fd:
Eric Kunzee5e26762020-10-13 16:11:07 -0700118 fd.write(self.ser.serialize())
119
Jeremy Johnson1271c442023-09-05 11:39:26 +0100120 # Get JSON descriptor from serializer
121 desc = json.loads(self.ser.writeJson(f"{testName}.tosa"))
122
123 if metaData:
124 # Add extra meta data to desc.json
125 desc["meta"] = metaData
126
evacha01ad8e1e22024-03-19 12:42:17 +0000127 if tags:
128 desc["tag"] = tags
129
Jeremy Johnson1271c442023-09-05 11:39:26 +0100130 # Validate desc.json before we output it
131 self.descSchemaValidator.validate_config(desc)
132
133 if metaData:
Jeremy Johnson65ba8092023-10-09 16:31:13 +0100134 if "data_gen" in metaData:
135 if self.args.lazy_data_gen:
136 # Output datagen meta data as CPP data
137 path_md = path / f"{testName}_meta_data_gen.cpp"
138 with path_md.open("w") as fd:
139 fd.write(TOSA_AUTOGENERATED_HEADER)
140 fd.write("// Test meta data for data generation setup\n\n")
141 fd.write(f'const char* json_tdg_config_{path.stem} = R"(')
142 json.dump(metaData["data_gen"], fd)
143 fd.write(')";\n\n')
Jeremy Johnson1271c442023-09-05 11:39:26 +0100144 if "compliance" in metaData:
145 # Output datagen meta data as CPP data
146 path_md = path / f"{testName}_meta_compliance.cpp"
147 with path_md.open("w") as fd:
148 fd.write(TOSA_AUTOGENERATED_HEADER)
149 fd.write("// Test meta data for compliance validation\n\n")
150 fd.write(f'const char* json_tvf_config_{path.stem} = R"(')
151 json.dump(metaData["compliance"], fd)
152 fd.write(')";\n\n')
153
154 # Write desc.json
155 path_desc = path / "desc.json"
156 with path_desc.open("w") as fd:
157 json.dump(desc, fd, indent=1)
Eric Kunzee5e26762020-10-13 16:11:07 -0700158
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100159 def buildPlaceholderTensors(self, rng, shape_list, dtype_list):
Eric Kunzee5e26762020-10-13 16:11:07 -0700160 placeholders = []
161
Kevin Cheng989cb052021-04-28 16:29:44 -0700162 assert len(shape_list) == len(dtype_list)
163
Jeremy Johnson1271c442023-09-05 11:39:26 +0100164 arr = None
Kevin Cheng989cb052021-04-28 16:29:44 -0700165 for idx, shape in enumerate(shape_list):
Jeremy Johnson1271c442023-09-05 11:39:26 +0100166 if not self.args.lazy_data_gen:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100167 arr = rng.randTensor(shape, dtype_list[idx])
Kevin Cheng989cb052021-04-28 16:29:44 -0700168 placeholders.append(self.ser.addPlaceholder(shape, dtype_list[idx], arr))
Eric Kunzee5e26762020-10-13 16:11:07 -0700169
170 return placeholders
171
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100172 def buildConstTensors(self, rng, shape_list, dtype_list):
Eric Kunzee5e26762020-10-13 16:11:07 -0700173 consts = []
174
Kevin Cheng989cb052021-04-28 16:29:44 -0700175 assert len(shape_list) == len(dtype_list)
176
Jeremy Johnson1271c442023-09-05 11:39:26 +0100177 arr = None
Kevin Cheng989cb052021-04-28 16:29:44 -0700178 for idx, shape in enumerate(shape_list):
Jeremy Johnson1271c442023-09-05 11:39:26 +0100179 if not self.args.lazy_data_gen:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100180 arr = rng.randTensor(shape, dtype_list[idx])
Kevin Cheng989cb052021-04-28 16:29:44 -0700181 consts.append(self.ser.addConst(shape, dtype_list[idx], arr))
Eric Kunzee5e26762020-10-13 16:11:07 -0700182
183 return consts
184
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100185 def makeShape(self, rng, rank):
Eric Kunzee5e26762020-10-13 16:11:07 -0700186 if self.targetted_shape:
187 return np.int32(self.targetted_shape)
Jeremy Johnson18a379d2024-03-28 15:53:21 +0000188 else:
189 return np.int32(
190 rng.integers(
191 low=self.args.tensor_shape_range[0],
192 high=self.args.tensor_shape_range[1],
193 size=rank,
194 )
Kevin Cheng550ccc52021-03-03 11:21:43 -0800195 )
Eric Kunzee5e26762020-10-13 16:11:07 -0700196
197 def setTargetShape(self, shape):
198 self.targetted_shape = shape
199
Eric Kunzee5e26762020-10-13 16:11:07 -0700200 def shapeStr(self, shape):
Jeremy Johnson18a379d2024-03-28 15:53:21 +0000201 assert shape is not None
202 if len(shape) > 0:
203 # Rank > 0
204 return "x".join([str(d) for d in shape])
205 else:
206 # Rank 0
207 return "0"
Eric Kunzee5e26762020-10-13 16:11:07 -0700208
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +0100209 def typeStr(self, dtype):
210 if isinstance(dtype, list) or isinstance(dtype, tuple):
211 assert len(dtype) >= 2
212 strs = [self.typeStr(t) for t in dtype]
213 # Limit types to the first 2 as the 3rd is the accumulator
214 return "x".join(strs[:2])
Eric Kunzee5e26762020-10-13 16:11:07 -0700215 else:
Jeremy Johnson1271c442023-09-05 11:39:26 +0100216 if dtype in gtu.DTYPE_ATTRIBUTES:
217 return gtu.DTYPE_ATTRIBUTES[dtype]["str"]
Kevin Cheng989cb052021-04-28 16:29:44 -0700218 else:
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +0100219 raise Exception(
220 "Unknown dtype, cannot convert to string: {}".format(dtype)
221 )
Eric Kunzee5e26762020-10-13 16:11:07 -0700222
Luke Hutton57287132023-02-06 14:54:18 +0000223 def constrictBatchSize(self, shape):
224 # Limit the batch size unless an explicit target shape set
225 if self.args.max_batch_size and not self.args.target_shapes:
226 shape[0] = min(shape[0], self.args.max_batch_size)
227 return shape
228
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100229 def makeDimension(self, rng):
230 return rng.randInt(
James Ward30124a82023-02-02 14:56:33 +0000231 low=self.args.tensor_shape_range[0], high=self.args.tensor_shape_range[1]
232 )
233
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100234 def tensorComplianceMetaData(
235 self, op, inputType, argsDict, outputTensor, errorName
236 ):
Jeremy Johnson4f931302024-01-04 17:05:24 +0000237 # TODO - Dot product Ops with BF16 inputs that produce FP32 outputs are not supported yet
238 UNSUPPORTED_NON_FP32_INPUT_OPS = (
239 Op.MATMUL,
240 Op.CONV2D,
241 Op.FULLY_CONNECTED,
242 Op.DEPTHWISE_CONV2D,
Jeremy Johnson95a67102024-01-10 14:16:39 +0000243 Op.TRANSPOSE_CONV2D,
evacha0147ab1762024-01-29 13:23:23 +0000244 Op.CONV3D,
Jeremy Johnson4f931302024-01-04 17:05:24 +0000245 )
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100246 if (
247 errorName
248 or not gtu.dtypeIsSupportedByCompliance(outputTensor.dtype)
Jeremy Johnson708da822023-11-15 16:25:45 +0000249 or (
250 not gtu.dtypeIsSupportedByCompliance(inputType)
251 and op["op"] in UNSUPPORTED_NON_FP32_INPUT_OPS
252 )
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100253 ):
254 # No compliance for error tests or unsupported types currently
Jeremy Johnson1271c442023-09-05 11:39:26 +0100255 return None
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +0100256
Jeremy Johnson1271c442023-09-05 11:39:26 +0100257 # Create compliance meta data for expected output tensor
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +0100258 compliance_tens = {
259 "mode": None,
260 # Data type is needed for all FP runs, as refmodel precise mode produces FP64
261 "data_type": gtu.DTYPE_ATTRIBUTES[outputTensor.dtype]["json"],
262 }
Jeremy Johnson1271c442023-09-05 11:39:26 +0100263 if argsDict["dg_type"] == gtu.DataGenType.DOT_PRODUCT:
264 mode = gtu.ComplianceMode.DOT_PRODUCT
265 compliance_tens["dot_product_info"] = {
266 "s": argsDict["s"],
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100267 "ks": int(argsDict["ksb"])
268 if "ksb" in argsDict
269 else int(argsDict["ks"]),
Jeremy Johnson1271c442023-09-05 11:39:26 +0100270 }
evacha019c96eef2024-02-07 11:21:55 +0000271 elif argsDict["dg_type"] == gtu.DataGenType.SPECIAL:
Jeremy Johnson1271c442023-09-05 11:39:26 +0100272 mode = gtu.ComplianceMode.FP_SPECIAL
273 elif "compliance" in op and "ulp" in op["compliance"]:
274 mode = gtu.ComplianceMode.ULP
275 compliance_tens["ulp_info"] = {"ulp": op["compliance"]["ulp"]}
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +0000276 elif "compliance" in op and "relative" in op["compliance"]:
277 mode = gtu.ComplianceMode.RELATIVE
278 compliance_tens["relative_info"] = {
279 "max": argsDict["max_abs_value"],
280 "scale": op["compliance"]["relative"],
281 }
Jeremy Johnson1271c442023-09-05 11:39:26 +0100282 elif op["op"] == Op.REDUCE_PRODUCT:
283 mode = gtu.ComplianceMode.REDUCE_PRODUCT
Jeremy Johnsonbd801962024-01-03 17:07:44 +0000284 compliance_tens["reduce_product_info"] = {"n": argsDict["n"]}
Jeremy Johnson534923d2023-12-04 11:11:06 +0000285 elif op["op"] in (Op.EXP, Op.POW, Op.TANH, Op.SIGMOID):
Jeremy Johnson9a758382023-11-07 16:27:35 +0000286 mode = gtu.ComplianceMode.ABS_ERROR
Jeremy Johnsond80ea5e2024-01-03 10:54:12 +0000287 if "compliance" in op and "abs_error_lower_bound" in op["compliance"]:
288 compliance_tens["abs_error_info"] = {
289 "lower_bound": op["compliance"]["abs_error_lower_bound"]
290 }
Jerry Ge51bd4f52024-02-20 11:21:19 -0800291 elif op["op"] in (Op.SIN, Op.COS):
292 mode = gtu.ComplianceMode.ABS_ERROR
293 if "compliance" in op and "abs_error_normal_divisor" in op["compliance"]:
294 compliance_tens["abs_error_info"] = {
295 "normal_divisor": op["compliance"]["abs_error_normal_divisor"]
296 }
Jeremy Johnson1271c442023-09-05 11:39:26 +0100297 else:
298 mode = gtu.ComplianceMode.EXACT
299 compliance_tens["mode"] = gtu.ComplianceMode(mode).name
300
301 return compliance_tens
302
303 # Build Op functions
304 # Create the output tensor (calling OutputShaper as needed)
305 # Do final tweaks to attributes (if necessary for errorIf)
306 # Add Op into graph
307 # Return resulting tensor information or BuildInfo
308
309 class BuildInfo:
310 """Enhanced build information containing result tensor and associated compliance dict."""
311
312 def __init__(self, resultTensor, complianceDict):
Jeremy Johnsonc8330812024-01-18 16:57:28 +0000313 if isinstance(resultTensor, list):
314 assert complianceDict is None or isinstance(complianceDict, list)
315 self.resultTensorList = resultTensor
316 self.complianceDictList = complianceDict
317 else:
318 self.resultTensorList = [resultTensor]
319 if complianceDict is None:
320 self.complianceDictList = None
321 else:
322 self.complianceDictList = [complianceDict]
323
324 def getComplianceInfo(self):
325 if self.complianceDictList is None:
326 return None
327 else:
328 tens_dict = {}
329 for tens, comp in zip(self.resultTensorList, self.complianceDictList):
330 if comp is not None:
331 tens_dict[tens.name] = comp
332
333 if tens_dict:
334 # Have some compliance data, so return the info
335 compliance = {
336 "version": "0.1",
337 "tensors": tens_dict,
338 }
339 else:
340 compliance = None
341 return compliance
Eric Kunzee5e26762020-10-13 16:11:07 -0700342
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000343 def build_unary(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100344 self,
345 rng,
346 op,
347 inputs,
348 args_dict,
349 validator_fcns=None,
350 error_name=None,
351 qinfo=None,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000352 ):
353 assert len(inputs) == 1
354 a = inputs[0]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100355 result_tensor = OutputShaper.unaryOp(self.ser, rng, a, error_name)
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100356
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000357 assert not isinstance(op, int)
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100358
359 # Ensure new output type has correct qinfo
360 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000361 if result_tensor.dtype not in [DType.INT8, DType.UINT8]:
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000362 qinfo = [
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100363 TosaQuantGen.getZeroPoint(rng, self.args.zeropoint, a.dtype),
364 TosaQuantGen.getZeroPoint(
365 rng, self.args.zeropoint, result_tensor.dtype
366 ),
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000367 ]
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100368
369 # Invalidate Input/Output list for error if checks.
370 input_list = [a.name]
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000371 output_list = [result_tensor.name]
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100372 pCount, cCount = op["operands"]
373 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000374 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100375 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000376 )
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100377
Les Bell729b0352021-11-24 10:28:21 +0000378 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100379 self.ser,
380 validator_fcns,
381 error_name,
382 op=op,
383 input_dtype=a.dtype,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000384 output_dtype=result_tensor.dtype,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000385 qinfo=qinfo,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000386 result_tensors=[result_tensor],
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100387 input_list=input_list,
388 output_list=output_list,
389 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000390 ):
391 return None
Matthew Haddone4ecdb22021-09-28 11:38:21 +0100392
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000393 attr = None
394 if op["op"] == Op.NEGATE:
395 attr = ts.TosaSerializerAttribute()
396 attr.NegateAttribute(qinfo[0], qinfo[1])
397
398 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000399
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +0000400 compliance = self.tensorComplianceMetaData(
401 op, a.dtype, args_dict, result_tensor, error_name
402 )
Jeremy Johnson2d70ac42023-11-06 17:46:02 +0000403 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700404
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +0000405 def build_binary_broadcast(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100406 self, rng, op, inputs, args_dict, validator_fcns, error_name=None, qinfo=None
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +0000407 ):
408 assert len(inputs) == 2
409 a, b = inputs
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100410 result_tensor = OutputShaper.binaryBroadcastOp(self.ser, rng, a, b, error_name)
Matthew Haddoneacff9a2021-09-24 14:42:13 +0100411
412 # Invalidate Input/Output list for error if checks.
413 input_list = [a.name, b.name]
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +0000414 output_list = [result_tensor.name]
Matthew Haddoneacff9a2021-09-24 14:42:13 +0100415 pCount, cCount = op["operands"]
416 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000417 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100418 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000419 )
Matthew Haddoneacff9a2021-09-24 14:42:13 +0100420
Les Bell729b0352021-11-24 10:28:21 +0000421 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddoneacff9a2021-09-24 14:42:13 +0100422 self.ser,
423 validator_fcns,
424 error_name,
425 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000426 input1=a,
427 input2=b,
428 input_dtype=a.dtype,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +0000429 output_dtype=result_tensor.dtype,
430 result_tensors=[result_tensor],
Matthew Haddoneacff9a2021-09-24 14:42:13 +0100431 input_list=input_list,
432 output_list=output_list,
433 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000434 ):
435 return None
Matthew Haddoneacff9a2021-09-24 14:42:13 +0100436
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000437 self.ser.addOperator(op["op"], input_list, output_list)
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +0000438
Jeremy Johnson9a758382023-11-07 16:27:35 +0000439 compliance = self.tensorComplianceMetaData(
440 op, a.dtype, args_dict, result_tensor, error_name
441 )
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +0000442
443 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700444
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000445 def build_arithmetic_right_shift(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100446 self,
447 rng,
448 op,
449 inputs,
450 args_dict,
451 validator_fcns=None,
452 error_name=None,
453 qinfo=None,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000454 ):
Jeremy Johnson587cc842024-02-08 11:45:44 +0000455 assert len(inputs) == 2
456 a, b = inputs
457 round = args_dict["round"]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100458 result_tensor = OutputShaper.binaryBroadcastOp(self.ser, rng, a, b, error_name)
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100459
460 # Invalidate Input/Output list for error if checks.
461 input_list = [a.name, b.name]
Jeremy Johnson587cc842024-02-08 11:45:44 +0000462 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100463 pCount, cCount = op["operands"]
464 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000465 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100466 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000467 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100468
Les Bell729b0352021-11-24 10:28:21 +0000469 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100470 self.ser,
471 validator_fcns,
472 error_name,
473 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000474 input1=a,
475 input2=b,
476 input_dtype=a.dtype,
Jeremy Johnson587cc842024-02-08 11:45:44 +0000477 output_dtype=result_tensor.dtype,
478 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100479 input_list=input_list,
480 output_list=output_list,
481 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000482 ):
483 return None
Kevin Chengaee1fac2020-11-11 13:54:06 -0800484
485 attr = ts.TosaSerializerAttribute()
486 attr.ArithmeticRightShiftAttribute(round)
487
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000488 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson587cc842024-02-08 11:45:44 +0000489
490 compliance = self.tensorComplianceMetaData(
491 op, a.dtype, args_dict, result_tensor, error_name
492 )
493
494 return TosaTestGen.BuildInfo(result_tensor, compliance)
Kevin Chengaee1fac2020-11-11 13:54:06 -0800495
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100496 def build_mul(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100497 self,
498 rng,
499 op,
500 inputs,
501 args_dict,
502 validator_fcns=None,
503 error_name=None,
504 qinfo=None,
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100505 ):
Jeremy Johnson0a042992024-02-28 13:20:05 +0000506 # Note that mul is binary operator but it has a shift value tensor
507 assert len(inputs) == 3
508 a, b, s = inputs
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100509
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100510 result_tensor = OutputShaper.binaryBroadcastOp(self.ser, rng, a, b, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -0700511
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100512 # Special for multiply: Force the result to INT32 for INT types
James Ward24dbc422022-10-19 12:20:31 +0100513 if a.dtype not in (DType.FP16, DType.BF16, DType.FP32):
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100514 result_tensor.setDtype(DType.INT32)
515
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100516 if error_name == ErrorIf.WrongOutputType:
517 all_dtypes = [DType.INT8, DType.INT16, DType.INT48]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100518 outputDType = rng.choice(all_dtypes)
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100519 result_tensor.setDtype(outputDType)
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100520
521 # Invalidate Input/Output list for error if checks.
Jeremy Johnson0a042992024-02-28 13:20:05 +0000522 input_list = [a.name, b.name, s.name]
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100523 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100524 pCount, cCount = op["operands"]
525 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000526 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100527 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000528 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100529
Les Bell729b0352021-11-24 10:28:21 +0000530 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100531 self.ser,
532 validator_fcns,
533 error_name,
534 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000535 input1=a,
536 input2=b,
537 input_dtype=a.dtype,
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100538 output_dtype=result_tensor.dtype,
539 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100540 input_list=input_list,
541 output_list=output_list,
542 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000543 ):
544 return None
Eric Kunzee5e26762020-10-13 16:11:07 -0700545
Jeremy Johnson0a042992024-02-28 13:20:05 +0000546 self.ser.addOperator(op["op"], input_list, output_list)
Jeremy Johnsona4d907e2023-10-26 13:53:14 +0100547
548 compliance = self.tensorComplianceMetaData(
549 op, a.dtype, args_dict, result_tensor, error_name
550 )
551
552 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700553
Jeremy Johnson587cc842024-02-08 11:45:44 +0000554 def build_table(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100555 self,
556 rng,
557 op,
558 inputs,
559 args_dict,
560 validator_fcns=None,
561 error_name=None,
562 qinfo=None,
Jeremy Johnson587cc842024-02-08 11:45:44 +0000563 ):
564 assert len(inputs) == 1
565 a = inputs[0]
566 table = args_dict["table"]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100567 result_tensor = OutputShaper.tableOp(self.ser, rng, a, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -0700568
Kevin Chengfe392ce2021-10-18 21:51:55 +0000569 attr = ts.TosaSerializerAttribute()
570 attr.TableAttribute(table)
571
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100572 # Invalidate Input/Output list for error if checks.
573 input_list = [a.name]
Jeremy Johnson587cc842024-02-08 11:45:44 +0000574 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100575 pCount, cCount = op["operands"]
576 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000577 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100578 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000579 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100580
Les Bell729b0352021-11-24 10:28:21 +0000581 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100582 self.ser,
583 validator_fcns,
584 error_name,
585 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000586 input_shape=a.shape,
587 input_dtype=a.dtype,
Jeremy Johnson587cc842024-02-08 11:45:44 +0000588 output_dtype=result_tensor.dtype,
589 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100590 input_list=input_list,
591 output_list=output_list,
592 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000593 ):
594 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100595
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000596 self.ser.addOperator(op["op"], input_list, output_list, attr)
Eric Kunzee5e26762020-10-13 16:11:07 -0700597
Jeremy Johnson587cc842024-02-08 11:45:44 +0000598 compliance = self.tensorComplianceMetaData(
599 op, a.dtype, args_dict, result_tensor, error_name
600 )
601
602 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700603
Jeremy Johnson7b9abce2024-01-10 11:07:29 +0000604 def build_select(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100605 self,
606 rng,
607 op,
608 inputs,
609 args_dict,
610 validator_fcns=None,
611 error_name=None,
612 qinfo=None,
Jeremy Johnson7b9abce2024-01-10 11:07:29 +0000613 ):
614 assert len(inputs) == 3
615 cond, a, b = inputs
616
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100617 result_tensor = OutputShaper.selectOp(self.ser, rng, cond, a, b, error_name)
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100618
619 # Invalidate Input/Output list for error if checks.
620 input_list = [cond.name, a.name, b.name]
Jeremy Johnson7b9abce2024-01-10 11:07:29 +0000621 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100622 pCount, cCount = op["operands"]
623 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000624 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100625 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000626 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100627
Les Bell729b0352021-11-24 10:28:21 +0000628 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100629 self.ser,
630 validator_fcns,
631 error_name,
632 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000633 input1=cond,
634 input2=a,
635 input3=b,
636 input_shape=a.shape,
637 input_dtype=a.dtype,
Jeremy Johnson7b9abce2024-01-10 11:07:29 +0000638 output_dtype=result_tensor.dtype,
639 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100640 input_list=input_list,
641 output_list=output_list,
642 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000643 ):
644 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100645
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000646 self.ser.addOperator(
647 op["op"],
648 input_list,
649 output_list,
650 )
Jeremy Johnson7b9abce2024-01-10 11:07:29 +0000651 compliance = self.tensorComplianceMetaData(
652 op, a.dtype, args_dict, result_tensor, error_name
653 )
654
655 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700656
Jeremy Johnsona0150012023-11-15 15:52:06 +0000657 def build_comparison(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100658 self,
659 rng,
660 op,
661 inputs,
662 args_dict,
663 validator_fcns=None,
664 error_name=None,
665 qinfo=None,
Jeremy Johnsona0150012023-11-15 15:52:06 +0000666 ):
667 assert len(inputs) == 2
668 a, b = inputs
669
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100670 result_tensor = OutputShaper.binaryComparisonOp(self.ser, rng, a, b, error_name)
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100671
672 # Invalidate Input/Output list for error if checks.
673 input_list = [a.name, b.name]
Jeremy Johnsona0150012023-11-15 15:52:06 +0000674 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100675 pCount, cCount = op["operands"]
676 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000677 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100678 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000679 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100680
Les Bell729b0352021-11-24 10:28:21 +0000681 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100682 self.ser,
683 validator_fcns,
684 error_name,
685 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000686 input1=a,
687 input2=b,
688 input_shape=a.shape,
689 input_dtype=a.dtype,
Jeremy Johnsona0150012023-11-15 15:52:06 +0000690 output_shape=result_tensor.shape,
691 output_dtype=result_tensor.dtype,
692 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100693 input_list=input_list,
694 output_list=output_list,
695 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000696 ):
697 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +0100698
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000699 self.ser.addOperator(
700 op["op"],
701 input_list,
702 output_list,
703 )
Jeremy Johnsona0150012023-11-15 15:52:06 +0000704
705 compliance = self.tensorComplianceMetaData(
706 op, a.dtype, args_dict, result_tensor, error_name
707 )
708 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700709
Jeremy Johnsonbfc53032023-11-01 11:29:56 +0000710 def build_argmax(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100711 self, rng, op, inputs, args_dict, validator_fcns, error_name, qinfo=None
Jeremy Johnsonbfc53032023-11-01 11:29:56 +0000712 ):
713 assert len(inputs) == 1
714 a = inputs[0]
715 axis = args_dict["axis"]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100716 result_tensor = OutputShaper.argmaxOp(self.ser, rng, a, axis, error_name)
Matthew Haddonc4cf0372021-10-11 09:38:10 +0100717
718 # Invalidate Input/Output list for error if checks.
719 input_list = [a.name]
Jeremy Johnsonbfc53032023-11-01 11:29:56 +0000720 output_list = [result_tensor.name]
Matthew Haddonc4cf0372021-10-11 09:38:10 +0100721 pCount, cCount = op["operands"]
722 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000723 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100724 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000725 )
Matthew Haddonc4cf0372021-10-11 09:38:10 +0100726
Les Bell729b0352021-11-24 10:28:21 +0000727 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonc4cf0372021-10-11 09:38:10 +0100728 self.ser,
729 validator_fcns,
730 error_name,
731 op=op,
732 axis=axis,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000733 input_shape=a.shape,
734 input_dtype=a.dtype,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +0000735 output_shape=result_tensor.shape,
736 output_dtype=result_tensor.dtype,
737 result_tensors=[result_tensor],
Matthew Haddonc4cf0372021-10-11 09:38:10 +0100738 input_list=input_list,
739 output_list=output_list,
740 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000741 ):
742 return None
Eric Kunzee5e26762020-10-13 16:11:07 -0700743
744 attr = ts.TosaSerializerAttribute()
745 attr.AxisAttribute(axis)
746
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000747 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnsonbfc53032023-11-01 11:29:56 +0000748
749 compliance = self.tensorComplianceMetaData(
750 op, inputs[0].dtype, args_dict, result_tensor, error_name
751 )
752 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700753
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000754 def build_pool2d(
755 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100756 rng,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000757 op,
Jeremy Johnsond41feb72023-10-12 16:03:15 +0100758 inputs,
759 args_dict,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000760 validator_fcns=None,
761 error_name=None,
762 qinfo=None,
763 ):
Jeremy Johnsond41feb72023-10-12 16:03:15 +0100764 assert len(inputs) == 1
765 input = inputs[0]
766 # max_pool has no accum_dtype
767 accum_dtype = (
768 args_dict["acc_type"] if "acc_type" in args_dict else DType.UNKNOWN
769 )
770 stride = args_dict["stride"]
771 pad = args_dict["pad"]
772 kernel = args_dict["kernel"]
773
Jeremy Johnson0601f802023-11-08 16:28:09 +0000774 result_tensor = OutputShaper.pool2dOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100775 self.ser, rng, input, kernel, stride, pad, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000776 )
Matthew Haddonb6b59e32021-10-07 17:19:20 +0100777
778 # Ensure new output type has correct qinfo
779 if error_name == ErrorIf.WrongInputType:
780 if input.dtype not in [DType.INT8, DType.UINT8]:
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000781 qinfo = [
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100782 TosaQuantGen.getZeroPoint(rng, self.args.zeropoint, input.dtype),
783 TosaQuantGen.getZeroPoint(
784 rng, self.args.zeropoint, result_tensor.dtype
785 ),
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000786 ]
Matthew Haddonb6b59e32021-10-07 17:19:20 +0100787
788 # Invalidate Input/Output list for error if checks.
789 input_list = [input.name]
Jeremy Johnson0601f802023-11-08 16:28:09 +0000790 output_list = [result_tensor.name]
Matthew Haddonb6b59e32021-10-07 17:19:20 +0100791 pCount, cCount = op["operands"]
792 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000793 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100794 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000795 )
Matthew Haddonb6b59e32021-10-07 17:19:20 +0100796
Les Bell729b0352021-11-24 10:28:21 +0000797 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonb6b59e32021-10-07 17:19:20 +0100798 self.ser,
799 validator_fcns,
800 error_name,
801 op=op,
802 input_shape=input.shape,
803 input_dtype=input.dtype,
Jeremy Johnson0601f802023-11-08 16:28:09 +0000804 output_shape=result_tensor.shape,
805 output_dtype=result_tensor.dtype,
Jeremy Johnson01e1c1c2024-02-07 16:09:09 +0000806 accum_dtype=accum_dtype,
Matthew Haddonb6b59e32021-10-07 17:19:20 +0100807 kernel=kernel,
808 stride=stride,
809 pad=pad,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000810 qinfo=qinfo,
Jeremy Johnson0601f802023-11-08 16:28:09 +0000811 result_tensors=[result_tensor],
Matthew Haddonb6b59e32021-10-07 17:19:20 +0100812 input_list=input_list,
813 output_list=output_list,
814 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +0000815 ):
816 return None
Eric Kunzee5e26762020-10-13 16:11:07 -0700817
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000818 if qinfo is None:
819 qinfo = [0, 0]
Eric Kunzee5e26762020-10-13 16:11:07 -0700820
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000821 attr = ts.TosaSerializerAttribute()
James Ward8b390432022-08-12 20:48:56 +0100822 attr.PoolAttribute(kernel, stride, pad, qinfo[0], qinfo[1], accum_dtype)
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000823
824 self.ser.addOperator(op["op"], input_list, output_list, attr)
Eric Kunzee5e26762020-10-13 16:11:07 -0700825
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100826 compliance = self.tensorComplianceMetaData(
827 op, inputs[0].dtype, args_dict, result_tensor, error_name
828 )
Jeremy Johnsond41feb72023-10-12 16:03:15 +0100829
830 return TosaTestGen.BuildInfo(result_tensor, compliance)
James Ward8b390432022-08-12 20:48:56 +0100831
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000832 def build_conv2d(
833 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100834 rng,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000835 op,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100836 inputs,
837 args_dict,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000838 validator_fcns=None,
839 error_name=None,
840 qinfo=None,
841 ):
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100842 assert len(inputs) == 3
843 ifm, filter, bias = inputs
844 accum_dtype = args_dict["acc_type"]
845 strides = args_dict["stride"]
846 padding = args_dict["pad"]
847 dilations = args_dict["dilation"]
848
Kevin Cheng550ccc52021-03-03 11:21:43 -0800849 assert len(padding) == 4
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100850 result_tensor = OutputShaper.conv2dOp(
James Ward8b390432022-08-12 20:48:56 +0100851 self.ser,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100852 rng,
James Ward8b390432022-08-12 20:48:56 +0100853 ifm,
854 filter,
855 accum_dtype,
856 strides,
857 padding,
858 dilations,
859 error_name,
Les Bell0e027d42021-11-09 14:42:14 +0000860 )
861
862 # Ensure new output type has correct qinfo
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000863 if error_name == ErrorIf.WrongInputType and ifm.dtype not in (
864 DType.INT8,
865 DType.UINT8,
866 ):
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000867 qinfo = [
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100868 TosaQuantGen.getZeroPoint(rng, self.args.zeropoint, ifm.dtype),
869 TosaQuantGen.getZeroPoint(
870 rng, self.args.zeropoint, result_tensor.dtype
871 ),
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000872 ]
Les Bell0e027d42021-11-09 14:42:14 +0000873
874 # Invalidate Input/Output list for error_if checks.
875 input_list = [ifm.name, filter.name, bias.name]
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100876 output_list = [result_tensor.name]
Les Bell0e027d42021-11-09 14:42:14 +0000877 num_operands = sum(op["operands"])
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000878 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100879 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000880 )
Les Bell0e027d42021-11-09 14:42:14 +0000881
Les Bell729b0352021-11-24 10:28:21 +0000882 if not TosaErrorValidator.evValidateErrorIfs(
Les Bell0e027d42021-11-09 14:42:14 +0000883 self.ser,
884 validator_fcns,
885 error_name,
886 op=op,
887 input_dtype=ifm.dtype,
888 weight_dtype=filter.dtype,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100889 output_dtype=result_tensor.dtype,
Les Bell0e027d42021-11-09 14:42:14 +0000890 qinfo=qinfo,
891 input_list=input_list,
892 num_operands=num_operands,
893 output_list=output_list,
894 pad=padding,
895 stride=strides,
896 dilation=dilations,
897 input_shape=ifm.shape,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +0100898 weight_shape=filter.shape,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100899 output_shape=result_tensor.shape,
Tai Lyf36f2562024-03-14 16:21:29 +0000900 accum_dtype=accum_dtype,
Les Bell729b0352021-11-24 10:28:21 +0000901 ):
902 return None
Eric Kunzee5e26762020-10-13 16:11:07 -0700903
Tai Lyd3797f02023-11-15 23:06:19 +0000904 # TODO - Test local_bound, for now set local bound attribute to False
905 local_bound = False
906
Eric Kunzee5e26762020-10-13 16:11:07 -0700907 attr = ts.TosaSerializerAttribute()
Tai Lyf36f2562024-03-14 16:21:29 +0000908 attr.ConvAttribute(
909 padding, strides, dilations, qinfo[0], qinfo[1], local_bound, accum_dtype
910 )
Eric Kunzee5e26762020-10-13 16:11:07 -0700911
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000912 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100913
914 compliance = self.tensorComplianceMetaData(
915 op, ifm.dtype, args_dict, result_tensor, error_name
916 )
917
918 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -0700919
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000920 def build_conv3d(
921 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100922 rng,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000923 op,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100924 inputs,
925 args_dict,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000926 validator_fcns=None,
927 error_name=None,
928 qinfo=None,
929 ):
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +0100930 assert len(inputs) == 3
931 ifm, filter, bias = inputs
932 accum_dtype = args_dict["acc_type"]
933 strides = args_dict["stride"]
934 padding = args_dict["pad"]
935 dilations = args_dict["dilation"]
936
Kevin Cheng1533b852021-09-01 12:51:58 -0700937 assert len(padding) == 6
evacha0147ab1762024-01-29 13:23:23 +0000938 result_tensor = OutputShaper.conv3dOp(
James Ward8b390432022-08-12 20:48:56 +0100939 self.ser,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100940 rng,
James Ward8b390432022-08-12 20:48:56 +0100941 ifm,
942 filter,
943 accum_dtype,
944 strides,
945 padding,
946 dilations,
947 error_name,
Les Bell0e027d42021-11-09 14:42:14 +0000948 )
949
950 # Ensure new output type has correct qinfo
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000951 if error_name == ErrorIf.WrongInputType and ifm.dtype not in (
952 DType.INT8,
953 DType.UINT8,
954 ):
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000955 qinfo = [
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100956 TosaQuantGen.getZeroPoint(rng, self.args.zeropoint, ifm.dtype),
957 TosaQuantGen.getZeroPoint(
958 rng, self.args.zeropoint, result_tensor.dtype
959 ),
Eric Kunzeb5fabec2022-06-07 05:20:44 +0000960 ]
Les Bell0e027d42021-11-09 14:42:14 +0000961
962 # Invalidate Input/Output list for error_if checks.
963 input_list = [ifm.name, filter.name, bias.name]
evacha0147ab1762024-01-29 13:23:23 +0000964 output_list = [result_tensor.name]
Les Bell0e027d42021-11-09 14:42:14 +0000965 num_operands = sum(op["operands"])
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000966 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +0100967 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +0000968 )
Les Bell0e027d42021-11-09 14:42:14 +0000969
Les Bell729b0352021-11-24 10:28:21 +0000970 if not TosaErrorValidator.evValidateErrorIfs(
Les Bell0e027d42021-11-09 14:42:14 +0000971 self.ser,
972 validator_fcns,
973 error_name,
974 op=op,
975 input_dtype=ifm.dtype,
976 weight_dtype=filter.dtype,
evacha0147ab1762024-01-29 13:23:23 +0000977 output_dtype=result_tensor.dtype,
Les Bell0e027d42021-11-09 14:42:14 +0000978 qinfo=qinfo,
979 input_list=input_list,
980 num_operands=num_operands,
981 output_list=output_list,
982 pad=padding,
983 stride=strides,
984 dilation=dilations,
985 input_shape=ifm.shape,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +0100986 weight_shape=filter.shape,
evacha0147ab1762024-01-29 13:23:23 +0000987 output_shape=result_tensor.shape,
Tai Lyf36f2562024-03-14 16:21:29 +0000988 accum_dtype=accum_dtype,
Les Bell729b0352021-11-24 10:28:21 +0000989 ):
990 return None
Kevin Cheng1533b852021-09-01 12:51:58 -0700991
Tai Lyd3797f02023-11-15 23:06:19 +0000992 # TODO - Test local_bound, for now set local bound attribute to False
993 local_bound = False
994
Kevin Cheng1533b852021-09-01 12:51:58 -0700995 attr = ts.TosaSerializerAttribute()
Tai Lyf36f2562024-03-14 16:21:29 +0000996 attr.ConvAttribute(
997 padding, strides, dilations, qinfo[0], qinfo[1], local_bound, accum_dtype
998 )
Kevin Cheng1533b852021-09-01 12:51:58 -0700999
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001000 self.ser.addOperator(op["op"], input_list, output_list, attr)
evacha0147ab1762024-01-29 13:23:23 +00001001
1002 compliance = self.tensorComplianceMetaData(
1003 op, ifm.dtype, args_dict, result_tensor, error_name
1004 )
1005
1006 return TosaTestGen.BuildInfo(result_tensor, compliance)
Kevin Cheng1533b852021-09-01 12:51:58 -07001007
Kevin Cheng550ccc52021-03-03 11:21:43 -08001008 def build_transpose_conv2d(
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001009 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001010 rng,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001011 op,
Jeremy Johnson95a67102024-01-10 14:16:39 +00001012 inputs,
1013 args_dict,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001014 validator_fcns=None,
1015 error_name=None,
1016 qinfo=None,
Kevin Cheng550ccc52021-03-03 11:21:43 -08001017 ):
Jeremy Johnson95a67102024-01-10 14:16:39 +00001018 assert len(inputs) == 3
1019 ifm, filter, bias = inputs
1020 accum_dtype = args_dict["acc_type"]
1021 strides = args_dict["stride"]
1022 out_pad = args_dict["pad"]
1023 output_shape = args_dict["out_shape"]
1024
TatWai Chong24594f52022-06-08 00:48:04 -07001025 assert len(out_pad) == 4
Jeremy Johnson95a67102024-01-10 14:16:39 +00001026 result_tensor = OutputShaper.transposeConv2DOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001027 self.ser, rng, ifm, output_shape, accum_dtype, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001028 )
Les Bell0e027d42021-11-09 14:42:14 +00001029
1030 # Ensure new output type has correct qinfo
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001031 if error_name == ErrorIf.WrongInputType and ifm.dtype not in (
1032 DType.INT8,
1033 DType.UINT8,
1034 ):
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001035 qinfo = [
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001036 TosaQuantGen.getZeroPoint(rng, self.args.zeropoint, ifm.dtype),
1037 TosaQuantGen.getZeroPoint(
1038 rng, self.args.zeropoint, result_tensor.dtype
1039 ),
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001040 ]
Les Bell0e027d42021-11-09 14:42:14 +00001041
1042 # Invalidate Input/Output list for error_if checks.
1043 input_list = [ifm.name, filter.name, bias.name]
Jeremy Johnson95a67102024-01-10 14:16:39 +00001044 output_list = [result_tensor.name]
Les Bell0e027d42021-11-09 14:42:14 +00001045 num_operands = sum(op["operands"])
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001046 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001047 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001048 )
Les Bell0e027d42021-11-09 14:42:14 +00001049
Les Bell729b0352021-11-24 10:28:21 +00001050 if not TosaErrorValidator.evValidateErrorIfs(
Les Bell0e027d42021-11-09 14:42:14 +00001051 self.ser,
1052 validator_fcns,
1053 error_name,
1054 op=op,
1055 input_dtype=ifm.dtype,
1056 weight_dtype=filter.dtype,
Jeremy Johnson95a67102024-01-10 14:16:39 +00001057 output_dtype=result_tensor.dtype,
Les Bell0e027d42021-11-09 14:42:14 +00001058 qinfo=qinfo,
1059 input_list=input_list,
1060 num_operands=num_operands,
1061 output_list=output_list,
TatWai Chong24594f52022-06-08 00:48:04 -07001062 pad=out_pad,
Jeremy Johnson95a67102024-01-10 14:16:39 +00001063 stride=strides,
Les Bell0e027d42021-11-09 14:42:14 +00001064 input_shape=ifm.shape,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01001065 weight_shape=filter.shape,
Jeremy Johnson95a67102024-01-10 14:16:39 +00001066 output_shape=result_tensor.shape,
Tai Lyf36f2562024-03-14 16:21:29 +00001067 accum_dtype=accum_dtype,
Les Bell729b0352021-11-24 10:28:21 +00001068 ):
1069 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001070
Tai Lyd3797f02023-11-15 23:06:19 +00001071 # TODO - Test local_bound, for now set local bound attribute to False
1072 local_bound = False
1073
Eric Kunzee5e26762020-10-13 16:11:07 -07001074 attr = ts.TosaSerializerAttribute()
Tai Lyd3797f02023-11-15 23:06:19 +00001075 attr.TransposeConvAttribute(
Tai Lyf36f2562024-03-14 16:21:29 +00001076 out_pad, strides, output_shape, qinfo[0], qinfo[1], local_bound, accum_dtype
Tai Lyd3797f02023-11-15 23:06:19 +00001077 )
Eric Kunzee5e26762020-10-13 16:11:07 -07001078
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001079 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson95a67102024-01-10 14:16:39 +00001080
1081 compliance = self.tensorComplianceMetaData(
1082 op, ifm.dtype, args_dict, result_tensor, error_name
1083 )
1084
1085 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001086
Kevin Cheng550ccc52021-03-03 11:21:43 -08001087 def build_depthwise_conv2d(
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001088 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001089 rng,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001090 op,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +01001091 inputs,
1092 args_dict,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001093 validator_fcns=None,
1094 error_name=None,
1095 qinfo=None,
Kevin Cheng550ccc52021-03-03 11:21:43 -08001096 ):
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +01001097 assert len(inputs) == 3
1098 ifm, filter, bias = inputs
1099 accum_dtype = args_dict["acc_type"]
1100 strides = args_dict["stride"]
1101 padding = args_dict["pad"]
1102 dilations = args_dict["dilation"]
1103
Jeremy Johnson4f931302024-01-04 17:05:24 +00001104 result_tensor = OutputShaper.depthwiseConv2dOp(
James Ward8b390432022-08-12 20:48:56 +01001105 self.ser,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001106 rng,
James Ward8b390432022-08-12 20:48:56 +01001107 ifm,
1108 filter,
1109 accum_dtype,
1110 strides,
1111 padding,
1112 dilations,
1113 error_name,
Les Bell0e027d42021-11-09 14:42:14 +00001114 )
1115
1116 # Ensure new output type has correct qinfo
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001117 if error_name == ErrorIf.WrongInputType and ifm.dtype not in (
1118 DType.INT8,
1119 DType.UINT8,
1120 ):
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001121 qinfo = [
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001122 TosaQuantGen.getZeroPoint(rng, self.args.zeropoint, ifm.dtype),
1123 TosaQuantGen.getZeroPoint(
1124 rng, self.args.zeropoint, result_tensor.dtype
1125 ),
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001126 ]
Les Bell0e027d42021-11-09 14:42:14 +00001127
1128 # Invalidate Input/Output list for error_if checks.
1129 input_list = [ifm.name, filter.name, bias.name]
Jeremy Johnson4f931302024-01-04 17:05:24 +00001130 output_list = [result_tensor.name]
Les Bell0e027d42021-11-09 14:42:14 +00001131 num_operands = sum(op["operands"])
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001132 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001133 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001134 )
Les Bell0e027d42021-11-09 14:42:14 +00001135
Les Bell729b0352021-11-24 10:28:21 +00001136 if not TosaErrorValidator.evValidateErrorIfs(
Les Bell0e027d42021-11-09 14:42:14 +00001137 self.ser,
1138 validator_fcns,
1139 error_name,
1140 op=op,
1141 input_dtype=ifm.dtype,
1142 weight_dtype=filter.dtype,
Jeremy Johnson4f931302024-01-04 17:05:24 +00001143 output_dtype=result_tensor.dtype,
Les Bell0e027d42021-11-09 14:42:14 +00001144 qinfo=qinfo,
1145 input_list=input_list,
1146 num_operands=num_operands,
1147 output_list=output_list,
1148 pad=padding,
1149 stride=strides,
1150 dilation=dilations,
1151 input_shape=ifm.shape,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01001152 weight_shape=filter.shape,
Jeremy Johnson4f931302024-01-04 17:05:24 +00001153 output_shape=result_tensor.shape,
Tai Lyf36f2562024-03-14 16:21:29 +00001154 accum_dtype=accum_dtype,
Les Bell729b0352021-11-24 10:28:21 +00001155 ):
1156 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001157
Tai Lyd3797f02023-11-15 23:06:19 +00001158 # TODO - Test local_bound, for now set local bound attribute to False
1159 local_bound = False
1160
Eric Kunzee5e26762020-10-13 16:11:07 -07001161 attr = ts.TosaSerializerAttribute()
Tai Lyf36f2562024-03-14 16:21:29 +00001162 attr.ConvAttribute(
1163 padding, strides, dilations, qinfo[0], qinfo[1], local_bound, accum_dtype
1164 )
Eric Kunzee5e26762020-10-13 16:11:07 -07001165
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001166 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson4f931302024-01-04 17:05:24 +00001167
1168 compliance = self.tensorComplianceMetaData(
1169 op, ifm.dtype, args_dict, result_tensor, error_name
1170 )
1171
1172 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001173
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001174 def build_fully_connected(
James Ward8b390432022-08-12 20:48:56 +01001175 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001176 rng,
James Ward8b390432022-08-12 20:48:56 +01001177 op,
Jeremy Johnsonaee62af2023-11-02 17:16:25 +00001178 inputs,
1179 args_dict,
James Ward8b390432022-08-12 20:48:56 +01001180 validator_fcns=None,
1181 error_name=None,
1182 qinfo=None,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001183 ):
Jeremy Johnsonaee62af2023-11-02 17:16:25 +00001184 assert len(inputs) == 3
1185 ifm, filter, bias = inputs
1186 accum_dtype = args_dict["acc_type"]
1187
1188 result_tensor = OutputShaper.fullyConnectedOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001189 self.ser, rng, ifm, filter, accum_dtype, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001190 )
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001191
1192 # Invalidate Input/Output list for error if checks.
1193 input_list = [ifm.name, filter.name, bias.name]
Jeremy Johnsonaee62af2023-11-02 17:16:25 +00001194 output_list = [result_tensor.name]
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001195 pCount, cCount = op["operands"]
1196 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001197 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001198 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001199 )
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001200
Les Bell729b0352021-11-24 10:28:21 +00001201 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001202 self.ser,
1203 validator_fcns,
1204 error_name,
1205 op=op,
1206 input_shape=ifm.shape,
1207 input_dtype=ifm.dtype,
1208 weight_dtype=filter.dtype,
Jeremy Johnsonaee62af2023-11-02 17:16:25 +00001209 output_shape=result_tensor.shape,
1210 output_dtype=result_tensor.dtype,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001211 qinfo=qinfo,
Jeremy Johnsonaee62af2023-11-02 17:16:25 +00001212 result_tensors=[result_tensor],
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001213 input_list=input_list,
1214 output_list=output_list,
1215 num_operands=num_operands,
James Ward8b390432022-08-12 20:48:56 +01001216 accum_dtype=accum_dtype,
Les Bell729b0352021-11-24 10:28:21 +00001217 ):
1218 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001219
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001220 attr = ts.TosaSerializerAttribute()
James Wardd34b3fc2023-01-18 14:51:25 +00001221 attr.FullyConnectedAttribute(qinfo[0], qinfo[1])
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001222
1223 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnsonaee62af2023-11-02 17:16:25 +00001224
1225 compliance = self.tensorComplianceMetaData(
1226 op, ifm.dtype, args_dict, result_tensor, error_name
1227 )
1228
1229 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001230
James Ward8b390432022-08-12 20:48:56 +01001231 def build_matmul(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001232 self,
1233 rng,
1234 op,
1235 inputs,
1236 args_dict,
1237 validator_fcns=None,
1238 error_name=None,
1239 qinfo=None,
James Ward8b390432022-08-12 20:48:56 +01001240 ):
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001241 assert len(inputs) == 2
1242 a, b = inputs
Jeremy Johnson1271c442023-09-05 11:39:26 +01001243 accum_dtype = args_dict["acc_type"]
1244 result_tensor = OutputShaper.matmulOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001245 self.ser, rng, a, b, accum_dtype, error_name
James Ward8b390432022-08-12 20:48:56 +01001246 )
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001247
1248 # Invalidate Input/Output list for error if checks.
1249 input_list = [a.name, b.name]
Jeremy Johnson1271c442023-09-05 11:39:26 +01001250 output_list = [result_tensor.name]
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001251 pCount, cCount = op["operands"]
1252 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001253 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001254 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001255 )
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001256
Les Bell729b0352021-11-24 10:28:21 +00001257 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001258 self.ser,
1259 validator_fcns,
1260 error_name,
1261 op=op,
1262 input_shape=a.shape,
1263 input_dtype=a.dtype,
1264 input2_shape=b.shape,
1265 input2_dtype=b.dtype,
Jeremy Johnson1271c442023-09-05 11:39:26 +01001266 output_shape=result_tensor.shape,
1267 output_dtype=result_tensor.dtype,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001268 qinfo=qinfo,
Jeremy Johnson1271c442023-09-05 11:39:26 +01001269 result_tensors=[result_tensor],
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001270 input_list=input_list,
1271 output_list=output_list,
1272 num_operands=num_operands,
James Ward8b390432022-08-12 20:48:56 +01001273 accum_dtype=accum_dtype,
Les Bell729b0352021-11-24 10:28:21 +00001274 ):
1275 return None
Matthew Haddonc4cf0372021-10-11 09:38:10 +01001276
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001277 attr = ts.TosaSerializerAttribute()
James Wardd34b3fc2023-01-18 14:51:25 +00001278 attr.MatMulAttribute(qinfo[0], qinfo[1])
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001279
1280 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson1271c442023-09-05 11:39:26 +01001281
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +01001282 compliance = self.tensorComplianceMetaData(
1283 op, a.dtype, args_dict, result_tensor, error_name
1284 )
Jeremy Johnson1271c442023-09-05 11:39:26 +01001285
1286 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001287
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001288 def build_reduce(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001289 self, rng, op, inputs, args_dict, validator_fcns, error_name=None, qinfo=None
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001290 ):
1291 assert len(inputs) == 1
1292 a = inputs[0]
1293 axis = args_dict["axis"]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001294 result_tensor = OutputShaper.reduceOp(self.ser, rng, a, axis, error_name)
Matthew Haddond6ce7252021-09-29 15:35:44 +01001295
1296 # Invalidate Input/Output list for error if checks.
1297 input_list = [a.name]
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001298 output_list = [result_tensor.name]
Matthew Haddond6ce7252021-09-29 15:35:44 +01001299 pCount, cCount = op["operands"]
1300 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001301 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001302 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001303 )
Matthew Haddond6ce7252021-09-29 15:35:44 +01001304
Les Bell729b0352021-11-24 10:28:21 +00001305 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddond6ce7252021-09-29 15:35:44 +01001306 self.ser,
1307 validator_fcns,
1308 error_name,
1309 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001310 axis=axis,
1311 input_shape=a.shape,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001312 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001313 input_dtype=a.dtype,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001314 output_dtype=result_tensor.dtype,
1315 result_tensors=[result_tensor],
Matthew Haddond6ce7252021-09-29 15:35:44 +01001316 input_list=input_list,
1317 output_list=output_list,
1318 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001319 ):
1320 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001321
1322 attr = ts.TosaSerializerAttribute()
1323 attr.AxisAttribute(axis)
1324
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001325 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001326
Jeremy Johnsonbd801962024-01-03 17:07:44 +00001327 if error_name is None and op["op"] == Op.REDUCE_PRODUCT:
1328 # Number of products - needed for compliance
1329 args_dict["n"] = a.shape[axis]
1330
1331 compliance = self.tensorComplianceMetaData(
1332 op, a.dtype, args_dict, result_tensor, error_name
1333 )
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001334
1335 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001336
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001337 def build_clamp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001338 self,
1339 rng,
1340 op,
1341 inputs,
1342 args_dict,
1343 validator_fcns=None,
1344 error_name=None,
1345 qinfo=None,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001346 ):
1347 assert len(inputs) == 1
1348 a = inputs[0]
1349
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001350 result_tensor = OutputShaper.unaryOp(self.ser, rng, a, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -07001351
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001352 v = [rng.randNumberDType(a.dtype), rng.randNumberDType(a.dtype)]
Eric Kunzee5e26762020-10-13 16:11:07 -07001353
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001354 if error_name == ErrorIf.MaxSmallerMin:
1355 # Make sure the numbers are different to invoke this error
1356 while v[0] == v[1]:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001357 v = [rng.randNumberDType(a.dtype), rng.randNumberDType(a.dtype)]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001358 max_val = min(v)
1359 min_val = max(v)
Eric Kunzee5e26762020-10-13 16:11:07 -07001360 else:
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001361 max_val = max(v)
1362 min_val = min(v)
Eric Kunzee5e26762020-10-13 16:11:07 -07001363
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001364 # Invalidate Input/Output list for error if checks.
1365 input_list = [a.name]
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001366 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001367 pCount, cCount = op["operands"]
1368 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001369 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001370 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001371 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001372
Les Bell729b0352021-11-24 10:28:21 +00001373 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001374 self.ser,
1375 validator_fcns,
1376 error_name,
1377 op=op,
1378 max_val=max_val,
1379 min_val=min_val,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001380 input_shape=a.shape,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001381 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001382 input_dtype=a.dtype,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001383 output_dtype=result_tensor.dtype,
1384 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001385 input_list=input_list,
1386 output_list=output_list,
1387 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001388 ):
1389 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001390
1391 attr = ts.TosaSerializerAttribute()
Tai Ly5d0e9c72024-04-05 01:19:31 +00001392 min_val_as_bytes = ts.TosaSerializer.convertDataToUint8Vec(a.dtype, [min_val])
1393 max_val_as_bytes = ts.TosaSerializer.convertDataToUint8Vec(a.dtype, [max_val])
1394
1395 # align to 8 bytes
1396 while (len(min_val_as_bytes) % 8) != 0:
1397 min_val_as_bytes.append(0)
1398 while (len(max_val_as_bytes) % 8) != 0:
1399 max_val_as_bytes.append(0)
Tai Ly60dc48c2024-03-08 22:19:41 +00001400
1401 attr.ClampAttribute(self.ser.builder, min_val_as_bytes, max_val_as_bytes)
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001402
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001403 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001404
1405 compliance = self.tensorComplianceMetaData(
1406 op, a.dtype, args_dict, result_tensor, error_name
1407 )
1408
1409 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001410
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001411 def build_activation(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001412 self,
1413 rng,
1414 op,
1415 inputs,
1416 args_dict,
1417 validator_fcns=None,
1418 error_name=None,
1419 qinfo=None,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001420 ):
1421 assert len(inputs) == 1
1422 a = inputs[0]
1423
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001424 result_tensor = OutputShaper.unaryOp(self.ser, rng, a, error_name)
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001425
1426 # Invalidate Input/Output list for error if checks.
1427 input_list = [a.name]
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001428 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001429 pCount, cCount = op["operands"]
1430 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001431 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001432 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001433 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001434
Les Bell729b0352021-11-24 10:28:21 +00001435 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001436 self.ser,
1437 validator_fcns,
1438 error_name,
1439 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001440 input_shape=a.shape,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001441 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001442 input_dtype=a.dtype,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001443 output_dtype=result_tensor.dtype,
1444 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001445 input_list=input_list,
1446 output_list=output_list,
1447 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001448 ):
1449 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001450
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001451 self.ser.addOperator(op["op"], input_list, output_list)
Eric Kunzee5e26762020-10-13 16:11:07 -07001452
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001453 compliance = self.tensorComplianceMetaData(
1454 op, a.dtype, args_dict, result_tensor, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001455 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001456
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00001457 return TosaTestGen.BuildInfo(result_tensor, compliance)
Won Jeon78155c62023-06-10 00:20:04 +00001458
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001459 def build_concat(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001460 self,
1461 rng,
1462 op,
1463 inputs,
1464 args_dict,
1465 validator_fcns=None,
1466 error_name=None,
1467 qinfo=None,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001468 ):
Won Jeon74342e52024-01-09 00:34:40 +00001469 if op["op"] == Op.CONCAT_SHAPE:
1470 axis = 0
1471 else:
1472 axis = args_dict["axis"]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001473 if error_name != ErrorIf.WrongInputType:
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001474 assert type(axis) == int
Matthew Haddon818ab902021-07-27 09:12:49 +01001475
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001476 result_tensor = OutputShaper.concatOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001477 self.ser, rng, axis, inputs, error_name=error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001478 )
Eric Kunzee5e26762020-10-13 16:11:07 -07001479
Matthew Haddon818ab902021-07-27 09:12:49 +01001480 input_tensor_names = []
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001481 for tensor in inputs:
Matthew Haddon818ab902021-07-27 09:12:49 +01001482 input_tensor_names.append(tensor.name)
1483
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001484 # Invalidate Input/Output list for error if checks.
1485 input_list = input_tensor_names
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001486 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001487 pCount, cCount = op["operands"]
1488 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001489 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001490 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001491 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001492
Les Bell729b0352021-11-24 10:28:21 +00001493 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001494 self.ser,
1495 validator_fcns,
1496 error_name,
1497 op=op,
1498 axis=axis,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001499 input_shape=inputs[0].shape,
1500 output_shape=result_tensor.shape,
1501 input_dtype=inputs[0].dtype,
1502 output_dtype=result_tensor.dtype,
1503 inputs=inputs,
1504 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001505 input_list=input_list,
1506 output_list=output_list,
1507 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001508 ):
1509 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001510
Won Jeon74342e52024-01-09 00:34:40 +00001511 if op["op"] == Op.CONCAT:
1512 attr = ts.TosaSerializerAttribute()
1513 attr.AxisAttribute(axis)
1514 else:
1515 assert op["op"] == Op.CONCAT_SHAPE
1516 attr = None
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001517 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson3eafe662024-01-10 13:13:35 +00001518
1519 compliance = self.tensorComplianceMetaData(
1520 op, inputs[0].dtype, args_dict, result_tensor, error_name
1521 )
1522
1523 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001524
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001525 def build_pad(
1526 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001527 rng,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001528 op,
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001529 inputs,
1530 args_dict,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001531 validator_fcns=None,
1532 error_name=None,
1533 qinfo=None,
1534 ):
Tai Lye095da72024-01-25 22:00:18 +00001535 assert len(inputs) == 2
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001536 a = inputs[0]
Tai Lye095da72024-01-25 22:00:18 +00001537 pad_input = inputs[1]
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001538 padding = args_dict["pad"]
1539 pad_const_int = args_dict["pad_const_int"]
1540 pad_const_float = args_dict["pad_const_fp"]
1541
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001542 result_tensor = OutputShaper.padOp(self.ser, rng, a, padding, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -07001543
Tai Ly60dc48c2024-03-08 22:19:41 +00001544 # get pad_const_val_as_bytes from either pad_const_float or pad_const_int
1545 if gtu.dtypeIsFloat(a.dtype):
Tai Ly5d0e9c72024-04-05 01:19:31 +00001546 pad_const_val_as_bytes = ts.TosaSerializer.convertDataToUint8Vec(
1547 a.dtype, [pad_const_float]
1548 )
Tai Ly60dc48c2024-03-08 22:19:41 +00001549 else:
Tai Ly5d0e9c72024-04-05 01:19:31 +00001550 pad_const_val_as_bytes = ts.TosaSerializer.convertDataToUint8Vec(
1551 a.dtype, [pad_const_int]
1552 )
1553
1554 # align to 8 bytes
1555 while (len(pad_const_val_as_bytes) % 8) != 0:
1556 pad_const_val_as_bytes.append(0)
Tai Ly60dc48c2024-03-08 22:19:41 +00001557
Kevin Chengfe392ce2021-10-18 21:51:55 +00001558 attr = ts.TosaSerializerAttribute()
Tai Ly60dc48c2024-03-08 22:19:41 +00001559 attr.PadAttribute(self.ser.builder, pad_const_val_as_bytes)
Eric Kunzee5e26762020-10-13 16:11:07 -07001560
Matthew Haddone807aae2021-10-11 18:12:58 +01001561 # Invalidate Input/Output list for error if checks.
Tai Lye095da72024-01-25 22:00:18 +00001562 input_list = [a.name, pad_input.name]
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001563 output_list = [result_tensor.name]
Matthew Haddone807aae2021-10-11 18:12:58 +01001564 pCount, cCount = op["operands"]
1565 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001566 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001567 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001568 )
Matthew Haddone807aae2021-10-11 18:12:58 +01001569
Les Bell729b0352021-11-24 10:28:21 +00001570 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddone807aae2021-10-11 18:12:58 +01001571 self.ser,
1572 validator_fcns,
1573 error_name,
1574 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001575 input_shape=a.shape,
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001576 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001577 input_dtype=a.dtype,
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001578 output_dtype=result_tensor.dtype,
Matthew Haddone807aae2021-10-11 18:12:58 +01001579 pad=padding,
1580 qinfo=qinfo,
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001581 result_tensors=[result_tensor],
Matthew Haddone807aae2021-10-11 18:12:58 +01001582 input_list=input_list,
1583 output_list=output_list,
1584 num_operands=num_operands,
Luke Huttona4e48ca2023-02-22 11:53:48 +00001585 input1=a,
Les Bell729b0352021-11-24 10:28:21 +00001586 ):
1587 return None
Matthew Haddone807aae2021-10-11 18:12:58 +01001588
Eric Kunzeb5fabec2022-06-07 05:20:44 +00001589 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001590
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +01001591 compliance = self.tensorComplianceMetaData(
1592 op, a.dtype, args_dict, result_tensor, error_name
1593 )
Jeremy Johnsond41feb72023-10-12 16:03:15 +01001594
1595 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001596
Won Jeona21b2e82023-08-10 10:33:01 +00001597 def build_dim(
1598 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001599 rng,
Won Jeona21b2e82023-08-10 10:33:01 +00001600 op,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001601 inputs,
1602 args_dict,
Won Jeona21b2e82023-08-10 10:33:01 +00001603 validator_fcns=None,
1604 error_name=None,
1605 qinfo=None,
1606 ):
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001607 assert len(inputs) == 1
1608 a = inputs[0]
1609 axis = args_dict["axis"]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001610 result_tensor = OutputShaper.dimOp(self.ser, rng, a, axis, error_name)
Won Jeona21b2e82023-08-10 10:33:01 +00001611
1612 # Invalidate Input/Output list for error if checks.
1613 input_list = [a.name]
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001614 output_list = [result_tensor.name]
Won Jeona21b2e82023-08-10 10:33:01 +00001615 pCount, cCount = op["operands"]
1616 num_operands = pCount + cCount
1617 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001618 rng, error_name, input_list, output_list
Won Jeona21b2e82023-08-10 10:33:01 +00001619 )
1620
1621 if not TosaErrorValidator.evValidateErrorIfs(
1622 self.ser,
1623 validator_fcns,
1624 error_name,
1625 op=op,
1626 axis=axis,
1627 input_shape=a.shape,
1628 input_dtype=a.dtype,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001629 output_shape=result_tensor.shape,
1630 output_dtype=result_tensor.dtype,
1631 result_tensors=[result_tensor],
Won Jeona21b2e82023-08-10 10:33:01 +00001632 input_list=input_list,
1633 output_list=output_list,
1634 num_operands=num_operands,
1635 ):
1636 return None
1637
1638 attr = ts.TosaSerializerAttribute()
1639 attr.AxisAttribute(axis)
1640
1641 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001642 return TosaTestGen.BuildInfo(result_tensor, None)
Won Jeona21b2e82023-08-10 10:33:01 +00001643
Jeremy Johnsonfe79acc2023-11-29 15:57:58 +00001644 def build_reshape(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001645 self,
1646 rng,
1647 op,
1648 inputs,
1649 args_dict,
1650 validator_fcns=None,
1651 error_name=None,
1652 qinfo=None,
Jeremy Johnsonfe79acc2023-11-29 15:57:58 +00001653 ):
Tai Ly8690a082023-12-18 20:40:24 +00001654 assert len(inputs) == 2
Jeremy Johnsonfe79acc2023-11-29 15:57:58 +00001655 a = inputs[0]
Won Jeon64e4bfe2024-01-18 06:31:55 +00001656 shape = inputs[1]
1657 shape_attr = args_dict["new_shape"]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001658 result_tensor = OutputShaper.reshapeOp(self.ser, rng, a, shape_attr, error_name)
Matthew Haddone807aae2021-10-11 18:12:58 +01001659
1660 # Invalidate Input/Output list for error if checks.
Won Jeon64e4bfe2024-01-18 06:31:55 +00001661 input_list = [a.name, shape.name]
Jeremy Johnsonfe79acc2023-11-29 15:57:58 +00001662 output_list = [result_tensor.name]
Matthew Haddone807aae2021-10-11 18:12:58 +01001663 pCount, cCount = op["operands"]
1664 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001665 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001666 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001667 )
Matthew Haddone807aae2021-10-11 18:12:58 +01001668
Les Bell729b0352021-11-24 10:28:21 +00001669 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddone807aae2021-10-11 18:12:58 +01001670 self.ser,
1671 validator_fcns,
1672 error_name,
1673 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001674 input_shape=a.shape,
Jeremy Johnsonfe79acc2023-11-29 15:57:58 +00001675 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001676 input_dtype=a.dtype,
Jeremy Johnsonfe79acc2023-11-29 15:57:58 +00001677 output_dtype=result_tensor.dtype,
1678 result_tensors=[result_tensor],
Matthew Haddone807aae2021-10-11 18:12:58 +01001679 input_list=input_list,
1680 output_list=output_list,
1681 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001682 ):
1683 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001684
Tai Ly8690a082023-12-18 20:40:24 +00001685 self.ser.addOperator(op["op"], input_list, output_list)
Jeremy Johnsonfe79acc2023-11-29 15:57:58 +00001686
1687 compliance = self.tensorComplianceMetaData(
1688 op, a.dtype, args_dict, result_tensor, error_name
1689 )
1690
1691 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001692
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001693 def build_reverse(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001694 self,
1695 rng,
1696 op,
1697 inputs,
1698 args_dict,
1699 validator_fcns=None,
1700 error_name=None,
1701 qinfo=None,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001702 ):
1703 assert len(inputs) == 1
1704 a = inputs[0]
1705 axis = args_dict["axis"]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001706 result_tensor = OutputShaper.unaryOp(self.ser, rng, a, error_name)
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001707
1708 # Invalidate Input/Output list for error if checks.
1709 input_list = [a.name]
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001710 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001711 pCount, cCount = op["operands"]
1712 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001713 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001714 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001715 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001716
Les Bell729b0352021-11-24 10:28:21 +00001717 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001718 self.ser,
1719 validator_fcns,
1720 error_name,
1721 op=op,
1722 axis=axis,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001723 input_shape=a.shape,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001724 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001725 input_dtype=a.dtype,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001726 output_dtype=result_tensor.dtype,
1727 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001728 input_list=input_list,
1729 output_list=output_list,
1730 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001731 ):
1732 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001733
1734 attr = ts.TosaSerializerAttribute()
1735 attr.AxisAttribute(axis)
1736
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001737 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00001738 return TosaTestGen.BuildInfo(result_tensor, None)
Eric Kunzee5e26762020-10-13 16:11:07 -07001739
evacha0198477222024-01-26 12:25:32 +00001740 def build_transpose(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001741 self,
1742 rng,
1743 op,
1744 inputs,
1745 args_dict,
1746 validator_fcns=None,
1747 error_name=None,
1748 qinfo=None,
evacha0198477222024-01-26 12:25:32 +00001749 ):
1750 assert len(inputs) == 1
1751 a = inputs[0]
1752 perms = args_dict["perms"]
1753
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001754 result_tensor = OutputShaper.transposeOp(self.ser, rng, a, perms, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -07001755
Kevin Chengfe392ce2021-10-18 21:51:55 +00001756 attr = ts.TosaSerializerAttribute()
1757 attr.TransposeAttribute(perms)
Eric Kunzee5e26762020-10-13 16:11:07 -07001758
Matthew Haddone807aae2021-10-11 18:12:58 +01001759 # Invalidate Input/Output list for error if checks.
Kevin Chengfe392ce2021-10-18 21:51:55 +00001760 input_list = [a.name]
evacha0198477222024-01-26 12:25:32 +00001761 output_list = [result_tensor.name]
Matthew Haddone807aae2021-10-11 18:12:58 +01001762 pCount, cCount = op["operands"]
1763 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001764 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001765 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001766 )
Matthew Haddone807aae2021-10-11 18:12:58 +01001767
Les Bell729b0352021-11-24 10:28:21 +00001768 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddone807aae2021-10-11 18:12:58 +01001769 self.ser,
1770 validator_fcns,
1771 error_name,
1772 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001773 input_shape=a.shape,
evacha0198477222024-01-26 12:25:32 +00001774 output_shape=result_tensor.shape,
Matthew Haddone807aae2021-10-11 18:12:58 +01001775 perms=perms,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001776 input_dtype=a.dtype,
evacha0198477222024-01-26 12:25:32 +00001777 output_dtype=result_tensor.dtype,
1778 result_tensors=[result_tensor],
Matthew Haddone807aae2021-10-11 18:12:58 +01001779 input_list=input_list,
1780 output_list=output_list,
1781 num_operands=num_operands,
Luke Huttona4e48ca2023-02-22 11:53:48 +00001782 input1=a,
Les Bell729b0352021-11-24 10:28:21 +00001783 ):
1784 return None
Matthew Haddone807aae2021-10-11 18:12:58 +01001785
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001786 self.ser.addOperator(op["op"], input_list, output_list, attr)
evacha0198477222024-01-26 12:25:32 +00001787
1788 compliance = self.tensorComplianceMetaData(
1789 op, a.dtype, args_dict, result_tensor, error_name
1790 )
1791
1792 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001793
evacha017f7d4252024-01-24 12:08:09 +00001794 def build_slice(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001795 self,
1796 rng,
1797 op,
1798 inputs,
1799 args_dict,
1800 validator_fcns=None,
1801 error_name=None,
1802 qinfo=None,
evacha017f7d4252024-01-24 12:08:09 +00001803 ):
TatWai Chongf15bad82024-01-31 21:33:27 -08001804 assert len(inputs) == 3
1805 a, start_var, size_var = inputs
1806 start_const = args_dict["start"]
1807 size_const = args_dict["size"]
evacha017f7d4252024-01-24 12:08:09 +00001808
1809 result_tensor = OutputShaper.sliceOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001810 self.ser, rng, a, start_const, size_const, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001811 )
Matthew Haddone807aae2021-10-11 18:12:58 +01001812
1813 # Invalidate Input/Output list for error if checks.
TatWai Chongf15bad82024-01-31 21:33:27 -08001814 input_list = [a.name, start_var.name, size_var.name]
evacha017f7d4252024-01-24 12:08:09 +00001815 output_list = [result_tensor.name]
Matthew Haddone807aae2021-10-11 18:12:58 +01001816 pCount, cCount = op["operands"]
1817 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001818 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001819 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001820 )
Matthew Haddone807aae2021-10-11 18:12:58 +01001821
Les Bell729b0352021-11-24 10:28:21 +00001822 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddone807aae2021-10-11 18:12:58 +01001823 self.ser,
1824 validator_fcns,
1825 error_name,
1826 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001827 input_shape=a.shape,
evacha017f7d4252024-01-24 12:08:09 +00001828 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001829 input_dtype=a.dtype,
evacha017f7d4252024-01-24 12:08:09 +00001830 output_dtype=result_tensor.dtype,
TatWai Chongf15bad82024-01-31 21:33:27 -08001831 start=start_const,
1832 size=size_const,
evacha017f7d4252024-01-24 12:08:09 +00001833 result_tensors=[result_tensor],
Matthew Haddone807aae2021-10-11 18:12:58 +01001834 input_list=input_list,
1835 output_list=output_list,
1836 num_operands=num_operands,
Luke Huttona4e48ca2023-02-22 11:53:48 +00001837 input1=a,
Les Bell729b0352021-11-24 10:28:21 +00001838 ):
1839 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001840
Tai Ly8ead6c42024-02-14 22:35:44 +00001841 self.ser.addOperator(op["op"], input_list, output_list)
evacha017f7d4252024-01-24 12:08:09 +00001842
1843 compliance = self.tensorComplianceMetaData(
1844 op, a.dtype, args_dict, result_tensor, error_name
1845 )
1846
1847 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001848
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001849 def build_tile(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001850 self,
1851 rng,
1852 op,
1853 inputs,
1854 args_dict,
1855 validator_fcns=None,
1856 error_name=None,
1857 qinfo=None,
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001858 ):
Tai Ly8690a082023-12-18 20:40:24 +00001859 assert len(inputs) == 2
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001860 a = inputs[0]
Won Jeon64e4bfe2024-01-18 06:31:55 +00001861 multiples = inputs[1]
Tai Ly8690a082023-12-18 20:40:24 +00001862 multiples_attr = args_dict["multiples"]
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001863 result_tensor = OutputShaper.tileOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001864 self.ser, rng, a, multiples_attr, error_name
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001865 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001866
1867 # Invalidate Input/Output list for error if checks.
Tai Ly8690a082023-12-18 20:40:24 +00001868 input_list = [a.name, multiples.name]
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001869 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001870 pCount, cCount = op["operands"]
1871 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001872 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001873 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001874 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001875
Les Bell729b0352021-11-24 10:28:21 +00001876 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001877 self.ser,
1878 validator_fcns,
1879 error_name,
1880 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001881 input_shape=a.shape,
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001882 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001883 input_dtype=a.dtype,
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001884 output_dtype=result_tensor.dtype,
1885 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001886 input_list=input_list,
1887 output_list=output_list,
1888 num_operands=num_operands,
Luke Huttona4e48ca2023-02-22 11:53:48 +00001889 input1=a,
Les Bell729b0352021-11-24 10:28:21 +00001890 ):
1891 return None
Eric Kunzee5e26762020-10-13 16:11:07 -07001892
Tai Ly8690a082023-12-18 20:40:24 +00001893 self.ser.addOperator(op["op"], input_list, output_list)
Jeremy Johnson9f5febe2024-01-15 15:12:17 +00001894
1895 compliance = self.tensorComplianceMetaData(
1896 op, a.dtype, args_dict, result_tensor, error_name
1897 )
1898
1899 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07001900
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001901 def build_gather(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001902 self,
1903 rng,
1904 op,
1905 inputs,
1906 args_dict,
1907 validator_fcns=None,
1908 error_name=None,
1909 qinfo=None,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001910 ):
1911 assert len(inputs) == 2
1912 values, indices = inputs
Eric Kunzee5e26762020-10-13 16:11:07 -07001913
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001914 result_tensor = OutputShaper.gatherOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001915 self.ser, rng, values, indices, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001916 )
Eric Kunzee5e26762020-10-13 16:11:07 -07001917
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001918 # Invalidate Input/Output list for error if checks.
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001919 input_list = [values.name, indices.name]
1920 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001921 pCount, cCount = op["operands"]
1922 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001923 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001924 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001925 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001926
Les Bell729b0352021-11-24 10:28:21 +00001927 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001928 self.ser,
1929 validator_fcns,
1930 error_name,
1931 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001932 input_shape=values.shape,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001933 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001934 input_dtype=values.dtype,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001935 output_dtype=result_tensor.dtype,
1936 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001937 input_list=input_list,
1938 output_list=output_list,
1939 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001940 ):
1941 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001942
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001943 self.ser.addOperator(op["op"], input_list, output_list)
Eric Kunzee5e26762020-10-13 16:11:07 -07001944
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001945 compliance = self.tensorComplianceMetaData(
1946 op, values.dtype, args_dict, result_tensor, error_name
1947 )
Eric Kunzee5e26762020-10-13 16:11:07 -07001948
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001949 return TosaTestGen.BuildInfo(result_tensor, compliance)
Kevin Cheng77d0f762020-11-24 10:26:32 -08001950
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001951 def build_scatter(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001952 self,
1953 rng,
1954 op,
1955 inputs,
1956 args_dict,
1957 validator_fcns=None,
1958 error_name=None,
1959 qinfo=None,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001960 ):
1961 assert len(inputs) == 3
1962 values_in, indices, input = inputs
1963 result_tensor = OutputShaper.scatterOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001964 self.ser, rng, values_in, indices, input, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001965 )
Kevin Cheng77d0f762020-11-24 10:26:32 -08001966
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001967 # Invalidate Input/Output list for error if checks.
Jeremy Johnson194fe312023-12-07 14:17:57 +00001968 input_list = [values_in.name, indices.name, input.name]
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001969 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001970 pCount, cCount = op["operands"]
1971 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001972 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01001973 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001974 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001975
Les Bell729b0352021-11-24 10:28:21 +00001976 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001977 self.ser,
1978 validator_fcns,
1979 error_name,
1980 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001981 input_shape=values_in.shape,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001982 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001983 input_dtype=values_in.dtype,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001984 output_dtype=result_tensor.dtype,
1985 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001986 input_list=input_list,
1987 output_list=output_list,
1988 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00001989 ):
1990 return None
Kevin Cheng77d0f762020-11-24 10:26:32 -08001991
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00001992 self.ser.addOperator(op["op"], input_list, output_list)
Matthew Haddonbb5676f2021-10-13 11:30:30 +01001993
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00001994 compliance = self.tensorComplianceMetaData(
1995 op, values_in.dtype, args_dict, result_tensor, error_name
1996 )
1997
1998 return TosaTestGen.BuildInfo(result_tensor, compliance)
Kevin Cheng77d0f762020-11-24 10:26:32 -08001999
Kevin Cheng550ccc52021-03-03 11:21:43 -08002000 def build_resize(
2001 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002002 rng,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002003 op,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002004 inputs,
2005 args_dict,
Matthew Haddone86fd342021-09-07 16:12:21 +01002006 validator_fcns,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002007 error_name=None,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002008 qinfo=None,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002009 ):
Tai Lyc5c2a7e2024-02-22 23:26:28 +00002010 assert len(inputs) == 4
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002011 input = inputs[0]
Tai Lyc5c2a7e2024-02-22 23:26:28 +00002012 scale_input = inputs[1]
2013 offset_input = inputs[2]
2014 border_input = inputs[3]
2015
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002016 mode = args_dict["mode"]
2017 scale = args_dict["scale"]
2018 offset = args_dict["offset"]
2019 border = args_dict["border"]
2020 output_dtype = args_dict["output_dtype"]
2021
2022 result_tensor = OutputShaper.resizeOp(
Kevin Cheng550ccc52021-03-03 11:21:43 -08002023 self.ser,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002024 rng,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002025 input,
2026 mode,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01002027 scale,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002028 offset,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01002029 border,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002030 input.dtype,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002031 output_dtype,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002032 error_name,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002033 )
Eric Kunzee5e26762020-10-13 16:11:07 -07002034
Matthew Haddon848efb42021-09-09 12:30:53 +01002035 # Invalidate Input/Output list for error if checks.
Tai Lyc5c2a7e2024-02-22 23:26:28 +00002036 input_list = [
2037 input.name,
2038 scale_input.name,
2039 offset_input.name,
2040 border_input.name,
2041 ]
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002042 output_list = [result_tensor.name]
Matthew Haddon848efb42021-09-09 12:30:53 +01002043 pCount, cCount = op["operands"]
2044 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002045 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002046 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002047 )
Matthew Haddone86fd342021-09-07 16:12:21 +01002048
Les Bell729b0352021-11-24 10:28:21 +00002049 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddon848efb42021-09-09 12:30:53 +01002050 self.ser,
2051 validator_fcns,
2052 error_name,
2053 op=op,
2054 mode=mode,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01002055 scale=scale,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002056 input_dtype=input.dtype,
Matthew Haddon848efb42021-09-09 12:30:53 +01002057 output_dtype=output_dtype,
Matthew Haddonb6b59e32021-10-07 17:19:20 +01002058 input_shape=input.shape,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002059 output_shape=result_tensor.shape,
Matthew Haddon848efb42021-09-09 12:30:53 +01002060 offset=offset,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01002061 border=border,
Matthew Haddon848efb42021-09-09 12:30:53 +01002062 input_list=input_list,
2063 output_list=output_list,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002064 result_tensors=[result_tensor],
Matthew Haddon848efb42021-09-09 12:30:53 +01002065 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00002066 ):
2067 return None
Matthew Haddone86fd342021-09-07 16:12:21 +01002068
Eric Kunzee5e26762020-10-13 16:11:07 -07002069 attr = ts.TosaSerializerAttribute()
Tai Lyc5c2a7e2024-02-22 23:26:28 +00002070 # write empty scale/offset/border into ResizeAttribute
2071 attr.ResizeAttribute([], [], [], mode)
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002072 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00002073
2074 compliance = self.tensorComplianceMetaData(
2075 op, input.dtype, args_dict, result_tensor, error_name
2076 )
2077
2078 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07002079
evacha0198477222024-01-26 12:25:32 +00002080 def build_const(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002081 self,
2082 rng,
2083 op,
2084 inputs,
2085 args_dict,
2086 validator_fcns=None,
2087 error_name=None,
2088 qinfo=None,
evacha0198477222024-01-26 12:25:32 +00002089 ):
2090 assert len(inputs) == 1
2091 val = inputs[0]
Kevin Cheng17e92022021-10-01 14:33:33 -07002092 self.ser.addOutputTensor(val)
evacha0198477222024-01-26 12:25:32 +00002093
2094 compliance = self.tensorComplianceMetaData(
2095 op, val.dtype, args_dict, val, error_name
2096 )
2097
2098 return TosaTestGen.BuildInfo(val, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07002099
2100 # Type Conversion
Jeremy Johnson708da822023-11-15 16:25:45 +00002101 def build_cast(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002102 self,
2103 rng,
2104 op,
2105 inputs,
2106 args_dict,
2107 validator_fcns=None,
2108 error_name=None,
2109 qinfo=None,
Jeremy Johnson708da822023-11-15 16:25:45 +00002110 ):
2111 assert len(inputs) == 1
2112 val = inputs[0]
2113 out_dtype = args_dict["out_type"]
2114
2115 result_tensor = OutputShaper.typeConversionOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002116 self.ser, rng, val, out_dtype, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002117 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01002118
2119 # Invalidate Input/Output list for error if checks.
2120 input_list = [val.name]
Jeremy Johnson708da822023-11-15 16:25:45 +00002121 output_list = [result_tensor.name]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01002122 pCount, cCount = op["operands"]
2123 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002124 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002125 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002126 )
Matthew Haddonbb5676f2021-10-13 11:30:30 +01002127
Les Bell729b0352021-11-24 10:28:21 +00002128 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonbb5676f2021-10-13 11:30:30 +01002129 self.ser,
2130 validator_fcns,
2131 error_name,
2132 op=op,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002133 input_shape=val.shape,
Jeremy Johnson708da822023-11-15 16:25:45 +00002134 output_shape=result_tensor.shape,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002135 input_dtype=val.dtype,
Jeremy Johnson708da822023-11-15 16:25:45 +00002136 output_dtype=result_tensor.dtype,
2137 result_tensors=[result_tensor],
Matthew Haddonbb5676f2021-10-13 11:30:30 +01002138 input_list=input_list,
2139 output_list=output_list,
2140 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00002141 ):
2142 return None
Matthew Haddonbb5676f2021-10-13 11:30:30 +01002143
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002144 self.ser.addOperator(op["op"], input_list, output_list)
Jeremy Johnson708da822023-11-15 16:25:45 +00002145
2146 compliance = self.tensorComplianceMetaData(
2147 op, val.dtype, args_dict, result_tensor, error_name
2148 )
2149
2150 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07002151
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002152 def build_rescale(
2153 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002154 rng,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002155 op,
Jeremy Johnson587cc842024-02-08 11:45:44 +00002156 inputs,
2157 args_dict,
2158 validator_fcns=None,
2159 error_name=None,
2160 qinfo=None,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002161 ):
Tai Ly6e1e2bc2024-03-01 20:59:32 +00002162 assert len(inputs) == 3
Jeremy Johnson587cc842024-02-08 11:45:44 +00002163 val = inputs[0]
Tai Ly6e1e2bc2024-03-01 20:59:32 +00002164 multiplier_val = inputs[1]
2165 shift_val = inputs[2]
Jeremy Johnson587cc842024-02-08 11:45:44 +00002166 out_dtype = args_dict["output_dtype"]
2167 scale32 = args_dict["scale"]
2168 double_round = args_dict["double_round"]
2169 per_channel = args_dict["per_channel"]
Tai Ly6e1e2bc2024-03-01 20:59:32 +00002170 shift_arr = args_dict["shift"]
Jeremy Johnsonaf090182024-02-13 18:25:39 +00002171 multiplier_arr = args_dict["multiplier"]
Jeremy Johnson587cc842024-02-08 11:45:44 +00002172
2173 result_tensor = OutputShaper.typeConversionOp(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002174 self.ser, rng, val, out_dtype, error_name
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002175 )
Eric Kunzee5e26762020-10-13 16:11:07 -07002176
2177 if per_channel:
2178 nc = val.shape[-1]
2179 else:
2180 nc = 1
2181
Tai Ly6e1e2bc2024-03-01 20:59:32 +00002182 in_type_width = gtu.dtypeWidth(val.dtype)
2183 out_type_width = gtu.dtypeWidth(out_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07002184
Tai Ly8690a082023-12-18 20:40:24 +00002185 input_unsigned = False
2186 output_unsigned = False
2187
Kevin Cheng3a478572021-01-22 17:21:02 -08002188 if val.dtype == DType.INT8:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002189 input_zp = rng.randInt(-128, 128)
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002190 in_type_width += 1
Kevin Chengacb550f2021-06-29 15:32:19 -07002191 elif val.dtype == DType.UINT8:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002192 input_zp = rng.randInt(0, 256)
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002193 in_type_width += 1
Tai Ly8690a082023-12-18 20:40:24 +00002194 input_unsigned = True
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002195 elif error_name in [
2196 ErrorIf.InputZeroPointNotZero,
2197 ErrorIf.U16InputZeroPointNotValid,
2198 ]:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002199 input_zp = rng.randInt(-128, 128)
Matthew Haddonc2025212021-10-08 21:21:05 +01002200 if input_zp == 0:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002201 input_zp = input_zp + rng.integers(1, 10)
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002202 in_type_width += 1
2203 elif val.dtype == DType.UINT16:
2204 # Must come after ErrorIf.U16InputZeroPointNotValid check
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002205 input_zp = rng.choice([0, 32768])
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002206 in_type_width += 1
Tai Ly8690a082023-12-18 20:40:24 +00002207 input_unsigned = True
Eric Kunzee5e26762020-10-13 16:11:07 -07002208 else:
2209 input_zp = 0
2210
Kevin Cheng3a478572021-01-22 17:21:02 -08002211 if out_dtype == DType.INT8:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002212 output_zp = rng.randInt(-128, 128)
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002213 out_type_width += 1
Matthew Haddoncac4ee92021-07-22 14:30:53 +01002214 elif out_dtype == DType.UINT8:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002215 output_zp = rng.randInt(0, 256)
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002216 out_type_width += 1
Tai Ly8690a082023-12-18 20:40:24 +00002217 output_unsigned = True
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002218 elif error_name in [
2219 ErrorIf.OutputZeroPointNotZero,
2220 ErrorIf.U16OutputZeroPointNotValid,
2221 ]:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002222 output_zp = rng.randInt(-128, 128)
Matthew Haddonc2025212021-10-08 21:21:05 +01002223 if output_zp == 0:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002224 output_zp = output_zp + rng.integers(1, 10)
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002225 out_type_width += 1
2226 elif out_dtype == DType.UINT16:
2227 # Must come after ErrorIf.U16OutputZeroPointNotValid check
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002228 output_zp = rng.choice([0, 32768])
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002229 out_type_width += 1
Tai Ly8690a082023-12-18 20:40:24 +00002230 output_unsigned = True
Eric Kunzee5e26762020-10-13 16:11:07 -07002231 else:
2232 output_zp = 0
2233
Jeremy Johnson42c9bae2022-02-01 11:37:58 +00002234 min_shift_value_arr = np.int64(np.zeros(shape=[nc]))
2235 max_shift_value_arr = np.int64(np.zeros(shape=[nc]))
Eric Kunzee5e26762020-10-13 16:11:07 -07002236
2237 for i in range(nc):
Eric Kunze750d27d2022-06-30 21:37:09 +00002238 min_shift_value_arr[i] = -1 << (shift_arr[i] - 1)
2239 max_shift_value_arr[i] = (1 << (shift_arr[i] - 1)) - 1
Eric Kunzee5e26762020-10-13 16:11:07 -07002240
Jeremy Johnsonaf090182024-02-13 18:25:39 +00002241 logger.debug(
2242 f"build_rescale: multiplier={multiplier_arr} shift={shift_arr} inzp={input_zp} outzp={output_zp}"
2243 )
Jeremy Johnsonc0fe04d2022-02-17 12:29:35 +00002244 if scale32 and error_name is None:
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01002245 # Make sure random values are within apply_scale_32 specification
Eric Kunze750d27d2022-06-30 21:37:09 +00002246 # REQUIRES(value >= (-1<<(shift-1)) && value < (1<<(shift-1))
Jeremy Johnson42c9bae2022-02-01 11:37:58 +00002247 assert val.placeholderFilename
2248 values = np.load(
2249 os.path.join(self.basePath, self.testPath, val.placeholderFilename)
2250 )
Jeremy Johnsonc0fe04d2022-02-17 12:29:35 +00002251 val_adj = np.subtract(values, input_zp, dtype=np.int64)
2252 val_adj = np.maximum(val_adj, min_shift_value_arr, dtype=np.int64)
2253 val_adj = np.minimum(val_adj, max_shift_value_arr, dtype=np.int64)
Jerry Gec5291692024-01-02 22:29:08 +00002254 val_adj = np.add(val_adj, input_zp, dtype=np.int64)
2255 # Check we can safely convert to the expected dtype
2256 assert (
2257 val_adj.all() >= np.iinfo(values.dtype).min
2258 and val_adj.all() <= np.iinfo(values.dtype).max
2259 )
2260
2261 # Force casting to output datatype
2262 val_adj = val_adj.astype(values.dtype, casting="unsafe")
2263
Jeremy Johnson42c9bae2022-02-01 11:37:58 +00002264 if not np.all(np.array_equal(values, val_adj)):
2265 # Values changed so overwrite file with new values
2266 np.save(
2267 os.path.join(self.basePath, self.testPath, val.placeholderFilename),
2268 val_adj,
2269 False,
2270 )
Eric Kunzee5e26762020-10-13 16:11:07 -07002271
Matthew Haddonc2025212021-10-08 21:21:05 +01002272 # Invalidate Input/Output list for error if checks.
Tai Ly6e1e2bc2024-03-01 20:59:32 +00002273 input_list = [val.name, multiplier_val.name, shift_val.name]
Jeremy Johnson587cc842024-02-08 11:45:44 +00002274 output_list = [result_tensor.name]
Matthew Haddonc2025212021-10-08 21:21:05 +01002275 pCount, cCount = op["operands"]
2276 num_operands = pCount + cCount
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002277 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002278 rng, error_name, input_list, output_list
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002279 )
Matthew Haddonc2025212021-10-08 21:21:05 +01002280
2281 qinfo = (input_zp, output_zp)
Les Bell729b0352021-11-24 10:28:21 +00002282 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddonc2025212021-10-08 21:21:05 +01002283 self.ser,
2284 validator_fcns,
2285 error_name,
2286 op=op,
2287 input_dtype=val.dtype,
2288 output_dtype=out_dtype,
2289 input_shape=val.shape,
2290 qinfo=qinfo,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002291 scale32=scale32,
2292 double_round=double_round,
Matthew Haddonc2025212021-10-08 21:21:05 +01002293 input_list=input_list,
2294 output_list=output_list,
Jeremy Johnson587cc842024-02-08 11:45:44 +00002295 result_tensors=[result_tensor],
Matthew Haddonc2025212021-10-08 21:21:05 +01002296 num_operands=num_operands,
Les Bell729b0352021-11-24 10:28:21 +00002297 ):
2298 return None
Matthew Haddonc2025212021-10-08 21:21:05 +01002299
Eric Kunzee5e26762020-10-13 16:11:07 -07002300 attr = ts.TosaSerializerAttribute()
Kevin Cheng550ccc52021-03-03 11:21:43 -08002301 attr.RescaleAttribute(
2302 input_zp,
2303 output_zp,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002304 scale32,
2305 double_round,
2306 per_channel,
Tai Ly8690a082023-12-18 20:40:24 +00002307 input_unsigned,
2308 output_unsigned,
Kevin Cheng550ccc52021-03-03 11:21:43 -08002309 )
Eric Kunzee5e26762020-10-13 16:11:07 -07002310
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002311 self.ser.addOperator(op["op"], input_list, output_list, attr)
Jeremy Johnson587cc842024-02-08 11:45:44 +00002312
2313 compliance = self.tensorComplianceMetaData(
2314 op, val.dtype, args_dict, result_tensor, error_name
2315 )
2316
2317 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07002318
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002319 def _get_condition_tensor(self, rng, op, cond, error_name):
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002320 if error_name == ErrorIf.CondIfCondNotMatchingBool:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002321 cond_type = gtu.get_wrong_output_type(op, rng, DType.BOOL)
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002322 else:
2323 cond_type = DType.BOOL
2324 if error_name == ErrorIf.CondIfCondShapeNotSizeOne:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002325 choice = rng.choice([1, 2])
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002326 if choice == 1:
2327 cond_shape = [2]
2328 else:
2329 cond_shape = [1, 2]
2330 else:
2331 # Must be of size 1 (rank 0)
2332 cond_shape = []
2333 cond_tens = self.ser.addConst(cond_shape, cond_type, [cond])
2334 return cond_tens
2335
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002336 def build_cond_if_const(
Jeremy Johnson587cc842024-02-08 11:45:44 +00002337 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002338 rng,
Jeremy Johnson587cc842024-02-08 11:45:44 +00002339 op,
2340 inputs,
2341 args_dict,
2342 validator_fcns=None,
2343 error_name=None,
2344 qinfo=None,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002345 ):
Eric Kunzee5e26762020-10-13 16:11:07 -07002346 # For cond_if with constants, we're supplied with then/else tensors that we ignore
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002347 # (except for the generated shape) and the condition. Build Then/Else blocks
Eric Kunzee5e26762020-10-13 16:11:07 -07002348 # and fill them with const nodes for the body.
Jeremy Johnson587cc842024-02-08 11:45:44 +00002349 assert len(inputs) == 2
2350 then_tens, else_tens = inputs
2351
2352 cond = args_dict["condition"]
Eric Kunzee5e26762020-10-13 16:11:07 -07002353
2354 # Condition tensor
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002355 cond_tens = self._get_condition_tensor(rng, op, cond, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -07002356
2357 # Make then/else tensors
2358 out_shape = then_tens.shape
Matthew Haddon630c17c2021-10-14 15:05:41 +01002359
Jeremy Johnson587cc842024-02-08 11:45:44 +00002360 dtype = DType.INT32
2361
Matthew Haddon630c17c2021-10-14 15:05:41 +01002362 # Create an incorrect output shape for error_if tests
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002363 if error_name in [
2364 ErrorIf.CondIfOutputListThenGraphMismatch,
2365 ErrorIf.CondIfOutputListElseGraphMismatch,
2366 ]:
Matthew Haddon630c17c2021-10-14 15:05:41 +01002367 incorrect_shape = deepcopy(then_tens.shape)
2368 for i in range(len(incorrect_shape)):
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002369 incorrect_shape[i] += (
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002370 rng.choice([-3, -2, 2, 3])
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002371 if incorrect_shape[i] > 3
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002372 else rng.choice([1, 2, 4])
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002373 )
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002374 incorrect_arr = np.int32(rng.integers(0, 256, size=incorrect_shape))
Matthew Haddon630c17c2021-10-14 15:05:41 +01002375
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002376 then_arr = np.int32(rng.integers(0, 256, size=out_shape))
2377 else_arr = np.int32(rng.integers(0, 256, size=out_shape))
Eric Kunzee5e26762020-10-13 16:11:07 -07002378
2379 # And the result tensor based on any of the outputs
Jeremy Johnson587cc842024-02-08 11:45:44 +00002380 result_tensor = self.ser.addOutput(out_shape, dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07002381
2382 # Create the attribute with the names of the then/else blocks
Kevin Cheng550ccc52021-03-03 11:21:43 -08002383 then_block = "THEN_BLOCK"
2384 else_block = "ELSE_BLOCK"
Eric Kunzee5e26762020-10-13 16:11:07 -07002385 attr = ts.TosaSerializerAttribute()
2386 attr.CondIfAttribute(then_block, else_block)
2387
2388 # Finally, build the op and the two blocks
Jeremy Johnson587cc842024-02-08 11:45:44 +00002389 self.ser.addOperator(op["op"], [cond_tens.name], [result_tensor.name], attr)
Eric Kunzee5e26762020-10-13 16:11:07 -07002390
Jerry Ge9e94af82022-10-27 09:57:00 -07002391 self.ser.addBasicBlock(then_block)
Eric Kunzee5e26762020-10-13 16:11:07 -07002392 # Build the actual then/else tensors inside their blocks
Matthew Haddon630c17c2021-10-14 15:05:41 +01002393 if error_name == ErrorIf.CondIfOutputListThenGraphMismatch:
Jeremy Johnson587cc842024-02-08 11:45:44 +00002394 then_tens = self.ser.addConst(incorrect_shape, dtype, incorrect_arr)
Matthew Haddon630c17c2021-10-14 15:05:41 +01002395 else:
Jeremy Johnson587cc842024-02-08 11:45:44 +00002396 then_tens = self.ser.addConst(out_shape, dtype, then_arr)
Eric Kunzee5e26762020-10-13 16:11:07 -07002397 self.ser.addOutputTensor(then_tens)
2398
Jerry Ge9e94af82022-10-27 09:57:00 -07002399 self.ser.addBasicBlock(else_block)
Matthew Haddon630c17c2021-10-14 15:05:41 +01002400 if error_name == ErrorIf.CondIfOutputListElseGraphMismatch:
Jeremy Johnson587cc842024-02-08 11:45:44 +00002401 else_tens = self.ser.addConst(incorrect_shape, dtype, incorrect_arr)
Matthew Haddon630c17c2021-10-14 15:05:41 +01002402 else:
Jeremy Johnson587cc842024-02-08 11:45:44 +00002403 else_tens = self.ser.addConst(out_shape, dtype, else_arr)
Eric Kunzee5e26762020-10-13 16:11:07 -07002404 self.ser.addOutputTensor(else_tens)
2405
Les Bell729b0352021-11-24 10:28:21 +00002406 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddon630c17c2021-10-14 15:05:41 +01002407 self.ser,
2408 validator_fcns,
2409 error_name,
2410 op=op,
Jerry Ge9e94af82022-10-27 09:57:00 -07002411 basicBlocks=self.ser.currRegion.basicBlocks,
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002412 cond=cond_tens,
Les Bell729b0352021-11-24 10:28:21 +00002413 ):
2414 return None
Matthew Haddon630c17c2021-10-14 15:05:41 +01002415
Jeremy Johnson587cc842024-02-08 11:45:44 +00002416 compliance = self.tensorComplianceMetaData(
2417 op, dtype, args_dict, result_tensor, error_name
2418 )
2419
2420 return TosaTestGen.BuildInfo(result_tensor, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07002421
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002422 def build_cond_if_binary(
Jeremy Johnson587cc842024-02-08 11:45:44 +00002423 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002424 rng,
Jeremy Johnson587cc842024-02-08 11:45:44 +00002425 op,
2426 inputs,
2427 args_dict,
2428 validator_fcns=None,
2429 error_name=None,
2430 qinfo=None,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002431 ):
Eric Kunzee5e26762020-10-13 16:11:07 -07002432 # For cond_if with a binary op in the then/else blocks, take a and b and
2433 # alternately add or subtract them based on the condition
Jeremy Johnson587cc842024-02-08 11:45:44 +00002434 assert len(inputs) == 2
2435 a, b = inputs
2436
2437 cond = args_dict["condition"]
Eric Kunzee5e26762020-10-13 16:11:07 -07002438
2439 # Condition tensor
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002440 cond_tens = self._get_condition_tensor(rng, op, cond, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -07002441
Jeremy Johnson587cc842024-02-08 11:45:44 +00002442 result_tensor = self.ser.addOutput(a.shape, a.dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07002443
2444 # Create the attribute with the names of the then/else blocks
Kevin Cheng550ccc52021-03-03 11:21:43 -08002445 then_block = "THEN_BLOCK"
2446 else_block = "ELSE_BLOCK"
Eric Kunzee5e26762020-10-13 16:11:07 -07002447 attr = ts.TosaSerializerAttribute()
2448 attr.CondIfAttribute(then_block, else_block)
2449
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002450 if error_name in [
2451 ErrorIf.CondIfInputListThenGraphMismatch,
2452 ErrorIf.CondIfInputListElseGraphMismatch,
2453 ErrorIf.CondIfOutputListElseGraphMismatch,
2454 ErrorIf.CondIfOutputListThenGraphMismatch,
2455 ]:
Matthew Haddon630c17c2021-10-14 15:05:41 +01002456 incorrect_shape = a.shape.copy()
2457 for i in range(len(incorrect_shape)):
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002458 incorrect_shape[i] += rng.choice([-3, -2, 2, 3])
Matthew Haddon630c17c2021-10-14 15:05:41 +01002459 incorrect_block_input = deepcopy(a)
2460 incorrect_block_input.shape = incorrect_shape
2461
Eric Kunzee5e26762020-10-13 16:11:07 -07002462 # Finally, build the op and the two blocks
Kevin Cheng550ccc52021-03-03 11:21:43 -08002463 self.ser.addOperator(
Jeremy Johnson587cc842024-02-08 11:45:44 +00002464 op["op"], [cond_tens.name, a.name, b.name], [result_tensor.name], attr
Kevin Cheng550ccc52021-03-03 11:21:43 -08002465 )
Eric Kunzee5e26762020-10-13 16:11:07 -07002466
James Ward24dbc422022-10-19 12:20:31 +01002467 if a.dtype in (DType.FP32, DType.BF16, DType.FP16, DType.INT32):
Jeremy Johnson587cc842024-02-08 11:45:44 +00002468 then_op, else_op = self.TOSA_OP_LIST["add"], self.TOSA_OP_LIST["sub"]
Les Bell6040b4d2021-10-11 12:50:31 +01002469 elif a.dtype in (DType.INT8, DType.INT16):
Jeremy Johnson587cc842024-02-08 11:45:44 +00002470 then_op, else_op = (
2471 self.TOSA_OP_LIST["logical_right_shift"],
2472 self.TOSA_OP_LIST["logical_left_shift"],
2473 )
Les Bell6040b4d2021-10-11 12:50:31 +01002474 else:
2475 assert False, f"No tests for DType: {a.dtype}"
Eric Kunzee5e26762020-10-13 16:11:07 -07002476
Jeremy Johnson587cc842024-02-08 11:45:44 +00002477 # Determine the element-wise binary operation that compliance will need to
2478 # check the results of
2479 compliance_op = then_op if cond else else_op
2480
2481 for block, block_op in ((then_block, then_op), (else_block, else_op)):
Jerry Ge9e94af82022-10-27 09:57:00 -07002482 self.ser.addBasicBlock(block)
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002483 if (
2484 error_name == ErrorIf.CondIfInputListThenGraphMismatch
2485 and block == then_block
2486 ) or (
2487 error_name == ErrorIf.CondIfInputListElseGraphMismatch
2488 and block == else_block
2489 ):
Matthew Haddon630c17c2021-10-14 15:05:41 +01002490 self.ser.addInputTensor(incorrect_block_input)
2491 self.ser.addInputTensor(b)
2492 tens = self.ser.addOutput(a.shape, a.dtype)
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002493 elif (
2494 error_name == ErrorIf.CondIfOutputListThenGraphMismatch
2495 and block == then_block
2496 ) or (
2497 error_name == ErrorIf.CondIfOutputListElseGraphMismatch
2498 and block == else_block
2499 ):
Matthew Haddon630c17c2021-10-14 15:05:41 +01002500 self.ser.addInputTensor(a)
2501 self.ser.addInputTensor(b)
2502 tens = self.ser.addOutput(incorrect_block_input.shape, a.dtype)
2503 else:
2504 self.ser.addInputTensor(a)
2505 self.ser.addInputTensor(b)
2506 tens = self.ser.addOutput(a.shape, a.dtype)
Jeremy Johnson587cc842024-02-08 11:45:44 +00002507 self.ser.addOperator(block_op["op"], [a.name, b.name], [tens.name])
Eric Kunzee5e26762020-10-13 16:11:07 -07002508
Les Bell729b0352021-11-24 10:28:21 +00002509 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddon630c17c2021-10-14 15:05:41 +01002510 self.ser,
2511 validator_fcns,
2512 error_name,
2513 op=op,
2514 a=a,
2515 b=b,
Jerry Ge9e94af82022-10-27 09:57:00 -07002516 basicBlocks=self.ser.currRegion.basicBlocks,
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002517 cond=cond_tens,
Les Bell729b0352021-11-24 10:28:21 +00002518 ):
2519 return None
Matthew Haddon630c17c2021-10-14 15:05:41 +01002520
Jeremy Johnson587cc842024-02-08 11:45:44 +00002521 compliance = self.tensorComplianceMetaData(
2522 compliance_op, a.dtype, args_dict, result_tensor, error_name
2523 )
Eric Kunzee5e26762020-10-13 16:11:07 -07002524
Jeremy Johnson587cc842024-02-08 11:45:44 +00002525 return TosaTestGen.BuildInfo(result_tensor, compliance)
2526
2527 def build_while_loop(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002528 self,
2529 rng,
2530 op,
2531 inputs,
2532 args_dict,
2533 validator_fcns=None,
2534 error_name=None,
2535 qinfo=None,
Jeremy Johnson587cc842024-02-08 11:45:44 +00002536 ):
2537 assert len(inputs) == 1
2538 a = inputs[0]
2539 iter_val = args_dict["iterations"]
2540
Kevin Cheng550ccc52021-03-03 11:21:43 -08002541 iter = self.ser.addPlaceholder([], DType.INT32, [np.int32(iter_val)])
Eric Kunzee5e26762020-10-13 16:11:07 -07002542
Kevin Cheng550ccc52021-03-03 11:21:43 -08002543 cond_block = "COND_BLOCK"
2544 body_block = "BODY_BLOCK"
Eric Kunzee5e26762020-10-13 16:11:07 -07002545
2546 attr = ts.TosaSerializerAttribute()
2547 attr.WhileLoopAttribute(cond_block, body_block)
2548
2549 # Accumulator tensor
Kevin Cheng550ccc52021-03-03 11:21:43 -08002550 # acc = self.ser.addOutput(a.shape, a.dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07002551 acc_init_val = np.int32(np.zeros(a.shape))
Kevin Cheng550ccc52021-03-03 11:21:43 -08002552 acc = self.ser.addPlaceholder(a.shape, a.dtype, acc_init_val)
Eric Kunzee5e26762020-10-13 16:11:07 -07002553
2554 # Intermediate/output tensors for everything going through the loop
Kevin Cheng550ccc52021-03-03 11:21:43 -08002555 iter_out = self.ser.addIntermediate(iter.shape, iter.dtype)
2556 a_out = self.ser.addIntermediate(a.shape, a.dtype)
Matthew Haddon630c17c2021-10-14 15:05:41 +01002557 if error_name == ErrorIf.InputListOutputListMismatch:
2558 incorrect_acc = deepcopy(acc)
2559 for i in range(len(incorrect_acc.shape)):
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002560 incorrect_acc.shape[i] += rng.choice([-3, -2, 2, 3])
Matthew Haddon630c17c2021-10-14 15:05:41 +01002561 acc_out = self.ser.addIntermediate(incorrect_acc.shape, acc.dtype)
2562 else:
2563 acc_out = self.ser.addIntermediate(acc.shape, acc.dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07002564
2565 # While_loop operator
Kevin Cheng550ccc52021-03-03 11:21:43 -08002566 self.ser.addOperator(
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002567 op["op"],
Kevin Cheng550ccc52021-03-03 11:21:43 -08002568 [iter.name, a.name, acc.name],
2569 [iter_out.name, a_out.name, acc_out.name],
2570 attr,
2571 )
Kevin Chengb227ae52021-09-02 13:43:17 -07002572 self.ser.addOutputTensor(acc_out)
Eric Kunzee5e26762020-10-13 16:11:07 -07002573
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002574 if error_name in [
2575 ErrorIf.InputListCondGraphMismatch,
2576 ErrorIf.InputListBodyGraphInputMismatch,
2577 ErrorIf.InputListBodyGraphOutputMismatch,
2578 ]:
Matthew Haddon630c17c2021-10-14 15:05:41 +01002579 incorrect_iter = deepcopy(iter)
2580 for i in range(len(incorrect_iter.shape)):
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002581 incorrect_iter.shape[i] += rng.choice([-3, -2, 2, 3])
Matthew Haddon630c17c2021-10-14 15:05:41 +01002582 if len(incorrect_iter.shape) == 0:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002583 incorrect_iter.shape.append(rng.choice([-3, -2, 2, 3]))
Matthew Haddon630c17c2021-10-14 15:05:41 +01002584
2585 incorrect_acc = deepcopy(acc)
2586 for i in range(len(incorrect_acc.shape)):
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002587 incorrect_acc.shape[i] += rng.choice([-3, -2, 2, 3])
Matthew Haddon630c17c2021-10-14 15:05:41 +01002588
Eric Kunzee5e26762020-10-13 16:11:07 -07002589 # COND block (input: iter, output: cond_tens )
Jerry Ge9e94af82022-10-27 09:57:00 -07002590 self.ser.addBasicBlock(cond_block)
2591
Matthew Haddon630c17c2021-10-14 15:05:41 +01002592 if error_name == ErrorIf.InputListCondGraphMismatch:
2593 self.ser.addInputTensor(incorrect_iter)
2594 self.ser.addInputTensor(a)
2595 self.ser.addInputTensor(incorrect_acc)
2596 else:
2597 self.ser.addInputTensor(iter)
2598 self.ser.addInputTensor(a)
2599 self.ser.addInputTensor(acc)
Kevin Cheng550ccc52021-03-03 11:21:43 -08002600 zero_tens = self.ser.addConst([], DType.INT32, [np.int32(0)])
Matthew Haddon630c17c2021-10-14 15:05:41 +01002601
2602 if error_name == ErrorIf.CondGraphOutputNotMatchingBool:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002603 cond_type = rng.choice([DType.INT8, DType.INT32, DType.FP32])
Matthew Haddon630c17c2021-10-14 15:05:41 +01002604 else:
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002605 cond_type = DType.BOOL
2606 if error_name == ErrorIf.CondGraphOutputShapeNotSizeOne:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002607 choice = rng.choice([1, 2])
Jeremy Johnson05c711e2022-12-12 18:00:41 +00002608 if choice == 1:
2609 cond_shape = [3]
2610 else:
2611 cond_shape = [1, 2]
2612 else:
2613 cond_shape = []
2614 cond_tens = self.ser.addOutput(cond_shape, cond_type)
Matthew Haddon630c17c2021-10-14 15:05:41 +01002615
Kevin Cheng550ccc52021-03-03 11:21:43 -08002616 self.ser.addOperator(Op.GREATER, [iter.name, zero_tens.name], [cond_tens.name])
Eric Kunzee5e26762020-10-13 16:11:07 -07002617
2618 # BODY block (input: a, acc, iter, output: a, acc, iter)
2619 # Note that local intermediate tensors need to be declared here for the outputs
Jerry Ge9e94af82022-10-27 09:57:00 -07002620 self.ser.addBasicBlock(body_block)
2621
Matthew Haddon630c17c2021-10-14 15:05:41 +01002622 if error_name == ErrorIf.InputListBodyGraphInputMismatch:
2623 self.ser.addInputTensor(incorrect_iter)
2624 self.ser.addInputTensor(a)
2625 self.ser.addInputTensor(incorrect_acc)
2626 else:
2627 self.ser.addInputTensor(iter)
2628 self.ser.addInputTensor(a)
2629 self.ser.addInputTensor(acc)
2630
Kevin Cheng550ccc52021-03-03 11:21:43 -08002631 one_tens = self.ser.addConst([], DType.INT32, [np.int32(1)])
Matthew Haddon630c17c2021-10-14 15:05:41 +01002632
2633 if error_name == ErrorIf.InputListBodyGraphOutputMismatch:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002634 iter_body_out = self.ser.addIntermediate(
2635 incorrect_iter.shape, incorrect_iter.dtype
2636 )
2637 acc_body_out = self.ser.addIntermediate(
2638 incorrect_acc.shape, incorrect_acc.dtype
2639 )
Matthew Haddon630c17c2021-10-14 15:05:41 +01002640 else:
2641 iter_body_out = self.ser.addIntermediate(iter.shape, iter.dtype)
2642 acc_body_out = self.ser.addIntermediate(acc.shape, acc.dtype)
2643
Eric Kunzee5e26762020-10-13 16:11:07 -07002644 self.ser.addOperator(Op.ADD, [a.name, acc.name], [acc_body_out.name])
2645 self.ser.addOperator(Op.SUB, [iter.name, one_tens.name], [iter_body_out.name])
2646 self.ser.addOutputTensor(iter_body_out)
2647 self.ser.addOutputTensor(a)
2648 self.ser.addOutputTensor(acc_body_out)
2649
Les Bell729b0352021-11-24 10:28:21 +00002650 if not TosaErrorValidator.evValidateErrorIfs(
Matthew Haddon630c17c2021-10-14 15:05:41 +01002651 self.ser,
2652 validator_fcns,
2653 error_name,
2654 op=op,
Jerry Ge9e94af82022-10-27 09:57:00 -07002655 basicBlocks=self.ser.currRegion.basicBlocks,
Les Bell729b0352021-11-24 10:28:21 +00002656 ):
2657 return None
Matthew Haddon630c17c2021-10-14 15:05:41 +01002658
Jeremy Johnson587cc842024-02-08 11:45:44 +00002659 compliance = self.tensorComplianceMetaData(
2660 op, a.dtype, args_dict, acc_out, error_name
2661 )
2662
2663 return TosaTestGen.BuildInfo(acc_out, compliance)
Eric Kunzee5e26762020-10-13 16:11:07 -07002664
Luke Hutton57287132023-02-06 14:54:18 +00002665 def build_fft2d(
Tai Lyd3797f02023-11-15 23:06:19 +00002666 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002667 rng,
Tai Lyd3797f02023-11-15 23:06:19 +00002668 op,
Jeremy Johnsonc8330812024-01-18 16:57:28 +00002669 inputs,
2670 args_dict,
Tai Lyd3797f02023-11-15 23:06:19 +00002671 validator_fcns=None,
2672 error_name=None,
Jeremy Johnsonc8330812024-01-18 16:57:28 +00002673 qinfo=None,
Luke Hutton57287132023-02-06 14:54:18 +00002674 ):
Jeremy Johnsonc8330812024-01-18 16:57:28 +00002675 assert len(inputs) == 2
2676 val1, val2 = inputs
2677 inverse = args_dict["inverse"]
2678
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002679 results = OutputShaper.fft2dOp(self.ser, rng, val1, val2, error_name)
Luke Hutton57287132023-02-06 14:54:18 +00002680
2681 input_names = [val1.name, val2.name]
2682 pCount, cCount = op["operands"]
2683 num_operands = pCount + cCount
2684
2685 output_names = [res.name for res in results]
2686 output_shapes = [res.shape for res in results]
2687 output_dtypes = [res.dtype for res in results]
2688
2689 input_names, output_names = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002690 rng, error_name, input_names, output_names
Luke Hutton57287132023-02-06 14:54:18 +00002691 )
2692
2693 if not TosaErrorValidator.evValidateErrorIfs(
2694 self.ser,
2695 validator_fcns,
2696 error_name,
2697 op=op,
2698 inverse=inverse,
2699 input1=val1,
2700 input2=val2,
2701 input_shape=val1.shape,
2702 input_dtype=val1.dtype,
2703 output_shape=output_shapes,
2704 output_dtype=output_dtypes,
2705 result_tensors=results,
2706 input_list=input_names,
2707 output_list=output_names,
2708 num_operands=num_operands,
2709 ):
2710 return None
2711
Tai Lyd3797f02023-11-15 23:06:19 +00002712 # TODO - Test local_bound, for now set local bound attribute to False
2713 local_bound = False
2714
Luke Hutton57287132023-02-06 14:54:18 +00002715 attr = ts.TosaSerializerAttribute()
Tai Lyd3797f02023-11-15 23:06:19 +00002716 attr.FFTAttribute(inverse, local_bound)
Luke Hutton57287132023-02-06 14:54:18 +00002717
2718 self.ser.addOperator(op["op"], input_names, output_names, attr)
Jeremy Johnsonc8330812024-01-18 16:57:28 +00002719
2720 compliance = []
2721 for res in results:
2722 compliance.append(
2723 self.tensorComplianceMetaData(
2724 op, val1.dtype, args_dict, res, error_name
2725 )
2726 )
2727
2728 return TosaTestGen.BuildInfo(results, compliance)
Luke Hutton57287132023-02-06 14:54:18 +00002729
Tai Lyd3797f02023-11-15 23:06:19 +00002730 def build_rfft2d(
2731 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002732 rng,
Tai Lyd3797f02023-11-15 23:06:19 +00002733 op,
Jeremy Johnson6f57e6e2024-01-30 16:10:50 +00002734 inputs,
2735 args_dict,
Tai Lyd3797f02023-11-15 23:06:19 +00002736 validator_fcns=None,
2737 error_name=None,
Jeremy Johnson6f57e6e2024-01-30 16:10:50 +00002738 qinfo=None,
Tai Lyd3797f02023-11-15 23:06:19 +00002739 ):
Jeremy Johnson6f57e6e2024-01-30 16:10:50 +00002740 assert len(inputs) == 1
2741 val = inputs[0]
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002742 results = OutputShaper.rfft2dOp(self.ser, rng, val, error_name)
Luke Hutton261b7b62023-01-10 14:50:31 +00002743
2744 input_names = [val.name]
2745 pCount, cCount = op["operands"]
2746 num_operands = pCount + cCount
2747
2748 output_names = [res.name for res in results]
Luke Hutton57287132023-02-06 14:54:18 +00002749 output_shapes = [res.shape for res in results]
Luke Hutton261b7b62023-01-10 14:50:31 +00002750 output_dtypes = [res.dtype for res in results]
2751
2752 input_names, output_names = TosaErrorIfArgGen.eiInvalidateInputOutputList(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002753 rng, error_name, input_names, output_names
Luke Hutton261b7b62023-01-10 14:50:31 +00002754 )
2755
2756 if not TosaErrorValidator.evValidateErrorIfs(
2757 self.ser,
2758 validator_fcns,
2759 error_name,
2760 op=op,
2761 input_shape=val.shape,
2762 input_dtype=val.dtype,
Luke Hutton57287132023-02-06 14:54:18 +00002763 output_shape=output_shapes,
Luke Hutton261b7b62023-01-10 14:50:31 +00002764 output_dtype=output_dtypes,
2765 result_tensors=results,
2766 input_list=input_names,
2767 output_list=output_names,
2768 num_operands=num_operands,
2769 ):
2770 return None
2771
Tai Lyd3797f02023-11-15 23:06:19 +00002772 # TODO - Test local_bound, for now set local bound attribute to False
2773 local_bound = False
2774
2775 attr = ts.TosaSerializerAttribute()
2776 attr.RFFTAttribute(local_bound)
2777
2778 self.ser.addOperator(op["op"], input_names, output_names, attr)
Jeremy Johnson6f57e6e2024-01-30 16:10:50 +00002779
2780 compliance = []
2781 for res in results:
2782 compliance.append(
2783 self.tensorComplianceMetaData(op, val.dtype, args_dict, res, error_name)
2784 )
2785
2786 return TosaTestGen.BuildInfo(results, compliance)
Luke Hutton261b7b62023-01-10 14:50:31 +00002787
Won Jeon74342e52024-01-09 00:34:40 +00002788 def build_shape_op(
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002789 self,
2790 rng,
2791 op,
2792 inputs,
2793 args_dict,
2794 validator_fcns=None,
2795 error_name=None,
2796 qinfo=None,
Won Jeon74342e52024-01-09 00:34:40 +00002797 ):
2798 assert len(inputs) == 2
2799 a, b = inputs
2800
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002801 result_tensor = OutputShaper.addShapeOp(self.ser, rng, a, b, error_name)
Won Jeon74342e52024-01-09 00:34:40 +00002802
2803 # Invalidate Input/Output list for error if checks.
2804 input_list = [a.name, b.name]
2805 output_list = [result_tensor.name]
2806 pCount, cCount = op["operands"]
2807 num_operands = pCount + cCount
2808 input_list, output_list = TosaErrorIfArgGen.eiInvalidateInputOutputList(
2809 self, error_name, input_list, output_list
2810 )
2811
2812 if not TosaErrorValidator.evValidateErrorIfs(
2813 self.ser,
2814 validator_fcns,
2815 error_name,
2816 op=op,
2817 input1=a,
2818 input2=b,
2819 input_shape=a.shape,
2820 input_dtype=a.dtype,
2821 output_shape=result_tensor.shape,
2822 output_dtype=result_tensor.dtype,
2823 result_tensors=[result_tensor],
2824 input_list=input_list,
2825 output_list=output_list,
2826 num_operands=num_operands,
2827 ):
2828 return None
2829
2830 self.ser.addOperator(
2831 op["op"],
2832 input_list,
2833 output_list,
2834 )
2835 compliance = self.tensorComplianceMetaData(
2836 op, a.dtype, args_dict, result_tensor, error_name
2837 )
2838
2839 return TosaTestGen.BuildInfo(result_tensor, compliance)
2840
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002841 def create_filter_lists(
2842 self, op, shapeFilter, rankFilter, dtypeFilter, testType, validator=None
2843 ):
Jeremy Johnson18a379d2024-03-28 15:53:21 +00002844 # Create a default testing rank range
2845 if testType == "positive":
2846 # 0-3 inclusive to keep test sizes reasonably small.
2847 default_test_rank_range = range(0, 4)
2848 else:
2849 # Some errors do not work with rank 0, use 1-3
2850 default_test_rank_range = range(1, 4)
Matthew Haddon1c00b712021-10-01 15:51:03 +01002851
2852 # Calculate the filters based on what is requested and what the operator allows
2853 rmin, rmax = op["rank"]
Jeremy Johnson18a379d2024-03-28 15:53:21 +00002854
2855 if shapeFilter:
2856 # Specified shapes - ignore rank filter and default to op ranks below
2857 rankFilter = None
2858 ranksToCheck = []
2859 elif rankFilter is None:
2860 # No set rank filter so ensure default behaviour is bounded
2861 ranksToCheck = default_test_rank_range
Matthew Haddon1c00b712021-10-01 15:51:03 +01002862 else:
Jeremy Johnson18a379d2024-03-28 15:53:21 +00002863 ranksToCheck = rankFilter
2864
2865 cleanRankFilter = []
2866 # Ensure rank values are allowed by operator
2867 for rank in ranksToCheck:
2868 if rank >= rmin and rank <= rmax:
2869 cleanRankFilter.append(rank)
2870
2871 if shapeFilter or (len(cleanRankFilter) == 0 and rankFilter is None):
2872 # Shapes specified or default test ranks didn't meet
2873 # op requirements - so just use op ranks
Matthew Haddon1c00b712021-10-01 15:51:03 +01002874 cleanRankFilter = range(rmin, rmax + 1)
2875
2876 dtypes = op["types"]
Matthew Haddonb6b59e32021-10-07 17:19:20 +01002877
Matthew Haddon1c00b712021-10-01 15:51:03 +01002878 if dtypeFilter is not None:
2879 cleanDtypeFilter = []
Jeremy Johnson03bec732021-10-07 12:06:00 +01002880 # Create list of operator dtypes filtered by requested dtypes
2881 for dtype in dtypes:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002882 if dtype in dtypeFilter or (
2883 isinstance(dtype, list) and dtype[0] in dtypeFilter
2884 ):
Matthew Haddon1c00b712021-10-01 15:51:03 +01002885 cleanDtypeFilter.append(dtype)
2886 else:
2887 cleanDtypeFilter = dtypes
2888
Jeremy Johnson18a379d2024-03-28 15:53:21 +00002889 if not shapeFilter:
2890 shapeFilter = [None]
2891
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002892 if testType == "positive":
Matthew Haddon1c00b712021-10-01 15:51:03 +01002893 filterDict = {
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002894 "shapeFilter": shapeFilter,
2895 "rankFilter": cleanRankFilter,
2896 "dtypeFilter": cleanDtypeFilter,
Matthew Haddon1c00b712021-10-01 15:51:03 +01002897 }
2898 return filterDict
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002899 elif testType == "negative":
Matthew Haddone807aae2021-10-11 18:12:58 +01002900 if validator is not None:
2901 validator_info = validator(check=False, op=op)
2902 else:
2903 return None
2904
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002905 error_arguments = validator_info["param_reqs"]
Matthew Haddon1c00b712021-10-01 15:51:03 +01002906
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002907 # Set parameters as required
2908 if error_arguments["rank"] is not None:
2909 rankFilter = error_arguments["rank"]
Matthew Haddon1c00b712021-10-01 15:51:03 +01002910 else:
2911 rankFilter = cleanRankFilter
2912
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002913 if error_arguments["dtype"] is not None:
2914 dtypeFilter = error_arguments["dtype"]
Matthew Haddon1c00b712021-10-01 15:51:03 +01002915 else:
2916 dtypeFilter = cleanDtypeFilter
2917
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002918 if error_arguments["shape"] is not None:
2919 shapeFilter = error_arguments["shape"]
Matthew Haddon1c00b712021-10-01 15:51:03 +01002920 else:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002921 shapeFilter = shapeFilter[
2922 :2
2923 ] # Reduce number of shapes to keep test numbers small
Matthew Haddon1c00b712021-10-01 15:51:03 +01002924
2925 filterDict = {
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002926 "shapeFilter": shapeFilter,
2927 "rankFilter": rankFilter,
2928 "dtypeFilter": dtypeFilter,
Matthew Haddon1c00b712021-10-01 15:51:03 +01002929 }
2930 return filterDict
2931
Kevin Cheng550ccc52021-03-03 11:21:43 -08002932 def genOpTestList(
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002933 self,
2934 opName,
2935 shapeFilter=[None],
2936 rankFilter=None,
2937 dtypeFilter=None,
2938 testType="positive",
Kevin Cheng550ccc52021-03-03 11:21:43 -08002939 ):
Eric Kunzee5e26762020-10-13 16:11:07 -07002940
2941 try:
2942 op = self.TOSA_OP_LIST[opName]
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002943 except KeyError:
Kevin Cheng550ccc52021-03-03 11:21:43 -08002944 raise Exception("Cannot find op with name {}".format(opName))
Eric Kunzee5e26762020-10-13 16:11:07 -07002945
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002946 if not self.args.stable_rng:
2947 # Initialize a new random number generator per op
2948 self.resetGlobalRNG()
Eric Kunzee5e26762020-10-13 16:11:07 -07002949
Jeremy Johnson1271c442023-09-05 11:39:26 +01002950 _, tgen_fcn, _, agen_fcn = op["build_fcn"]
Eric Kunzee5e26762020-10-13 16:11:07 -07002951
Eric Kunzee5e26762020-10-13 16:11:07 -07002952 # Test list consists of a tuple of:
2953 # (opName, testNameStr, dtype, shapeList, argumentsList)
2954 testList = []
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002955 if testType == "negative" and "error_if_validators" in op:
Matthew Haddon1c00b712021-10-01 15:51:03 +01002956 error_if_validators = op["error_if_validators"]
Jeremy Johnsondd975b82024-02-28 17:29:13 +00002957 num_error_types_created = 0
Matthew Haddon1c00b712021-10-01 15:51:03 +01002958 else:
2959 error_if_validators = [None]
Jeremy Johnsondd975b82024-02-28 17:29:13 +00002960 num_error_types_created = None
Eric Kunzee5e26762020-10-13 16:11:07 -07002961
Matthew Haddon1c00b712021-10-01 15:51:03 +01002962 for validator in error_if_validators:
2963 if validator is not None:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002964 error_name = validator(check=False, op=op)["error_name"]
Matthew Haddon1c00b712021-10-01 15:51:03 +01002965 else:
2966 error_name = None
2967
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002968 filterDict = self.create_filter_lists(
2969 op, shapeFilter, rankFilter, dtypeFilter, testType, validator
2970 )
2971 if filterDict is None:
Matthew Haddone807aae2021-10-11 18:12:58 +01002972 return []
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00002973 cleanRankFilter = filterDict["rankFilter"]
2974 cleanDtypeFilter = filterDict["dtypeFilter"]
2975 cleanShapeFilter = filterDict["shapeFilter"]
Jeremy Johnsonaf090182024-02-13 18:25:39 +00002976 logger.debug(
2977 f"genOpTestList: Error={error_name}, Filters S={cleanShapeFilter}, R={cleanRankFilter}, T={cleanDtypeFilter}"
2978 )
Matthew Haddon1c00b712021-10-01 15:51:03 +01002979
2980 for r in cleanRankFilter:
Matthew Haddon1c00b712021-10-01 15:51:03 +01002981 for t in cleanDtypeFilter:
2982 for shape in cleanShapeFilter:
Matthew Haddon74567092021-07-16 15:38:20 +01002983 # Filter out by rank
2984 if shape is not None and len(shape) != r:
2985 continue
Matthew Haddon74567092021-07-16 15:38:20 +01002986 self.setTargetShape(shape)
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01002987 typeStr = self.typeStr(t)
2988 if self.args.stable_rng:
2989 shape_rng = TosaHashRandomGenerator(
2990 self.random_seed,
2991 [opName, r, typeStr],
2992 self.random_dtype_range,
2993 )
2994 else:
2995 shape_rng = self.global_rng
2996 shapeList = tgen_fcn(self, shape_rng, op, r, error_name)
Eric Kunzee5e26762020-10-13 16:11:07 -07002997
Matthew Haddon74567092021-07-16 15:38:20 +01002998 shapeStr = self.shapeStr(shapeList[0])
Eric Kunzee5e26762020-10-13 16:11:07 -07002999
Matthew Haddon74567092021-07-16 15:38:20 +01003000 # Argument lists consists of tuples of the (str, []) string representation and the build function argument list
3001 argList = []
3002 if agen_fcn:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01003003 if self.args.stable_rng:
3004 arg_rng = TosaHashRandomGenerator(
3005 self.random_seed,
3006 [opName, shapeStr, typeStr],
3007 self.random_dtype_range,
3008 )
3009 else:
3010 arg_rng = self.global_rng
3011
3012 argList = agen_fcn(
3013 self, arg_rng, opName, shapeList, t, error_name
3014 )
Eric Kunzee5e26762020-10-13 16:11:07 -07003015 else:
Matthew Haddon74567092021-07-16 15:38:20 +01003016 argList = [("", [])]
Eric Kunzee5e26762020-10-13 16:11:07 -07003017
Matthew Haddon74567092021-07-16 15:38:20 +01003018 for argStr, args in argList:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01003019 # Create the test name string - for example: add_1x2x3_i32
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003020 if testType == "positive":
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01003021 name_parts = [opName, shapeStr, typeStr]
3022 else:
3023 assert testType == "negative"
3024 name_parts = [
3025 opName,
3026 "ERRORIF",
3027 error_name,
3028 shapeStr,
3029 typeStr,
3030 ]
3031 if argStr:
3032 name_parts.append(argStr)
3033 testStr = "_".join(name_parts)
Matthew Haddon1c00b712021-10-01 15:51:03 +01003034
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003035 testList.append(
3036 (opName, testStr, t, error_name, shapeList, args)
3037 )
Jeremy Johnsondd975b82024-02-28 17:29:13 +00003038 if error_name is not None:
3039 # Check the last test is of the error we wanted
3040 if len(testList) == 0 or testList[-1][3] != error_name:
3041 if self.args.level8k:
3042 logger.info(f"Missing {error_name} tests due to level8k mode")
3043 else:
3044 logger.error(f"ERROR: Failed to create any {error_name} tests")
3045 logger.debug(
3046 "Last test created: {}".format(
3047 testList[-1] if testList else None
3048 )
3049 )
3050 else:
3051 # Successfully created at least one ERRROR_IF test
3052 num_error_types_created += 1
Matthew Haddon1c00b712021-10-01 15:51:03 +01003053
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003054 if testType == "positive":
Matthew Haddon1c00b712021-10-01 15:51:03 +01003055 # Remove tests which are expected to fail but don't correlate to a ERROR_IF statement
3056 if "invalid_test_validators" in op:
3057 invalid_test_validators = op["invalid_test_validators"]
3058 clean_testList = []
3059 for test in testList:
Jeremy Johnson0c716862023-04-13 17:18:19 +01003060 remove_test = False
Matthew Haddon1c00b712021-10-01 15:51:03 +01003061 for validator_fcn in invalid_test_validators:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003062 if validator_fcn(
3063 opName=test[0],
3064 input_dtype=test[2],
3065 shapeList=test[4],
3066 args=test[5],
3067 ):
Matthew Haddon1c00b712021-10-01 15:51:03 +01003068 remove_test = True
3069 if not remove_test:
3070 clean_testList.append(test)
3071 testList = clean_testList
Jeremy Johnsondd975b82024-02-28 17:29:13 +00003072 else:
3073 if num_error_types_created is not None and not self.args.level8k:
3074 remaining_error_types = (
3075 len(error_if_validators) - num_error_types_created
3076 )
3077 if remaining_error_types:
3078 raise Exception(
3079 f"Failed to create {remaining_error_types} error types for {opName}"
3080 )
Eric Kunzee5e26762020-10-13 16:11:07 -07003081
3082 return testList
3083
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003084 def serializeTest(
Jeremy Johnson587cc842024-02-08 11:45:44 +00003085 self, opName, testStr, dtype_or_dtypeList, error_name, shapeList, argsDict
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003086 ):
Eric Kunzee5e26762020-10-13 16:11:07 -07003087 try:
3088 op = self.TOSA_OP_LIST[opName]
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003089 except KeyError:
Kevin Cheng550ccc52021-03-03 11:21:43 -08003090 raise Exception("Cannot find op with name {}".format(opName))
Eric Kunzee5e26762020-10-13 16:11:07 -07003091
Jeremy Johnsonaf090182024-02-13 18:25:39 +00003092 logger.info(f"Creating {testStr}")
Jeremy Johnson0c716862023-04-13 17:18:19 +01003093
Eric Kunzee5e26762020-10-13 16:11:07 -07003094 # Create a serializer
3095 self.createSerializer(opName, testStr)
3096
Jeremy Johnson1271c442023-09-05 11:39:26 +01003097 build_fcn, _, tvgen_fcn, _ = op["build_fcn"]
Matthew Haddone86fd342021-09-07 16:12:21 +01003098 if "error_if_validators" in op:
3099 error_if_validators = op["error_if_validators"]
3100 else:
3101 error_if_validators = None
3102
Kevin Cheng550ccc52021-03-03 11:21:43 -08003103 pCount, cCount = op["operands"]
Kevin Cheng989cb052021-04-28 16:29:44 -07003104 num_operands = pCount + cCount
3105
3106 if isinstance(dtype_or_dtypeList, list):
3107 dtypeList = dtype_or_dtypeList
Won Jeon74342e52024-01-09 00:34:40 +00003108 elif op["op"] in (Op.CONCAT, Op.CONCAT_SHAPE):
Matthew Haddon818ab902021-07-27 09:12:49 +01003109 dtypeList = [dtype_or_dtypeList] * len(shapeList)
Kevin Cheng989cb052021-04-28 16:29:44 -07003110 else:
3111 dtypeList = [dtype_or_dtypeList] * (num_operands)
3112
Won Jeon74342e52024-01-09 00:34:40 +00003113 if op["op"] not in (Op.CONCAT, Op.CONCAT_SHAPE):
Matthew Haddon818ab902021-07-27 09:12:49 +01003114 assert (
3115 len(shapeList) == num_operands
3116 ), "shapeList length {} must match number of operands {}".format(
3117 len(shapeList), num_operands
3118 )
3119 assert (
3120 len(dtypeList) == num_operands
3121 ), "dtypeList length {} must match number of operands {}".format(
3122 len(dtypeList), num_operands
3123 )
Eric Kunzee5e26762020-10-13 16:11:07 -07003124
3125 try:
Kevin Cheng550ccc52021-03-03 11:21:43 -08003126 qgen = op["qgen"]
Eric Kunzee5e26762020-10-13 16:11:07 -07003127 except KeyError:
3128 qgen = None
3129
3130 # Build the random tensor operands and the test
Kevin Chengaee1fac2020-11-11 13:54:06 -08003131
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01003132 # Set the random number generator
3133 if self.args.stable_rng:
3134 build_rng = TosaHashRandomGenerator(
3135 self.random_seed, [testStr], self.random_dtype_range
3136 )
3137 else:
3138 build_rng = self.global_rng
3139
Matthew Haddon1c00b712021-10-01 15:51:03 +01003140 if qgen is not None:
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01003141 qinfo = qgen(
3142 build_rng, self.args.zeropoint, op, dtype_or_dtypeList, error_name
3143 )
Matthew Haddon1c00b712021-10-01 15:51:03 +01003144 else:
3145 qinfo = None
3146
Jeremy Johnson1271c442023-09-05 11:39:26 +01003147 # Extra meta data for the desc.json
3148 tensMeta = {}
3149
Jeremy Johnson587cc842024-02-08 11:45:44 +00003150 # Check we are using the new interface with an argsDict dictionary
3151 assert isinstance(
3152 argsDict, dict
3153 ), f"{opName} is not using new tvg/build_fcn interface"
Jeremy Johnsond41feb72023-10-12 16:03:15 +01003154
Jeremy Johnson587cc842024-02-08 11:45:44 +00003155 # New interface with args info in dictionary
3156 assert "dg_type" in argsDict
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01003157 tvgInfo = tvgen_fcn(
3158 self, build_rng, opName, dtypeList, shapeList, argsDict, error_name
3159 )
Jeremy Johnson587cc842024-02-08 11:45:44 +00003160 if tvgInfo.dataGenDict:
3161 tensMeta["data_gen"] = tvgInfo.dataGenDict
3162 tens = tvgInfo.tensorList
Jeremy Johnson81ee53d2022-03-23 15:32:34 +00003163
evacha01ad8e1e22024-03-19 12:42:17 +00003164 tags = argsDict.get("tags", None)
3165
Jeremy Johnson587cc842024-02-08 11:45:44 +00003166 result = build_fcn(
3167 self,
Jeremy Johnson0a6d1de2023-09-27 14:59:43 +01003168 build_rng,
Jeremy Johnson587cc842024-02-08 11:45:44 +00003169 op,
3170 tens,
3171 argsDict,
3172 validator_fcns=error_if_validators,
3173 error_name=error_name,
3174 qinfo=qinfo,
3175 )
Matthew Haddon1c00b712021-10-01 15:51:03 +01003176
Jeremy Johnson1271c442023-09-05 11:39:26 +01003177 if result:
Les Bell729b0352021-11-24 10:28:21 +00003178 # The test is valid, serialize it
Jeremy Johnsonc8330812024-01-18 16:57:28 +00003179 if isinstance(result, TosaTestGen.BuildInfo):
3180 # Add the compliance meta data (if any)
3181 compliance = result.getComplianceInfo()
3182 if compliance:
3183 tensMeta["compliance"] = compliance
evacha01ad8e1e22024-03-19 12:42:17 +00003184 self.serialize("test", tensMeta, tags)
Jeremy Johnsondd975b82024-02-28 17:29:13 +00003185 return True
Les Bell729b0352021-11-24 10:28:21 +00003186 else:
3187 # The test is not valid
Jeremy Johnsonaf090182024-02-13 18:25:39 +00003188 logger.error(f"Invalid ERROR_IF test created: {opName} {testStr}")
Jeremy Johnsondd975b82024-02-28 17:29:13 +00003189 return False
Matthew Haddon1c00b712021-10-01 15:51:03 +01003190
Eric Kunzee5e26762020-10-13 16:11:07 -07003191 def createDynamicOpLists(self):
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003192 # Find all the ops marked as templates
3193 templateKeys = []
3194 for opName in self.TOSA_OP_LIST:
Eric Kunzee5e26762020-10-13 16:11:07 -07003195 try:
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003196 if self.TOSA_OP_LIST[opName]["template"]:
3197 templateKeys.append(opName)
Eric Kunzee5e26762020-10-13 16:11:07 -07003198 except KeyError:
3199 pass
3200
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003201 bigK = self.TOSA_8K_LEVEL_MAX_KERNEL
3202
3203 # Add dynamic ops based on kernel sizes
3204 for opName in templateKeys:
3205 assert opName.endswith("_TEMPLATE"), "Found incorrect template"
3206 realName = opName[: len(opName) - len("_TEMPLATE")]
3207 template = self.TOSA_OP_LIST[opName]
3208 k_rank = 3 if realName == "conv3d" else 2
3209
3210 # Choose kernels to build tests for from the template or args
3211 if self.args.level8k:
3212 if k_rank == 3:
3213 kernels = [[1, bigK, 1], [2, 2, bigK]]
3214 else:
3215 kernels = [[1, bigK], [bigK, 2]]
3216 else:
3217 kernels = []
3218 if len(self.args.conv_kernels) > 0:
3219 kernels = [k for k in self.args.conv_kernels if len(k) == k_rank]
3220 if len(kernels) == 0:
3221 logger.debug(
3222 f"{realName} op using defaults as no rank {k_rank} kernels found in {self.args.conv_kernels}"
3223 )
3224 if len(kernels) == 0:
3225 # Fallback to use the defined template kernels
3226 kernels = self.TOSA_OP_LIST[opName]["filter"]
3227
3228 # Dynamically create ops for listed kernel sizes
3229 for k in kernels:
3230 kernelStr = "x".join([str(d) for d in k])
3231 testName = f"{realName}_{kernelStr}"
3232 kernelOp = template.copy()
3233 kernelOp["filter"] = k
3234 kernelOp["template"] = False
3235 kernelOp["real_name"] = realName
3236 self.TOSA_OP_LIST[testName] = kernelOp
3237
3238 # Delete the template after having created the dynamic ops
3239 del self.TOSA_OP_LIST[opName]
Eric Kunzee5e26762020-10-13 16:11:07 -07003240
3241 def initOpListDefaults(self):
Kevin Cheng550ccc52021-03-03 11:21:43 -08003242 """Fill in default fields for ops if they aren't already specified.
3243 Look for missing required fields (datastructure linting)."""
Eric Kunzee5e26762020-10-13 16:11:07 -07003244 for op in self.TOSA_OP_LIST:
3245
3246 # Required fields
3247 try:
Kevin Cheng550ccc52021-03-03 11:21:43 -08003248 pl, c = self.TOSA_OP_LIST[op]["operands"]
Eric Kunzee5e26762020-10-13 16:11:07 -07003249 except (KeyError, ValueError, TypeError):
Kevin Cheng550ccc52021-03-03 11:21:43 -08003250 raise Exception(
3251 "Op {} is missing a valid operand tuple in TOSA_OP_LIST".format(op)
3252 )
Eric Kunzee5e26762020-10-13 16:11:07 -07003253
3254 try:
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003255 fcn, tgen, tvgen, arggen = self.TOSA_OP_LIST[op]["build_fcn"]
Eric Kunzee5e26762020-10-13 16:11:07 -07003256 except (KeyError, ValueError, TypeError):
Kevin Cheng550ccc52021-03-03 11:21:43 -08003257 raise Exception(
3258 "Op {} is missing a valid build_fcn tuple in TOSA_OP_LIST".format(
3259 op
3260 )
3261 )
Eric Kunzee5e26762020-10-13 16:11:07 -07003262
3263 try:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003264 _ = self.TOSA_OP_LIST[op]["types"]
3265 except KeyError:
Kevin Cheng550ccc52021-03-03 11:21:43 -08003266 raise Exception(
3267 "Op {} is missing a valid type list in TOSA_OP_LIST".format(op)
3268 )
Eric Kunzee5e26762020-10-13 16:11:07 -07003269
3270 try:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003271 _ = self.TOSA_OP_LIST[op]["op"]
3272 except KeyError:
Kevin Cheng550ccc52021-03-03 11:21:43 -08003273 raise Exception(
3274 "Op {} is missing the Op field in TOSA_OP_LIST".format(op)
3275 )
Eric Kunzee5e26762020-10-13 16:11:07 -07003276
3277 # Put in default rank range, if missing
3278 try:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003279 _ = self.TOSA_OP_LIST[op]["rank"]
Eric Kunzee5e26762020-10-13 16:11:07 -07003280 except KeyError:
Kevin Cheng550ccc52021-03-03 11:21:43 -08003281 self.TOSA_OP_LIST[op]["rank"] = self.DEFAULT_RANK_RANGE
Eric Kunzee5e26762020-10-13 16:11:07 -07003282
3283 # Tensor operator list
3284 # 'op': op name
3285 # 'operands': tuple of (placeholder, const) operands
Kevin Cheng3a478572021-01-22 17:21:02 -08003286 # 'rank': optional, restricts rank to tuple inclusive of (min, max),
3287 # if not specified, defaults to (1, 4)
Eric Kunzee5e26762020-10-13 16:11:07 -07003288 # 'build_fcn': tuple of the function to (build_operator(), TensorGen function, ArgGen enum)
3289 # 'types': array of datatypes to be tested
James Ward24dbc422022-10-19 12:20:31 +01003290 TYPE_FP = [DType.FP32, DType.FP16, DType.BF16]
Eric Kunzee5e26762020-10-13 16:11:07 -07003291
Kevin Cheng550ccc52021-03-03 11:21:43 -08003292 TYPE_INT = [DType.INT8, DType.INT16, DType.INT32] # Excludes INT4
James Ward8b390432022-08-12 20:48:56 +01003293 TYPE_INT_FP = [
3294 DType.INT8,
3295 DType.INT16,
3296 DType.INT32,
3297 DType.FP16,
James Ward24dbc422022-10-19 12:20:31 +01003298 DType.BF16,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01003299 DType.FP32,
James Ward8b390432022-08-12 20:48:56 +01003300 ] # Excludes INT4
Eric Kunzee5e26762020-10-13 16:11:07 -07003301
Kevin Cheng550ccc52021-03-03 11:21:43 -08003302 TYPE_BOOL = [DType.BOOL]
James Ward24dbc422022-10-19 12:20:31 +01003303 TYPE_FI32 = [
3304 DType.FP32,
3305 DType.FP16,
3306 DType.BF16,
3307 DType.INT32,
3308 ] # floating-types and INT32
James Ward8b390432022-08-12 20:48:56 +01003309 TYPE_FIB = [
3310 DType.FP16,
James Ward24dbc422022-10-19 12:20:31 +01003311 DType.BF16,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01003312 DType.FP32,
James Ward8b390432022-08-12 20:48:56 +01003313 DType.INT8,
3314 DType.INT16,
3315 DType.INT32,
3316 DType.BOOL,
3317 ]
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01003318 TYPE_FI16 = [DType.FP32, DType.INT16]
Eric Kunzee5e26762020-10-13 16:11:07 -07003319
Won Jeon2c34b462024-02-06 18:37:00 +00003320 TYPE_NARROW_INT_FP = [
3321 DType.INT8,
3322 DType.INT16,
3323 DType.FP16,
3324 DType.BF16,
3325 DType.FP32,
3326 ]
Eric Kunzee5e26762020-10-13 16:11:07 -07003327
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01003328 # List of [Input Type 1, Input Type 2, Accumulator Type]
Kevin Cheng1533b852021-09-01 12:51:58 -07003329 TYPE_CONV = [
Kevin Chenga9017402021-07-28 17:19:23 -07003330 [DType.INT8, DType.INT4, DType.INT32],
Kevin Cheng989cb052021-04-28 16:29:44 -07003331 [DType.INT8, DType.INT8, DType.INT32],
3332 [DType.INT16, DType.INT8, DType.INT48],
James Ward8b390432022-08-12 20:48:56 +01003333 [DType.FP16, DType.FP16, DType.FP16],
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01003334 [DType.FP16, DType.FP16, DType.FP32],
James Ward24dbc422022-10-19 12:20:31 +01003335 [DType.BF16, DType.BF16, DType.FP32],
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01003336 [DType.FP32, DType.FP32, DType.FP32],
Won Jeon2c34b462024-02-06 18:37:00 +00003337 [DType.FP8E4M3, DType.FP8E4M3, DType.FP16],
3338 [DType.FP8E5M2, DType.FP8E5M2, DType.FP16],
Kevin Cheng989cb052021-04-28 16:29:44 -07003339 ]
3340
Jeremy Johnson18a379d2024-03-28 15:53:21 +00003341 DEFAULT_RANK_RANGE = (0, gtu.MAX_TENSOR_RANK)
Eric Kunzee5e26762020-10-13 16:11:07 -07003342
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003343 KERNELS_2D = [[1, 1], [2, 2], [3, 3], [5, 5], [3, 1], [1, 3]]
3344 KERNELS_3D = [[1, 1, 1], [2, 1, 1], [1, 2, 1], [1, 1, 2]]
3345
evacha01ad8e1e22024-03-19 12:42:17 +00003346 PSEUDO_RANDOM_DATAGEN = {
3347 DType.FP16: (gtu.DataGenType.PSEUDO_RANDOM,),
3348 DType.FP32: (gtu.DataGenType.PSEUDO_RANDOM,),
3349 }
3350 DOT_PRODUCT_DATAGEN = {
3351 DType.FP16: (gtu.DataGenType.DOT_PRODUCT,),
3352 DType.FP32: (gtu.DataGenType.DOT_PRODUCT,),
3353 }
3354 EW_UNARY_DATAGEN = {
3355 DType.FP16: (gtu.DataGenType.PSEUDO_RANDOM, gtu.DataGenType.FULL_RANGE)
3356 }
3357
Eric Kunzee5e26762020-10-13 16:11:07 -07003358 TOSA_OP_LIST = {
Jared Smolens573ecd42021-03-04 15:24:10 -08003359 # Tensor operators
Kevin Cheng550ccc52021-03-03 11:21:43 -08003360 "argmax": {
3361 "op": Op.ARGMAX,
3362 "operands": (1, 0),
Jeremy Johnson18a379d2024-03-28 15:53:21 +00003363 "rank": (1, gtu.MAX_TENSOR_RANK),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003364 "build_fcn": (
3365 build_argmax,
3366 TosaTensorGen.tgBasic,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00003367 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003368 TosaArgGen.agAxis,
3369 ),
Won Jeon2c34b462024-02-06 18:37:00 +00003370 "types": TYPE_NARROW_INT_FP + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003371 "error_if_validators": (
3372 TosaErrorValidator.evAxisSmallerZero,
3373 TosaErrorValidator.evAxisLargerRank,
3374 TosaErrorValidator.evArgmaxOutputRankMismatch,
3375 TosaErrorValidator.evArgmaxOutputShapeMismatch,
3376 TosaErrorValidator.evWrongRank,
3377 TosaErrorValidator.evWrongInputType,
3378 TosaErrorValidator.evWrongOutputType,
3379 TosaErrorValidator.evWrongInputList,
3380 TosaErrorValidator.evWrongOutputList,
3381 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003382 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003383 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003384 "avg_pool2d": {
3385 "op": Op.AVG_POOL2D,
3386 "operands": (1, 0),
3387 "rank": (4, 4),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003388 "build_fcn": (
3389 build_pool2d,
3390 TosaTensorGen.tgNHWC,
Jeremy Johnsond41feb72023-10-12 16:03:15 +01003391 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003392 TosaArgGen.agPooling,
3393 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003394 "qgen": TosaQuantGen.qgUnary,
Won Jeon2c34b462024-02-06 18:37:00 +00003395 "types": TYPE_NARROW_INT_FP + [DType.FP8E4M3, DType.FP8E5M2],
Les Bell0e027d42021-11-09 14:42:14 +00003396 "invalid_test_validators": (TosaInvalidValidator.ivHeightWidthInvalid,),
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003397 "error_if_validators": (
3398 TosaErrorValidator.evKernelSmallerOne,
3399 TosaErrorValidator.evStrideSmallerOne,
3400 TosaErrorValidator.evPadSmallerZero,
3401 TosaErrorValidator.evWrongRank,
3402 TosaErrorValidator.evWrongInputType,
3403 TosaErrorValidator.evWrongOutputType,
3404 TosaErrorValidator.evWrongInputList,
3405 TosaErrorValidator.evWrongOutputList,
3406 TosaErrorValidator.evInputZeroPointNotZero,
3407 TosaErrorValidator.evOutputZeroPointNotZero,
3408 TosaErrorValidator.evPadLargerEqualKernel,
3409 TosaErrorValidator.evPoolingOutputShapeMismatch,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01003410 TosaErrorValidator.evPoolingOutputShapeNonInteger,
Jeremy Johnson01e1c1c2024-02-07 16:09:09 +00003411 TosaErrorValidator.evWrongAccumulatorType,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003412 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003413 "data_gen": DOT_PRODUCT_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08003414 },
Eric Kunzee5e26762020-10-13 16:11:07 -07003415 # Templated operator. Filled in by createDynamicOpLists
Kevin Cheng550ccc52021-03-03 11:21:43 -08003416 "conv2d_TEMPLATE": {
3417 "op": Op.CONV2D,
3418 "operands": (1, 2),
3419 "rank": (4, 4),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003420 "build_fcn": (
3421 build_conv2d,
3422 TosaTensorGen.tgConv2D,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +01003423 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003424 TosaArgGen.agConv,
3425 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08003426 "qgen": TosaQuantGen.qgConv,
Kevin Cheng1533b852021-09-01 12:51:58 -07003427 "types": TYPE_CONV,
Les Bell0e027d42021-11-09 14:42:14 +00003428 "invalid_test_validators": (TosaInvalidValidator.ivHeightWidthInvalid,),
3429 "error_if_validators": (
3430 TosaErrorValidator.evWrongInputType,
3431 TosaErrorValidator.evWrongOutputType,
3432 TosaErrorValidator.evWrongInputList,
3433 TosaErrorValidator.evWrongOutputList,
3434 TosaErrorValidator.evInputZeroPointNotZero,
3435 TosaErrorValidator.evWeightZeroPointNotZero,
3436 TosaErrorValidator.evPadSmallerZero,
3437 TosaErrorValidator.evStrideSmallerOne,
3438 TosaErrorValidator.evDilationSmallerOne,
3439 TosaErrorValidator.evWrongRank,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01003440 TosaErrorValidator.evConvOutputShapeMismatch,
3441 TosaErrorValidator.evConvOutputShapeNonInteger,
Tai Lyf36f2562024-03-14 16:21:29 +00003442 TosaErrorValidator.evWrongAccumulatorType,
Les Bell0e027d42021-11-09 14:42:14 +00003443 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003444 "data_gen": DOT_PRODUCT_DATAGEN,
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003445 "broadcastable_bias": True,
3446 "filter": KERNELS_2D,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003447 "template": True,
3448 },
Kevin Cheng1533b852021-09-01 12:51:58 -07003449 # Templated operator. Filled in by createDynamicOpLists
3450 "conv3d_TEMPLATE": {
3451 "op": Op.CONV3D,
3452 "operands": (1, 2),
3453 "rank": (5, 5),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003454 "build_fcn": (
3455 build_conv3d,
3456 TosaTensorGen.tgConv3D,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +01003457 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003458 TosaArgGen.agConv,
3459 ),
Kevin Cheng1533b852021-09-01 12:51:58 -07003460 "qgen": TosaQuantGen.qgConv,
3461 "types": TYPE_CONV,
Les Bell0e027d42021-11-09 14:42:14 +00003462 "invalid_test_validators": (TosaInvalidValidator.ivHeightWidthInvalid,),
3463 "error_if_validators": (
3464 TosaErrorValidator.evWrongInputType,
3465 TosaErrorValidator.evWrongOutputType,
3466 TosaErrorValidator.evWrongInputList,
3467 TosaErrorValidator.evWrongOutputList,
3468 TosaErrorValidator.evInputZeroPointNotZero,
3469 TosaErrorValidator.evWeightZeroPointNotZero,
3470 TosaErrorValidator.evPadSmallerZero,
3471 TosaErrorValidator.evStrideSmallerOne,
3472 TosaErrorValidator.evDilationSmallerOne,
3473 TosaErrorValidator.evWrongRank,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01003474 TosaErrorValidator.evConvOutputShapeMismatch,
3475 TosaErrorValidator.evConvOutputShapeNonInteger,
Tai Lyf36f2562024-03-14 16:21:29 +00003476 TosaErrorValidator.evWrongAccumulatorType,
Les Bell0e027d42021-11-09 14:42:14 +00003477 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003478 "data_gen": DOT_PRODUCT_DATAGEN,
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003479 "filter": KERNELS_3D,
Kevin Cheng1533b852021-09-01 12:51:58 -07003480 "template": True,
3481 },
Eric Kunzee5e26762020-10-13 16:11:07 -07003482 # Templated operator. Filled in by createDynamicOpLists
Kevin Cheng550ccc52021-03-03 11:21:43 -08003483 "depthwise_conv2d_TEMPLATE": {
3484 "op": Op.DEPTHWISE_CONV2D,
3485 "operands": (1, 2),
Kevin Cheng550ccc52021-03-03 11:21:43 -08003486 "rank": (4, 4),
3487 "build_fcn": (
3488 build_depthwise_conv2d,
3489 TosaTensorGen.tgDepthwiseConv2D,
Jeremy Johnsond1a08ce2023-10-18 17:22:21 +01003490 TosaTensorValuesGen.tvgLazyGenDefault,
Les Bell7aa69f42021-09-20 10:44:07 +01003491 TosaArgGen.agConv,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003492 ),
3493 "qgen": TosaQuantGen.qgConv,
Kevin Cheng1533b852021-09-01 12:51:58 -07003494 "types": TYPE_CONV,
Les Bell0e027d42021-11-09 14:42:14 +00003495 "invalid_test_validators": (TosaInvalidValidator.ivHeightWidthInvalid,),
3496 "error_if_validators": (
3497 TosaErrorValidator.evWrongInputType,
3498 TosaErrorValidator.evWrongOutputType,
3499 TosaErrorValidator.evWrongInputList,
3500 TosaErrorValidator.evWrongOutputList,
3501 TosaErrorValidator.evInputZeroPointNotZero,
3502 TosaErrorValidator.evWeightZeroPointNotZero,
3503 TosaErrorValidator.evPadSmallerZero,
3504 TosaErrorValidator.evStrideSmallerOne,
3505 TosaErrorValidator.evDilationSmallerOne,
3506 TosaErrorValidator.evWrongRank,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01003507 TosaErrorValidator.evConvOutputShapeMismatch,
3508 TosaErrorValidator.evConvOutputShapeNonInteger,
Tai Lyf36f2562024-03-14 16:21:29 +00003509 TosaErrorValidator.evWrongAccumulatorType,
Les Bell0e027d42021-11-09 14:42:14 +00003510 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003511 "data_gen": DOT_PRODUCT_DATAGEN,
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003512 "filter": KERNELS_2D,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003513 "template": True,
3514 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003515 "fully_connected": {
3516 "op": Op.FULLY_CONNECTED,
3517 "operands": (1, 2),
3518 "rank": (2, 2),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003519 "build_fcn": (
3520 build_fully_connected,
3521 TosaTensorGen.tgFullyConnected,
Jeremy Johnson30476252023-11-20 16:15:30 +00003522 TosaTensorValuesGen.tvgFullyConnected,
James Ward8b390432022-08-12 20:48:56 +01003523 TosaArgGen.agFullyConnected,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003524 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003525 "qgen": TosaQuantGen.qgConv,
Kevin Cheng1533b852021-09-01 12:51:58 -07003526 "types": TYPE_CONV,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003527 "error_if_validators": (
3528 TosaErrorValidator.evInputZeroPointNotZero,
3529 TosaErrorValidator.evWeightZeroPointNotZero,
3530 TosaErrorValidator.evWrongRank,
3531 TosaErrorValidator.evWrongInputType,
3532 TosaErrorValidator.evWrongOutputType,
3533 TosaErrorValidator.evWrongInputList,
3534 TosaErrorValidator.evWrongOutputList,
3535 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003536 "data_gen": DOT_PRODUCT_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08003537 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003538 "matmul": {
3539 "op": Op.MATMUL,
3540 "operands": (2, 0),
Kevin Cheng2d60f002021-06-09 14:18:32 -07003541 "rank": (3, 3),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003542 "build_fcn": (
3543 build_matmul,
3544 TosaTensorGen.tgMatmul,
Jeremy Johnson1271c442023-09-05 11:39:26 +01003545 TosaTensorValuesGen.tvgLazyGenDefault,
James Ward8b390432022-08-12 20:48:56 +01003546 TosaArgGen.agMatMul,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003547 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003548 "qgen": TosaQuantGen.qgMatmul,
Won Jeon2c34b462024-02-06 18:37:00 +00003549 "types": TYPE_NARROW_INT_FP + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003550 "error_if_validators": (
3551 TosaErrorValidator.evInputZeroPointNotZero,
3552 TosaErrorValidator.evWrongRank,
3553 TosaErrorValidator.evWrongInputType,
3554 TosaErrorValidator.evWrongOutputType,
3555 TosaErrorValidator.evWrongInputList,
3556 TosaErrorValidator.evWrongOutputList,
3557 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003558 "data_gen": DOT_PRODUCT_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08003559 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003560 "max_pool2d": {
3561 "op": Op.MAX_POOL2D,
3562 "operands": (1, 0),
3563 "rank": (4, 4),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003564 "build_fcn": (
Jeremy Johnson0601f802023-11-08 16:28:09 +00003565 build_pool2d,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003566 TosaTensorGen.tgNHWC,
Jeremy Johnsond41feb72023-10-12 16:03:15 +01003567 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003568 TosaArgGen.agPooling,
3569 ),
Won Jeon2c34b462024-02-06 18:37:00 +00003570 "types": TYPE_NARROW_INT_FP + [DType.FP8E4M3, DType.FP8E5M2],
Les Bell0e027d42021-11-09 14:42:14 +00003571 "invalid_test_validators": (TosaInvalidValidator.ivHeightWidthInvalid,),
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003572 "error_if_validators": (
3573 TosaErrorValidator.evKernelSmallerOne,
3574 TosaErrorValidator.evStrideSmallerOne,
3575 TosaErrorValidator.evPadSmallerZero,
3576 TosaErrorValidator.evWrongRank,
3577 TosaErrorValidator.evWrongInputType,
3578 TosaErrorValidator.evWrongOutputType,
3579 TosaErrorValidator.evWrongInputList,
3580 TosaErrorValidator.evWrongOutputList,
3581 TosaErrorValidator.evPadLargerEqualKernel,
3582 TosaErrorValidator.evPoolingOutputShapeMismatch,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01003583 TosaErrorValidator.evPoolingOutputShapeNonInteger,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003584 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003585 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08003586 },
Eric Kunzee5e26762020-10-13 16:11:07 -07003587 # Templated operator. Filled in by createDynamicOpLists
Kevin Cheng550ccc52021-03-03 11:21:43 -08003588 "transpose_conv2d_TEMPLATE": {
3589 "op": Op.TRANSPOSE_CONV2D,
Kevin Cheng989cb052021-04-28 16:29:44 -07003590 "operands": (1, 2),
Kevin Cheng550ccc52021-03-03 11:21:43 -08003591 "rank": (4, 4),
3592 "build_fcn": (
3593 build_transpose_conv2d,
3594 TosaTensorGen.tgTransposeConv2D,
Jeremy Johnson95a67102024-01-10 14:16:39 +00003595 TosaTensorValuesGen.tvgLazyGenDefault,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003596 TosaArgGen.agTransposeConv2D,
3597 ),
3598 "qgen": TosaQuantGen.qgConv,
Kevin Cheng1533b852021-09-01 12:51:58 -07003599 "types": TYPE_CONV,
Les Bell0e027d42021-11-09 14:42:14 +00003600 "invalid_test_validators": (
3601 TosaInvalidValidator.ivHeightWidthInvalid,
3602 TosaInvalidValidator.ivNonPositiveOutputShape,
3603 ),
3604 "error_if_validators": (
3605 TosaErrorValidator.evWrongInputType,
3606 TosaErrorValidator.evWrongOutputType,
3607 TosaErrorValidator.evWrongInputList,
3608 TosaErrorValidator.evWrongOutputList,
3609 TosaErrorValidator.evInputZeroPointNotZero,
3610 TosaErrorValidator.evWeightZeroPointNotZero,
Eric Kunzec1a97832022-07-01 16:56:09 -07003611 TosaErrorValidator.evPadLargerEqualKernel,
Les Bell0e027d42021-11-09 14:42:14 +00003612 TosaErrorValidator.evStrideSmallerOne,
Les Bell0e027d42021-11-09 14:42:14 +00003613 TosaErrorValidator.evWrongRank,
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01003614 TosaErrorValidator.evConvOutputShapeMismatch,
Tai Lyf36f2562024-03-14 16:21:29 +00003615 TosaErrorValidator.evWrongAccumulatorType,
Les Bell0e027d42021-11-09 14:42:14 +00003616 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003617 "data_gen": DOT_PRODUCT_DATAGEN,
Jeremy Johnson5e36bde2024-03-14 16:56:10 +00003618 "filter": KERNELS_2D,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003619 "template": True,
3620 },
Eric Kunzee5e26762020-10-13 16:11:07 -07003621 # Activation functions
Kevin Cheng550ccc52021-03-03 11:21:43 -08003622 "clamp": {
3623 "op": Op.CLAMP,
3624 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003625 "build_fcn": (
3626 build_clamp,
3627 TosaTensorGen.tgBasic,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003628 TosaTensorValuesGen.tvgLazyGenDefault,
3629 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003630 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08003631 "types": TYPE_NARROW_INT_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003632 "error_if_validators": (
3633 TosaErrorValidator.evMaxSmallerMin,
3634 TosaErrorValidator.evWrongInputType,
3635 TosaErrorValidator.evWrongOutputType,
3636 TosaErrorValidator.evWrongInputList,
3637 TosaErrorValidator.evWrongOutputList,
3638 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003639 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003640 },
Kevin Cheng550ccc52021-03-03 11:21:43 -08003641 "sigmoid": {
3642 "op": Op.SIGMOID,
3643 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003644 "build_fcn": (
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003645 build_activation,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003646 TosaTensorGen.tgBasic,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003647 TosaTensorValuesGen.tvgLazyGenDefault,
3648 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003649 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08003650 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003651 "error_if_validators": (
3652 TosaErrorValidator.evWrongInputType,
3653 TosaErrorValidator.evWrongOutputType,
3654 TosaErrorValidator.evWrongInputList,
3655 TosaErrorValidator.evWrongOutputList,
3656 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003657 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08003658 },
3659 "tanh": {
3660 "op": Op.TANH,
3661 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003662 "build_fcn": (
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003663 build_activation,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003664 TosaTensorGen.tgBasic,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003665 TosaTensorValuesGen.tvgLazyGenDefault,
3666 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003667 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08003668 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003669 "error_if_validators": (
3670 TosaErrorValidator.evWrongInputType,
3671 TosaErrorValidator.evWrongOutputType,
3672 TosaErrorValidator.evWrongInputList,
3673 TosaErrorValidator.evWrongOutputList,
3674 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003675 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jeremy Johnsond80ea5e2024-01-03 10:54:12 +00003676 "compliance": {
3677 "abs_error_lower_bound": 0.5,
3678 },
Kevin Cheng550ccc52021-03-03 11:21:43 -08003679 },
Won Jeon78155c62023-06-10 00:20:04 +00003680 "erf": {
3681 "op": Op.ERF,
3682 "operands": (1, 0),
3683 "build_fcn": (
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003684 build_activation,
Won Jeon78155c62023-06-10 00:20:04 +00003685 TosaTensorGen.tgBasic,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003686 TosaTensorValuesGen.tvgLazyGenDefault,
3687 TosaArgGen.agNone,
Won Jeon78155c62023-06-10 00:20:04 +00003688 ),
3689 "types": TYPE_FP,
3690 "error_if_validators": (
3691 TosaErrorValidator.evWrongInputType,
3692 TosaErrorValidator.evWrongOutputType,
3693 TosaErrorValidator.evWrongInputList,
3694 TosaErrorValidator.evWrongOutputList,
3695 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003696 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00003697 "compliance": {"ulp": 5},
Won Jeon78155c62023-06-10 00:20:04 +00003698 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003699 # Elementwise Binary Operators
3700 "add": {
3701 "op": Op.ADD,
3702 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003703 "build_fcn": (
3704 build_binary_broadcast,
3705 TosaTensorGen.tgBroadcastFuzz,
3706 TosaTensorValuesGen.tvgAddSub,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003707 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003708 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003709 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003710 "error_if_validators": (
3711 TosaErrorValidator.evRankMismatch,
3712 TosaErrorValidator.evWrongInputType,
3713 TosaErrorValidator.evWrongOutputType,
3714 TosaErrorValidator.evWrongInputList,
3715 TosaErrorValidator.evWrongOutputList,
3716 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003717 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003718 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003719 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003720 "compliance": {"ulp": 0.5},
Jared Smolens573ecd42021-03-04 15:24:10 -08003721 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003722 "arithmetic_right_shift": {
3723 "op": Op.ARITHMETIC_RIGHT_SHIFT,
3724 "operands": (2, 0),
3725 "build_fcn": (
3726 build_arithmetic_right_shift,
3727 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003728 TosaTensorValuesGen.tvgArithmeticRightShift,
Jared Smolens573ecd42021-03-04 15:24:10 -08003729 TosaArgGen.agArithmeticRightShift,
3730 ),
3731 "types": TYPE_INT,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003732 "error_if_validators": (
3733 TosaErrorValidator.evRankMismatch,
3734 TosaErrorValidator.evWrongInputType,
3735 TosaErrorValidator.evWrongOutputType,
3736 TosaErrorValidator.evWrongInputList,
3737 TosaErrorValidator.evWrongOutputList,
3738 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003739 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003740 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003741 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003742 "bitwise_and": {
3743 "op": Op.BITWISE_AND,
3744 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003745 "build_fcn": (
3746 build_binary_broadcast,
3747 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003748 TosaTensorValuesGen.tvgLazyGenDefault,
3749 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003750 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003751 "types": TYPE_INT,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003752 "error_if_validators": (
3753 TosaErrorValidator.evRankMismatch,
3754 TosaErrorValidator.evWrongInputType,
3755 TosaErrorValidator.evWrongOutputType,
3756 TosaErrorValidator.evWrongInputList,
3757 TosaErrorValidator.evWrongOutputList,
3758 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003759 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003760 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003761 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003762 "bitwise_or": {
3763 "op": Op.BITWISE_OR,
3764 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003765 "build_fcn": (
3766 build_binary_broadcast,
3767 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003768 TosaTensorValuesGen.tvgLazyGenDefault,
3769 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003770 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003771 "types": TYPE_INT,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003772 "error_if_validators": (
3773 TosaErrorValidator.evRankMismatch,
3774 TosaErrorValidator.evWrongInputType,
3775 TosaErrorValidator.evWrongOutputType,
3776 TosaErrorValidator.evWrongInputList,
3777 TosaErrorValidator.evWrongOutputList,
3778 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003779 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003780 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003781 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003782 "bitwise_xor": {
3783 "op": Op.BITWISE_XOR,
3784 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003785 "build_fcn": (
3786 build_binary_broadcast,
3787 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003788 TosaTensorValuesGen.tvgLazyGenDefault,
3789 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003790 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003791 "types": TYPE_INT,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003792 "error_if_validators": (
3793 TosaErrorValidator.evRankMismatch,
3794 TosaErrorValidator.evWrongInputType,
3795 TosaErrorValidator.evWrongOutputType,
3796 TosaErrorValidator.evWrongInputList,
3797 TosaErrorValidator.evWrongOutputList,
3798 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003799 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003800 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003801 },
Matthew Haddon459443c2021-08-23 16:43:13 +01003802 "intdiv": {
3803 "op": Op.INTDIV,
Kevin Cheng14d7f7a2021-05-12 10:44:49 -07003804 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003805 "build_fcn": (
3806 build_binary_broadcast,
3807 TosaTensorGen.tgBroadcastFuzz,
3808 TosaTensorValuesGen.tvgIntDiv,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003809 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003810 ),
Kevin Cheng14d7f7a2021-05-12 10:44:49 -07003811 "types": [DType.INT32],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003812 "error_if_validators": (
3813 TosaErrorValidator.evRankMismatch,
3814 TosaErrorValidator.evWrongInputType,
3815 TosaErrorValidator.evWrongOutputType,
3816 TosaErrorValidator.evWrongInputList,
3817 TosaErrorValidator.evWrongOutputList,
3818 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003819 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003820 ),
Kevin Cheng14d7f7a2021-05-12 10:44:49 -07003821 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003822 "logical_and": {
3823 "op": Op.LOGICAL_AND,
3824 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003825 "build_fcn": (
3826 build_binary_broadcast,
3827 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003828 TosaTensorValuesGen.tvgLazyGenDefault,
3829 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003830 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003831 "types": TYPE_BOOL,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003832 "error_if_validators": (
3833 TosaErrorValidator.evRankMismatch,
3834 TosaErrorValidator.evWrongInputType,
3835 TosaErrorValidator.evWrongOutputType,
3836 TosaErrorValidator.evWrongInputList,
3837 TosaErrorValidator.evWrongOutputList,
3838 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003839 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003840 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003841 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003842 "logical_left_shift": {
3843 "op": Op.LOGICAL_LEFT_SHIFT,
3844 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003845 "build_fcn": (
3846 build_binary_broadcast,
3847 TosaTensorGen.tgBroadcastFuzz,
3848 TosaTensorValuesGen.tvgLogicalShift,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003849 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003850 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003851 "types": TYPE_INT,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003852 "error_if_validators": (
3853 TosaErrorValidator.evRankMismatch,
3854 TosaErrorValidator.evWrongInputType,
3855 TosaErrorValidator.evWrongOutputType,
3856 TosaErrorValidator.evWrongInputList,
3857 TosaErrorValidator.evWrongOutputList,
3858 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003859 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003860 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003861 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003862 "logical_right_shift": {
3863 "op": Op.LOGICAL_RIGHT_SHIFT,
3864 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003865 "build_fcn": (
3866 build_binary_broadcast,
3867 TosaTensorGen.tgBroadcastFuzz,
3868 TosaTensorValuesGen.tvgLogicalShift,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003869 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003870 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003871 "types": TYPE_INT,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003872 "error_if_validators": (
3873 TosaErrorValidator.evRankMismatch,
3874 TosaErrorValidator.evWrongInputType,
3875 TosaErrorValidator.evWrongOutputType,
3876 TosaErrorValidator.evWrongInputList,
3877 TosaErrorValidator.evWrongOutputList,
3878 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003879 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003880 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003881 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003882 "logical_or": {
3883 "op": Op.LOGICAL_OR,
3884 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003885 "build_fcn": (
3886 build_binary_broadcast,
3887 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003888 TosaTensorValuesGen.tvgLazyGenDefault,
3889 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003890 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003891 "types": TYPE_BOOL,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003892 "error_if_validators": (
3893 TosaErrorValidator.evRankMismatch,
3894 TosaErrorValidator.evWrongInputType,
3895 TosaErrorValidator.evWrongOutputType,
3896 TosaErrorValidator.evWrongInputList,
3897 TosaErrorValidator.evWrongOutputList,
3898 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003899 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003900 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003901 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003902 "logical_xor": {
3903 "op": Op.LOGICAL_XOR,
3904 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003905 "build_fcn": (
3906 build_binary_broadcast,
3907 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003908 TosaTensorValuesGen.tvgLazyGenDefault,
3909 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003910 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003911 "types": TYPE_BOOL,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003912 "error_if_validators": (
3913 TosaErrorValidator.evRankMismatch,
3914 TosaErrorValidator.evWrongInputType,
3915 TosaErrorValidator.evWrongOutputType,
3916 TosaErrorValidator.evWrongInputList,
3917 TosaErrorValidator.evWrongOutputList,
3918 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003919 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003920 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003921 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003922 "maximum": {
3923 "op": Op.MAXIMUM,
3924 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003925 "build_fcn": (
3926 build_binary_broadcast,
3927 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003928 TosaTensorValuesGen.tvgLazyGenDefault,
3929 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003930 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003931 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003932 "error_if_validators": (
3933 TosaErrorValidator.evRankMismatch,
3934 TosaErrorValidator.evWrongInputType,
3935 TosaErrorValidator.evWrongOutputType,
3936 TosaErrorValidator.evWrongInputList,
3937 TosaErrorValidator.evWrongOutputList,
3938 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003939 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003940 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003941 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08003942 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003943 "minimum": {
3944 "op": Op.MINIMUM,
3945 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003946 "build_fcn": (
3947 build_binary_broadcast,
3948 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00003949 TosaTensorValuesGen.tvgLazyGenDefault,
3950 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003951 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003952 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003953 "error_if_validators": (
3954 TosaErrorValidator.evRankMismatch,
3955 TosaErrorValidator.evWrongInputType,
3956 TosaErrorValidator.evWrongOutputType,
3957 TosaErrorValidator.evWrongInputList,
3958 TosaErrorValidator.evWrongOutputList,
3959 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003960 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003961 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003962 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08003963 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003964 "mul": {
3965 "op": Op.MUL,
Jeremy Johnson0a042992024-02-28 13:20:05 +00003966 "operands": (3, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003967 "build_fcn": (
3968 build_mul,
Jeremy Johnson0a042992024-02-28 13:20:05 +00003969 TosaTensorGen.tgMul,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003970 TosaTensorValuesGen.tvgMul,
3971 TosaArgGen.agMul,
3972 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003973 "types": TYPE_INT_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003974 "error_if_validators": (
3975 TosaErrorValidator.evWrongInputType,
3976 TosaErrorValidator.evWrongOutputType,
3977 TosaErrorValidator.evWrongInputList,
3978 TosaErrorValidator.evWrongOutputList,
3979 TosaErrorValidator.evRankMismatch,
3980 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00003981 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003982 ),
evacha01ad8e1e22024-03-19 12:42:17 +00003983 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jeremy Johnsona4d907e2023-10-26 13:53:14 +01003984 "compliance": {"ulp": 0.5},
Jared Smolens573ecd42021-03-04 15:24:10 -08003985 },
Jared Smolens573ecd42021-03-04 15:24:10 -08003986 "pow": {
3987 "op": Op.POW,
3988 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003989 "build_fcn": (
3990 build_binary_broadcast,
3991 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnson30476252023-11-20 16:15:30 +00003992 TosaTensorValuesGen.tvgPow,
3993 TosaArgGen.agPow,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01003994 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08003995 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00003996 "error_if_validators": (
3997 TosaErrorValidator.evRankMismatch,
3998 TosaErrorValidator.evWrongInputType,
3999 TosaErrorValidator.evWrongOutputType,
4000 TosaErrorValidator.evWrongInputList,
4001 TosaErrorValidator.evWrongOutputList,
4002 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00004003 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004004 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004005 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004006 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004007 "sub": {
4008 "op": Op.SUB,
4009 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004010 "build_fcn": (
4011 build_binary_broadcast,
4012 TosaTensorGen.tgBroadcastFuzz,
4013 TosaTensorValuesGen.tvgAddSub,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00004014 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004015 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004016 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004017 "error_if_validators": (
4018 TosaErrorValidator.evRankMismatch,
4019 TosaErrorValidator.evWrongInputType,
4020 TosaErrorValidator.evWrongOutputType,
4021 TosaErrorValidator.evWrongInputList,
4022 TosaErrorValidator.evWrongOutputList,
4023 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00004024 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004025 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004026 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jeremy Johnson7bf0cb92023-10-31 14:37:54 +00004027 "compliance": {"ulp": 0.5},
Jared Smolens573ecd42021-03-04 15:24:10 -08004028 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004029 "table": {
4030 "op": Op.TABLE,
4031 # Use the automatic generation functions to create the input array
4032 # but create the table tensor in the build function, as it may be
4033 # a different type from the input
4034 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004035 "build_fcn": (
4036 build_table,
4037 TosaTensorGen.tgBasic,
Jeremy Johnson587cc842024-02-08 11:45:44 +00004038 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004039 TosaArgGen.agTable,
4040 ),
Jeremy Johnsonf54d8a22021-07-20 16:01:06 +01004041 "types": [DType.INT8, DType.INT16],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004042 "error_if_validators": (
4043 TosaErrorValidator.evWrongInputType,
4044 TosaErrorValidator.evWrongOutputType,
4045 TosaErrorValidator.evWrongInputList,
4046 TosaErrorValidator.evWrongOutputList,
4047 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004048 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004049 # Elementwise Unary operators
4050 "abs": {
4051 "op": Op.ABS,
4052 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004053 "build_fcn": (
4054 build_unary,
4055 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004056 TosaTensorValuesGen.tvgLazyGenDefault,
4057 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004058 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004059 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004060 "error_if_validators": (
4061 TosaErrorValidator.evWrongInputType,
4062 TosaErrorValidator.evWrongOutputType,
4063 TosaErrorValidator.evWrongInputList,
4064 TosaErrorValidator.evWrongOutputList,
4065 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004066 "data_gen": EW_UNARY_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004067 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004068 "bitwise_not": {
4069 "op": Op.BITWISE_NOT,
4070 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004071 "build_fcn": (
4072 build_unary,
4073 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004074 TosaTensorValuesGen.tvgLazyGenDefault,
4075 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004076 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004077 "types": TYPE_INT,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004078 "error_if_validators": (
4079 TosaErrorValidator.evWrongInputType,
4080 TosaErrorValidator.evWrongOutputType,
4081 TosaErrorValidator.evWrongInputList,
4082 TosaErrorValidator.evWrongOutputList,
4083 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004084 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004085 "ceil": {
4086 "op": Op.CEIL,
4087 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004088 "build_fcn": (
4089 build_unary,
4090 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004091 TosaTensorValuesGen.tvgLazyGenDefault,
4092 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004093 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004094 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004095 "error_if_validators": (
4096 TosaErrorValidator.evWrongInputType,
4097 TosaErrorValidator.evWrongOutputType,
4098 TosaErrorValidator.evWrongInputList,
4099 TosaErrorValidator.evWrongOutputList,
4100 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004101 "data_gen": EW_UNARY_DATAGEN,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004102 "compliance": {"ulp": 0.5},
Jared Smolens573ecd42021-03-04 15:24:10 -08004103 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004104 "clz": {
4105 "op": Op.CLZ,
4106 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004107 "build_fcn": (
4108 build_unary,
4109 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004110 TosaTensorValuesGen.tvgLazyGenDefault,
4111 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004112 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004113 "types": [DType.INT32],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004114 "error_if_validators": (
4115 TosaErrorValidator.evWrongInputType,
4116 TosaErrorValidator.evWrongOutputType,
4117 TosaErrorValidator.evWrongInputList,
4118 TosaErrorValidator.evWrongOutputList,
4119 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004120 },
Jerry Ge51bd4f52024-02-20 11:21:19 -08004121 "cos": {
4122 "op": Op.COS,
4123 "operands": (1, 0),
4124 "build_fcn": (
4125 build_unary,
4126 TosaTensorGen.tgBasic,
4127 TosaTensorValuesGen.tvgLazyGenDefault,
4128 TosaArgGen.agNone,
4129 ),
4130 "types": TYPE_FP,
4131 "error_if_validators": (
4132 TosaErrorValidator.evWrongInputType,
4133 TosaErrorValidator.evWrongOutputType,
4134 TosaErrorValidator.evWrongInputList,
4135 TosaErrorValidator.evWrongOutputList,
4136 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004137 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jerry Ge51bd4f52024-02-20 11:21:19 -08004138 "compliance": {"abs_error_normal_divisor": 2},
4139 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004140 "exp": {
4141 "op": Op.EXP,
4142 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004143 "build_fcn": (
4144 build_unary,
4145 TosaTensorGen.tgBasic,
Jeremy Johnson30476252023-11-20 16:15:30 +00004146 TosaTensorValuesGen.tvgExp,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004147 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004148 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004149 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004150 "error_if_validators": (
4151 TosaErrorValidator.evWrongInputType,
4152 TosaErrorValidator.evWrongOutputType,
4153 TosaErrorValidator.evWrongInputList,
4154 TosaErrorValidator.evWrongOutputList,
4155 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004156 "data_gen": EW_UNARY_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004157 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004158 "floor": {
4159 "op": Op.FLOOR,
4160 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004161 "build_fcn": (
4162 build_unary,
4163 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004164 TosaTensorValuesGen.tvgLazyGenDefault,
4165 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004166 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004167 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004168 "error_if_validators": (
4169 TosaErrorValidator.evWrongInputType,
4170 TosaErrorValidator.evWrongOutputType,
4171 TosaErrorValidator.evWrongInputList,
4172 TosaErrorValidator.evWrongOutputList,
4173 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004174 "data_gen": EW_UNARY_DATAGEN,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004175 "compliance": {"ulp": 0.5},
Jared Smolens573ecd42021-03-04 15:24:10 -08004176 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004177 "log": {
4178 "op": Op.LOG,
4179 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004180 "build_fcn": (
4181 build_unary,
4182 TosaTensorGen.tgBasic,
Jeremy Johnson30476252023-11-20 16:15:30 +00004183 TosaTensorValuesGen.tvgLogRsqrt,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004184 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004185 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004186 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004187 "error_if_validators": (
4188 TosaErrorValidator.evWrongInputType,
4189 TosaErrorValidator.evWrongOutputType,
4190 TosaErrorValidator.evWrongInputList,
4191 TosaErrorValidator.evWrongOutputList,
4192 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004193 "data_gen": EW_UNARY_DATAGEN,
Jeremy Johnson0bbd8bc2023-11-09 16:56:07 +00004194 "compliance": {"ulp": 5},
Jared Smolens573ecd42021-03-04 15:24:10 -08004195 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004196 "logical_not": {
4197 "op": Op.LOGICAL_NOT,
4198 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004199 "build_fcn": (
4200 build_unary,
4201 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004202 TosaTensorValuesGen.tvgLazyGenDefault,
4203 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004204 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004205 "types": TYPE_BOOL,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004206 "error_if_validators": (
4207 TosaErrorValidator.evWrongInputType,
4208 TosaErrorValidator.evWrongOutputType,
4209 TosaErrorValidator.evWrongInputList,
4210 TosaErrorValidator.evWrongOutputList,
4211 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004212 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004213 "negate": {
4214 "op": Op.NEGATE,
4215 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004216 "build_fcn": (
4217 build_unary,
4218 TosaTensorGen.tgBasic,
4219 TosaTensorValuesGen.tvgNegate,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004220 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004221 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004222 "qgen": TosaQuantGen.qgUnary,
4223 "types": TYPE_INT_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004224 "error_if_validators": (
4225 TosaErrorValidator.evInputZeroPointNotZero,
4226 TosaErrorValidator.evOutputZeroPointNotZero,
4227 TosaErrorValidator.evWrongInputType,
4228 TosaErrorValidator.evWrongOutputType,
4229 TosaErrorValidator.evWrongInputList,
4230 TosaErrorValidator.evWrongOutputList,
4231 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004232 "data_gen": EW_UNARY_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004233 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004234 "reciprocal": {
4235 "op": Op.RECIPROCAL,
4236 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004237 "build_fcn": (
4238 build_unary,
4239 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004240 TosaTensorValuesGen.tvgLazyGenDefault,
4241 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004242 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004243 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004244 "error_if_validators": (
4245 TosaErrorValidator.evWrongInputType,
4246 TosaErrorValidator.evWrongOutputType,
4247 TosaErrorValidator.evWrongInputList,
4248 TosaErrorValidator.evWrongOutputList,
4249 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004250 "data_gen": EW_UNARY_DATAGEN,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004251 "compliance": {"ulp": 1.0},
Jared Smolens573ecd42021-03-04 15:24:10 -08004252 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004253 "rsqrt": {
4254 "op": Op.RSQRT,
4255 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004256 "build_fcn": (
4257 build_unary,
4258 TosaTensorGen.tgBasic,
Jeremy Johnson30476252023-11-20 16:15:30 +00004259 TosaTensorValuesGen.tvgLogRsqrt,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004260 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004261 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004262 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004263 "error_if_validators": (
4264 TosaErrorValidator.evWrongInputType,
4265 TosaErrorValidator.evWrongOutputType,
4266 TosaErrorValidator.evWrongInputList,
4267 TosaErrorValidator.evWrongOutputList,
4268 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004269 "data_gen": EW_UNARY_DATAGEN,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004270 "compliance": {"ulp": 2},
Jared Smolens573ecd42021-03-04 15:24:10 -08004271 },
Jerry Ge51bd4f52024-02-20 11:21:19 -08004272 "sin": {
4273 "op": Op.SIN,
4274 "operands": (1, 0),
4275 "build_fcn": (
4276 build_unary,
4277 TosaTensorGen.tgBasic,
4278 TosaTensorValuesGen.tvgLazyGenDefault,
4279 TosaArgGen.agNone,
4280 ),
4281 "types": TYPE_FP,
4282 "error_if_validators": (
4283 TosaErrorValidator.evWrongInputType,
4284 TosaErrorValidator.evWrongOutputType,
4285 TosaErrorValidator.evWrongInputList,
4286 TosaErrorValidator.evWrongOutputList,
4287 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004288 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jerry Ge51bd4f52024-02-20 11:21:19 -08004289 "compliance": {"abs_error_normal_divisor": 2},
4290 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004291 # Elementwise Ternary operators
4292 "select": {
4293 "op": Op.SELECT,
4294 "operands": (3, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004295 "build_fcn": (
4296 build_select,
4297 TosaTensorGen.tgBroadcastFuzz,
4298 TosaTensorValuesGen.tvgSelect,
Jeremy Johnson7b9abce2024-01-10 11:07:29 +00004299 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004300 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004301 "types": TYPE_FIB,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004302 "error_if_validators": (
4303 TosaErrorValidator.evRankMismatch,
4304 TosaErrorValidator.evWrongInputType,
4305 TosaErrorValidator.evWrongOutputType,
4306 TosaErrorValidator.evWrongInputList,
4307 TosaErrorValidator.evWrongOutputList,
4308 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00004309 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004310 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004311 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004312 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004313 # Comparison operators
4314 "equal": {
4315 "op": Op.EQUAL,
4316 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004317 "build_fcn": (
4318 build_comparison,
4319 TosaTensorGen.tgBroadcastFuzz,
4320 TosaTensorValuesGen.tvgEqual,
Jeremy Johnsona0150012023-11-15 15:52:06 +00004321 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004322 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004323 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004324 "error_if_validators": (
4325 TosaErrorValidator.evRankMismatch,
4326 TosaErrorValidator.evWrongInputType,
4327 TosaErrorValidator.evWrongOutputType,
4328 TosaErrorValidator.evWrongInputList,
4329 TosaErrorValidator.evWrongOutputList,
4330 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00004331 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004332 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004333 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004334 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004335 "greater_equal": {
4336 "op": Op.GREATER_EQUAL,
4337 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004338 "build_fcn": (
4339 build_comparison,
4340 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnsona0150012023-11-15 15:52:06 +00004341 TosaTensorValuesGen.tvgLazyGenDefault,
4342 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004343 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004344 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004345 "error_if_validators": (
4346 TosaErrorValidator.evRankMismatch,
4347 TosaErrorValidator.evWrongInputType,
4348 TosaErrorValidator.evWrongOutputType,
4349 TosaErrorValidator.evWrongInputList,
4350 TosaErrorValidator.evWrongOutputList,
4351 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00004352 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004353 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004354 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004355 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004356 "greater": {
4357 "op": Op.GREATER,
4358 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004359 "build_fcn": (
4360 build_comparison,
4361 TosaTensorGen.tgBroadcastFuzz,
Jeremy Johnsona0150012023-11-15 15:52:06 +00004362 TosaTensorValuesGen.tvgLazyGenDefault,
4363 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004364 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004365 "types": TYPE_FI32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004366 "error_if_validators": (
4367 TosaErrorValidator.evRankMismatch,
4368 TosaErrorValidator.evWrongInputType,
4369 TosaErrorValidator.evWrongOutputType,
4370 TosaErrorValidator.evWrongInputList,
4371 TosaErrorValidator.evWrongOutputList,
4372 TosaErrorValidator.evDimensionMismatch,
Jerry Ge135c9552023-05-23 20:59:32 +00004373 TosaErrorValidator.evBroadcastShapesMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004374 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004375 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004376 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004377 # Reduction operators
4378 "reduce_all": {
4379 "op": Op.REDUCE_ALL,
4380 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004381 "build_fcn": (
4382 build_reduce,
4383 TosaTensorGen.tgBasic,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00004384 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004385 TosaArgGen.agAxis,
4386 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004387 "types": TYPE_BOOL,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004388 "error_if_validators": (
4389 TosaErrorValidator.evAxisLargerRank,
4390 TosaErrorValidator.evAxisSmallerZero,
4391 TosaErrorValidator.evShapeOfAxisNotOne,
4392 TosaErrorValidator.evWrongInputType,
4393 TosaErrorValidator.evWrongOutputType,
4394 TosaErrorValidator.evWrongRank,
4395 TosaErrorValidator.evWrongInputList,
4396 TosaErrorValidator.evWrongOutputList,
4397 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004398 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004399 "reduce_any": {
4400 "op": Op.REDUCE_ANY,
4401 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004402 "build_fcn": (
4403 build_reduce,
4404 TosaTensorGen.tgBasic,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00004405 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004406 TosaArgGen.agAxis,
4407 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004408 "types": TYPE_BOOL,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004409 "error_if_validators": (
4410 TosaErrorValidator.evAxisLargerRank,
4411 TosaErrorValidator.evAxisSmallerZero,
4412 TosaErrorValidator.evShapeOfAxisNotOne,
4413 TosaErrorValidator.evWrongInputType,
4414 TosaErrorValidator.evWrongOutputType,
4415 TosaErrorValidator.evWrongRank,
4416 TosaErrorValidator.evWrongInputList,
4417 TosaErrorValidator.evWrongOutputList,
4418 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004419 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004420 "reduce_max": {
4421 "op": Op.REDUCE_MAX,
4422 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004423 "build_fcn": (
4424 build_reduce,
4425 TosaTensorGen.tgBasic,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00004426 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004427 TosaArgGen.agAxis,
4428 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004429 "types": TYPE_INT_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004430 "error_if_validators": (
4431 TosaErrorValidator.evAxisLargerRank,
4432 TosaErrorValidator.evAxisSmallerZero,
4433 TosaErrorValidator.evShapeOfAxisNotOne,
4434 TosaErrorValidator.evWrongInputType,
4435 TosaErrorValidator.evWrongOutputType,
4436 TosaErrorValidator.evWrongRank,
4437 TosaErrorValidator.evWrongInputList,
4438 TosaErrorValidator.evWrongOutputList,
4439 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004440 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004441 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004442 "reduce_min": {
Jeremy Johnson8a8cca92022-03-14 12:16:46 +00004443 "op": Op.REDUCE_MIN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004444 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004445 "build_fcn": (
4446 build_reduce,
4447 TosaTensorGen.tgBasic,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00004448 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004449 TosaArgGen.agAxis,
4450 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004451 "types": TYPE_INT_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004452 "error_if_validators": (
4453 TosaErrorValidator.evAxisLargerRank,
4454 TosaErrorValidator.evAxisSmallerZero,
4455 TosaErrorValidator.evShapeOfAxisNotOne,
4456 TosaErrorValidator.evWrongInputType,
4457 TosaErrorValidator.evWrongOutputType,
4458 TosaErrorValidator.evWrongRank,
4459 TosaErrorValidator.evWrongInputList,
4460 TosaErrorValidator.evWrongOutputList,
4461 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004462 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004463 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004464 "reduce_product": {
4465 "op": Op.REDUCE_PRODUCT,
4466 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004467 "build_fcn": (
4468 build_reduce,
4469 TosaTensorGen.tgBasic,
Jeremy Johnsonbd801962024-01-03 17:07:44 +00004470 TosaTensorValuesGen.tvgReduceProduct,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004471 TosaArgGen.agAxis,
4472 ),
Jared Smolens573ecd42021-03-04 15:24:10 -08004473 "types": TYPE_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004474 "error_if_validators": (
4475 TosaErrorValidator.evAxisLargerRank,
4476 TosaErrorValidator.evAxisSmallerZero,
4477 TosaErrorValidator.evShapeOfAxisNotOne,
4478 TosaErrorValidator.evWrongInputType,
4479 TosaErrorValidator.evWrongOutputType,
4480 TosaErrorValidator.evWrongRank,
4481 TosaErrorValidator.evWrongInputList,
4482 TosaErrorValidator.evWrongOutputList,
4483 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004484 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004485 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004486 "reduce_sum": {
4487 "op": Op.REDUCE_SUM,
4488 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004489 "build_fcn": (
4490 build_reduce,
4491 TosaTensorGen.tgBasic,
4492 TosaTensorValuesGen.tvgReduceSum,
4493 TosaArgGen.agAxis,
4494 ),
James Ward24dbc422022-10-19 12:20:31 +01004495 "types": (DType.FP16, DType.BF16, DType.FP32, DType.INT32),
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004496 "error_if_validators": (
4497 TosaErrorValidator.evAxisLargerRank,
4498 TosaErrorValidator.evAxisSmallerZero,
4499 TosaErrorValidator.evShapeOfAxisNotOne,
4500 TosaErrorValidator.evWrongInputType,
4501 TosaErrorValidator.evWrongOutputType,
4502 TosaErrorValidator.evWrongRank,
4503 TosaErrorValidator.evWrongInputList,
4504 TosaErrorValidator.evWrongOutputList,
4505 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004506 "data_gen": DOT_PRODUCT_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004507 },
Eric Kunzee5e26762020-10-13 16:11:07 -07004508 # Data layout operators
Kevin Cheng550ccc52021-03-03 11:21:43 -08004509 "concat": {
4510 "op": Op.CONCAT,
4511 "operands": (2, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004512 "build_fcn": (
4513 build_concat,
4514 TosaTensorGen.tgConcat,
4515 TosaTensorValuesGen.tvgConcat,
4516 TosaArgGen.agAxis,
4517 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004518 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004519 "error_if_validators": (
4520 TosaErrorValidator.evAxisLargerRank,
4521 TosaErrorValidator.evAxisSmallerZero,
4522 TosaErrorValidator.evConcatInputRankMismatch,
4523 TosaErrorValidator.evConcatShapeSumMismatch,
4524 TosaErrorValidator.evConcatInputDimMismatch,
4525 TosaErrorValidator.evWrongInputType,
4526 TosaErrorValidator.evWrongOutputType,
4527 TosaErrorValidator.evWrongOutputList,
4528 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004529 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004530 },
4531 "pad": {
4532 "op": Op.PAD,
Tai Lye095da72024-01-25 22:00:18 +00004533 "operands": (2, 0),
Jeremy Johnson18a379d2024-03-28 15:53:21 +00004534 "rank": (1, gtu.MAX_TENSOR_RANK),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004535 "build_fcn": (
4536 build_pad,
4537 TosaTensorGen.tgBasic,
Tai Lye095da72024-01-25 22:00:18 +00004538 TosaTensorValuesGen.tvgPad,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004539 TosaArgGen.agPad,
4540 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004541 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004542 "error_if_validators": (
4543 TosaErrorValidator.evWrongInputType,
4544 TosaErrorValidator.evPadSmallerZero,
Jeremy Johnsond32c6da2022-08-24 17:09:09 +01004545 TosaErrorValidator.evPadOutputShapeMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004546 TosaErrorValidator.evWrongOutputType,
4547 TosaErrorValidator.evWrongInputList,
4548 TosaErrorValidator.evWrongOutputList,
Luke Huttona4e48ca2023-02-22 11:53:48 +00004549 TosaErrorValidator.evRankMismatch,
4550 TosaErrorValidator.evWrongRank,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004551 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004552 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004553 },
Won Jeona21b2e82023-08-10 10:33:01 +00004554 "dim": {
4555 "op": Op.DIM,
4556 "operands": (1, 0),
Jeremy Johnson18a379d2024-03-28 15:53:21 +00004557 "rank": (1, gtu.MAX_TENSOR_RANK),
Won Jeona21b2e82023-08-10 10:33:01 +00004558 "build_fcn": (
4559 build_dim,
4560 TosaTensorGen.tgBasic,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00004561 TosaTensorValuesGen.tvgLazyGenDefault,
Won Jeona21b2e82023-08-10 10:33:01 +00004562 TosaArgGen.agAxis,
4563 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004564 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Won Jeona21b2e82023-08-10 10:33:01 +00004565 "error_if_validators": (
4566 TosaErrorValidator.evAxisLargerRank,
4567 TosaErrorValidator.evAxisSmallerZero,
4568 TosaErrorValidator.evWrongInputType,
4569 TosaErrorValidator.evWrongInputList,
4570 TosaErrorValidator.evWrongOutputList,
4571 TosaErrorValidator.evWrongRank,
4572 ),
4573 },
Kevin Cheng550ccc52021-03-03 11:21:43 -08004574 "reshape": {
4575 "op": Op.RESHAPE,
Tai Ly8690a082023-12-18 20:40:24 +00004576 "operands": (2, 0),
Jeremy Johnson18a379d2024-03-28 15:53:21 +00004577 "rank": (1, gtu.MAX_TENSOR_RANK),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004578 "build_fcn": (
4579 build_reshape,
4580 TosaTensorGen.tgBasic,
Won Jeon64e4bfe2024-01-18 06:31:55 +00004581 TosaTensorValuesGen.tvgReshape,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004582 TosaArgGen.agReshape,
4583 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004584 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004585 "error_if_validators": (
4586 TosaErrorValidator.evTensorSizeInputOutputMismatch,
4587 TosaErrorValidator.evWrongInputType,
4588 TosaErrorValidator.evWrongOutputType,
4589 TosaErrorValidator.evWrongInputList,
4590 TosaErrorValidator.evWrongOutputList,
4591 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004592 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004593 },
4594 "reverse": {
4595 "op": Op.REVERSE,
4596 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004597 "build_fcn": (
4598 build_reverse,
4599 TosaTensorGen.tgBasic,
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00004600 TosaTensorValuesGen.tvgLazyGenDefault,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004601 TosaArgGen.agAxis,
4602 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004603 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004604 "error_if_validators": (
4605 TosaErrorValidator.evAxisSmallerZero,
4606 TosaErrorValidator.evAxisLargerRank,
4607 TosaErrorValidator.evWrongInputType,
4608 TosaErrorValidator.evWrongOutputType,
4609 TosaErrorValidator.evWrongInputList,
4610 TosaErrorValidator.evWrongOutputList,
4611 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004612 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004613 },
4614 "slice": {
4615 "op": Op.SLICE,
TatWai Chongf15bad82024-01-31 21:33:27 -08004616 "operands": (3, 0),
Jeremy Johnson18a379d2024-03-28 15:53:21 +00004617 "rank": (1, gtu.MAX_TENSOR_RANK),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004618 "build_fcn": (
4619 build_slice,
4620 TosaTensorGen.tgBasic,
TatWai Chongf15bad82024-01-31 21:33:27 -08004621 TosaTensorValuesGen.tvgSlice,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004622 TosaArgGen.agSlice,
4623 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004624 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004625 "error_if_validators": (
TatWai Chongf15bad82024-01-31 21:33:27 -08004626 # TODO Turn off these error categories for now as the reference
4627 # model cannot allocate memory space for empty tensor. We probably
4628 # can report an accurate error messege at the right place during
4629 # exeuction.
4630 # TosaErrorValidator.evStartSmallerZero,
4631 # TosaErrorValidator.evSizeSmallerEqualZero,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004632 TosaErrorValidator.evStartSizeOutsideBounds,
4633 TosaErrorValidator.evSizeOutputShapeMismatch,
4634 TosaErrorValidator.evInputSizeStartLengthMismatch,
4635 TosaErrorValidator.evWrongRank,
4636 TosaErrorValidator.evWrongInputType,
4637 TosaErrorValidator.evWrongOutputType,
4638 TosaErrorValidator.evWrongInputList,
4639 TosaErrorValidator.evWrongOutputList,
Luke Huttona4e48ca2023-02-22 11:53:48 +00004640 TosaErrorValidator.evRankMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004641 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004642 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004643 },
4644 "tile": {
4645 "op": Op.TILE,
Tai Ly8690a082023-12-18 20:40:24 +00004646 "operands": (2, 0),
Jeremy Johnson18a379d2024-03-28 15:53:21 +00004647 "rank": (1, gtu.MAX_TENSOR_RANK),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004648 "build_fcn": (
4649 build_tile,
4650 TosaTensorGen.tgBasic,
Won Jeon64e4bfe2024-01-18 06:31:55 +00004651 TosaTensorValuesGen.tvgTile,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004652 TosaArgGen.agTile,
4653 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004654 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004655 "error_if_validators": (
4656 TosaErrorValidator.evWrongInputType,
4657 TosaErrorValidator.evWrongOutputType,
4658 TosaErrorValidator.evWrongInputList,
4659 TosaErrorValidator.evWrongOutputList,
Luke Huttona4e48ca2023-02-22 11:53:48 +00004660 TosaErrorValidator.evRankMismatch,
4661 TosaErrorValidator.evWrongRank,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004662 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004663 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004664 },
4665 "transpose": {
4666 "op": Op.TRANSPOSE,
4667 "operands": (1, 0),
Jeremy Johnson18a379d2024-03-28 15:53:21 +00004668 "rank": (1, gtu.MAX_TENSOR_RANK),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004669 "build_fcn": (
4670 build_transpose,
4671 TosaTensorGen.tgBasic,
evacha0198477222024-01-26 12:25:32 +00004672 TosaTensorValuesGen.tvgLazyGenDefault,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004673 TosaArgGen.agTranspose,
4674 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004675 "types": TYPE_FIB + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004676 "error_if_validators": (
4677 TosaErrorValidator.evIndexOutsideBounds,
4678 TosaErrorValidator.evIndexUsedTwice,
4679 TosaErrorValidator.evWrongInputType,
4680 TosaErrorValidator.evWrongOutputType,
4681 TosaErrorValidator.evWrongInputList,
4682 TosaErrorValidator.evWrongOutputList,
Luke Huttona4e48ca2023-02-22 11:53:48 +00004683 TosaErrorValidator.evWrongRank,
4684 TosaErrorValidator.evRankMismatch,
4685 TosaErrorValidator.evTensorSizeInputOutputMismatch,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004686 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004687 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004688 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004689 # Data nodes
4690 "const": {
4691 "op": Op.CONST,
Kevin Cheng17e92022021-10-01 14:33:33 -07004692 "operands": (0, 1),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004693 "build_fcn": (
4694 build_const,
4695 TosaTensorGen.tgBasic,
evacha0198477222024-01-26 12:25:32 +00004696 TosaTensorValuesGen.tvgLazyGenDefault,
4697 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004698 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004699 "types": TYPE_FIB + [DType.INT48, DType.FP8E4M3, DType.FP8E5M2],
evacha01ad8e1e22024-03-19 12:42:17 +00004700 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004701 },
Jared Smolens573ecd42021-03-04 15:24:10 -08004702 "identity": {
4703 "op": Op.IDENTITY,
4704 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004705 "build_fcn": (
4706 build_unary,
4707 TosaTensorGen.tgBasic,
Jeremy Johnson2d70ac42023-11-06 17:46:02 +00004708 TosaTensorValuesGen.tvgLazyGenDefault,
4709 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004710 ),
evacha011adff832024-03-06 17:33:44 +00004711 "types": TYPE_FIB + [DType.INT4, DType.INT48],
evacha01ad8e1e22024-03-19 12:42:17 +00004712 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jared Smolens573ecd42021-03-04 15:24:10 -08004713 },
Eric Kunzee5e26762020-10-13 16:11:07 -07004714 # Scatter/Gather
Kevin Cheng550ccc52021-03-03 11:21:43 -08004715 "gather": {
4716 "op": Op.GATHER,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00004717 "operands": (2, 0),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004718 "rank": (3, 3),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004719 "build_fcn": (
4720 build_gather,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00004721 TosaTensorGen.tgGather,
4722 TosaTensorValuesGen.tvgGather,
4723 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004724 ),
James Ward24dbc422022-10-19 12:20:31 +01004725 "types": (
4726 DType.INT8,
4727 DType.INT16,
4728 DType.INT32,
4729 DType.FP16,
4730 DType.BF16,
4731 DType.FP32,
Won Jeon2c34b462024-02-06 18:37:00 +00004732 DType.FP8E4M3,
4733 DType.FP8E5M2,
James Ward24dbc422022-10-19 12:20:31 +01004734 ),
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004735 "error_if_validators": (
4736 TosaErrorValidator.evWrongInputType,
4737 TosaErrorValidator.evWrongOutputType,
4738 TosaErrorValidator.evWrongInputList,
4739 TosaErrorValidator.evWrongOutputList,
4740 TosaErrorValidator.evWrongRank,
4741 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004742 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004743 },
4744 "scatter": {
4745 "op": Op.SCATTER,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00004746 "operands": (3, 0),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004747 "rank": (3, 3),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004748 "build_fcn": (
4749 build_scatter,
4750 TosaTensorGen.tgScatter,
Jeremy Johnsona8420ad2023-12-07 16:35:28 +00004751 TosaTensorValuesGen.tvgScatter,
4752 TosaArgGen.agNone,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004753 ),
Won Jeon2c34b462024-02-06 18:37:00 +00004754 "types": TYPE_INT_FP + [DType.FP8E4M3, DType.FP8E5M2],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004755 "error_if_validators": (
4756 TosaErrorValidator.evWrongInputType,
4757 TosaErrorValidator.evWrongOutputType,
4758 TosaErrorValidator.evWrongInputList,
4759 TosaErrorValidator.evWrongOutputList,
4760 TosaErrorValidator.evWrongRank,
4761 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004762 "data_gen": PSEUDO_RANDOM_DATAGEN,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004763 },
Eric Kunzee5e26762020-10-13 16:11:07 -07004764 # Image operations
Kevin Cheng550ccc52021-03-03 11:21:43 -08004765 "resize": {
4766 "op": Op.RESIZE,
Tai Lyc5c2a7e2024-02-22 23:26:28 +00004767 "operands": (4, 0),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004768 "rank": (4, 4),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004769 "build_fcn": (
4770 build_resize,
4771 TosaTensorGen.tgNHWC,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00004772 TosaTensorValuesGen.tvgResize,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004773 TosaArgGen.agResize,
4774 ),
James Ward24dbc422022-10-19 12:20:31 +01004775 "types": (DType.INT8, DType.INT16, DType.FP16, DType.BF16, DType.FP32),
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004776 "invalid_test_validators": (
4777 TosaInvalidValidator.ivWrongDataTypeOrModeResize,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004778 ),
4779 "error_if_validators": (
4780 TosaErrorValidator.evMaxDimExceeded,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01004781 TosaErrorValidator.evScaleSmallerEqualZero,
4782 TosaErrorValidator.evScaleNLargerMax,
4783 TosaErrorValidator.evScaleDLargerMax,
4784 TosaErrorValidator.evOffsetSmallerMin,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004785 TosaErrorValidator.evOffsetLargerEqualMax,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01004786 TosaErrorValidator.evBorderSmallerMin,
4787 TosaErrorValidator.evBorderLargerEqualMax,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004788 TosaErrorValidator.evWrongInputType,
4789 TosaErrorValidator.evWrongOutputType,
4790 TosaErrorValidator.evWrongRank,
4791 TosaErrorValidator.evWrongInputList,
4792 TosaErrorValidator.evWrongOutputList,
4793 TosaErrorValidator.evBatchMismatch,
4794 TosaErrorValidator.evChannelMismatch,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01004795 TosaErrorValidator.evResizeOutputShapeMismatch,
4796 TosaErrorValidator.evResizeOutputShapeNonInteger,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004797 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004798 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jeremy Johnson32d0b5a2024-02-01 15:54:07 +00004799 "compliance": {"relative": 0.006},
Kevin Cheng550ccc52021-03-03 11:21:43 -08004800 },
Eric Kunzee5e26762020-10-13 16:11:07 -07004801 # Type conversion
Kevin Cheng550ccc52021-03-03 11:21:43 -08004802 "cast": {
4803 "op": Op.CAST,
4804 "operands": (1, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004805 "build_fcn": (
4806 build_cast,
4807 TosaTensorGen.tgBasic,
Jeremy Johnson708da822023-11-15 16:25:45 +00004808 TosaTensorValuesGen.tvgCast,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004809 TosaArgGen.agCast,
4810 ),
James Ward8b390432022-08-12 20:48:56 +01004811 "types": (
4812 DType.FP16,
James Ward24dbc422022-10-19 12:20:31 +01004813 DType.BF16,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01004814 DType.FP32,
James Ward8b390432022-08-12 20:48:56 +01004815 DType.INT8,
4816 DType.INT16,
4817 DType.INT32,
4818 DType.BOOL,
Won Jeon2c34b462024-02-06 18:37:00 +00004819 DType.FP8E4M3,
4820 DType.FP8E5M2,
James Ward8b390432022-08-12 20:48:56 +01004821 ),
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004822 "error_if_validators": (
4823 TosaErrorValidator.evWrongInputType,
4824 TosaErrorValidator.evWrongOutputType,
4825 TosaErrorValidator.evWrongInputList,
4826 TosaErrorValidator.evWrongOutputList,
4827 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004828 "data_gen": PSEUDO_RANDOM_DATAGEN,
Jeremy Johnson708da822023-11-15 16:25:45 +00004829 "compliance": {"ulp": 0.5},
Kevin Cheng550ccc52021-03-03 11:21:43 -08004830 },
4831 "rescale": {
4832 "op": Op.RESCALE,
Tai Ly6e1e2bc2024-03-01 20:59:32 +00004833 "operands": (3, 0),
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004834 "build_fcn": (
4835 build_rescale,
4836 TosaTensorGen.tgBasic,
Tai Ly6e1e2bc2024-03-01 20:59:32 +00004837 TosaTensorValuesGen.tvgRescale,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004838 TosaArgGen.agRescale,
4839 ),
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01004840 "types": [
4841 DType.UINT8,
4842 DType.INT8,
4843 DType.INT16,
4844 DType.INT32,
4845 DType.INT48,
4846 DType.UINT16,
4847 ],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004848 "error_if_validators": (
4849 TosaErrorValidator.evInputZeroPointNotZero,
4850 TosaErrorValidator.evOutputZeroPointNotZero,
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +01004851 TosaErrorValidator.evU16InputZeroPointNotValid,
4852 TosaErrorValidator.evU16OutputZeroPointNotValid,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004853 TosaErrorValidator.evScaleTrue,
4854 TosaErrorValidator.evScaleNotTrue,
4855 TosaErrorValidator.evWrongInputType,
4856 TosaErrorValidator.evWrongOutputType,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004857 TosaErrorValidator.evWrongInputList,
4858 TosaErrorValidator.evWrongOutputList,
4859 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004860 },
Eric Kunzee5e26762020-10-13 16:11:07 -07004861 # Custom
4862 # Not implemented.
Jared Smolens573ecd42021-03-04 15:24:10 -08004863 # Control flow operators
Eric Kunzee5e26762020-10-13 16:11:07 -07004864 # Two varients of cond_if, one that generates one of two constant tensors (no
4865 # inputs to the basic blocks, one output) and another that either adds or subtracts two tensors
4866 # (two inputs to the basic blocks, one output)
Kevin Cheng550ccc52021-03-03 11:21:43 -08004867 "cond_if_const": {
4868 "op": Op.COND_IF,
4869 "operands": (0, 2),
4870 "build_fcn": (
4871 build_cond_if_const,
4872 TosaTensorGen.tgBasic,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004873 TosaTensorValuesGen.tvgCondIfWhileLoop,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004874 TosaArgGen.agCondIf,
4875 ),
4876 "types": [DType.BOOL],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004877 "error_if_validators": (
4878 TosaErrorValidator.evOutputListThenGraphMismatch,
4879 TosaErrorValidator.evOutputListElseGraphMismatch,
Jeremy Johnson05c711e2022-12-12 18:00:41 +00004880 TosaErrorValidator.evCondIfCondNotMatchingBool,
4881 TosaErrorValidator.evCondIfCondShapeNotSizeOne,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004882 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004883 },
4884 "cond_if_binary": {
4885 "op": Op.COND_IF,
4886 "operands": (2, 0),
4887 "build_fcn": (
4888 build_cond_if_binary,
4889 TosaTensorGen.tgBasic,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004890 TosaTensorValuesGen.tvgCondIfWhileLoop,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004891 TosaArgGen.agCondIf,
4892 ),
Les Bell6040b4d2021-10-11 12:50:31 +01004893 "types": TYPE_INT_FP,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004894 "error_if_validators": (
4895 TosaErrorValidator.evInputListThenGraphMismatch,
4896 TosaErrorValidator.evInputListElseGraphMismatch,
4897 TosaErrorValidator.evOutputListThenGraphMismatch,
4898 TosaErrorValidator.evOutputListElseGraphMismatch,
Jeremy Johnson05c711e2022-12-12 18:00:41 +00004899 TosaErrorValidator.evCondIfCondNotMatchingBool,
4900 TosaErrorValidator.evCondIfCondShapeNotSizeOne,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004901 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004902 },
Eric Kunzee5e26762020-10-13 16:11:07 -07004903 # while_loop
Kevin Cheng550ccc52021-03-03 11:21:43 -08004904 "while_loop": {
4905 "op": Op.WHILE_LOOP,
4906 "operands": (0, 1),
4907 "build_fcn": (
4908 build_while_loop,
4909 TosaTensorGen.tgBasic,
Jeremy Johnson9a66abb2022-04-07 11:29:20 +01004910 TosaTensorValuesGen.tvgCondIfWhileLoop,
Kevin Cheng550ccc52021-03-03 11:21:43 -08004911 TosaArgGen.agWhileLoop,
4912 ),
4913 "types": [DType.INT32],
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004914 "error_if_validators": (
4915 TosaErrorValidator.evInputListOutputListMismatch,
4916 TosaErrorValidator.evInputListCondGraphMismatch,
4917 TosaErrorValidator.evInputListBodyGraphInputMismatch,
4918 TosaErrorValidator.evInputListBodyGraphOutputMismatch,
4919 TosaErrorValidator.evCondGraphOutputNotMatchingBool,
Jeremy Johnson05c711e2022-12-12 18:00:41 +00004920 TosaErrorValidator.evCondGraphOutputShapeNotSizeOne,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00004921 ),
Kevin Cheng550ccc52021-03-03 11:21:43 -08004922 },
Luke Hutton57287132023-02-06 14:54:18 +00004923 "fft2d": {
4924 "op": Op.FFT2D,
4925 "operands": (2, 0),
4926 "rank": (3, 3),
4927 "build_fcn": (
4928 build_fft2d,
4929 TosaTensorGen.tgFFT2d,
Jeremy Johnsonc8330812024-01-18 16:57:28 +00004930 TosaTensorValuesGen.tvgLazyGenDefault,
Luke Hutton57287132023-02-06 14:54:18 +00004931 TosaArgGen.agFFT2d,
4932 ),
4933 "types": [DType.FP32],
4934 "error_if_validators": (
4935 TosaErrorValidator.evWrongInputType,
4936 TosaErrorValidator.evWrongOutputType,
4937 TosaErrorValidator.evWrongInputList,
4938 TosaErrorValidator.evWrongOutputList,
4939 TosaErrorValidator.evWrongRank,
4940 TosaErrorValidator.evBatchMismatch,
4941 TosaErrorValidator.evKernelNotPowerOfTwo,
4942 TosaErrorValidator.evFFTInputShapeMismatch,
4943 TosaErrorValidator.evFFTOutputShapeMismatch,
4944 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004945 "data_gen": DOT_PRODUCT_DATAGEN,
Luke Hutton57287132023-02-06 14:54:18 +00004946 },
Luke Hutton261b7b62023-01-10 14:50:31 +00004947 "rfft2d": {
4948 "op": Op.RFFT2D,
4949 "operands": (1, 0),
4950 "rank": (3, 3),
4951 "build_fcn": (
4952 build_rfft2d,
4953 TosaTensorGen.tgRFFT2d,
Jeremy Johnson6f57e6e2024-01-30 16:10:50 +00004954 TosaTensorValuesGen.tvgLazyGenDefault,
4955 TosaArgGen.agRFFT2d,
Luke Hutton261b7b62023-01-10 14:50:31 +00004956 ),
4957 "types": [DType.FP32],
4958 "error_if_validators": (
4959 TosaErrorValidator.evWrongInputType,
4960 TosaErrorValidator.evWrongOutputType,
4961 TosaErrorValidator.evWrongInputList,
4962 TosaErrorValidator.evWrongOutputList,
4963 TosaErrorValidator.evWrongRank,
4964 TosaErrorValidator.evBatchMismatch,
4965 TosaErrorValidator.evKernelNotPowerOfTwo,
Luke Hutton57287132023-02-06 14:54:18 +00004966 TosaErrorValidator.evFFTOutputShapeMismatch,
Luke Hutton261b7b62023-01-10 14:50:31 +00004967 ),
evacha01ad8e1e22024-03-19 12:42:17 +00004968 "data_gen": DOT_PRODUCT_DATAGEN,
Luke Hutton261b7b62023-01-10 14:50:31 +00004969 },
Won Jeon74342e52024-01-09 00:34:40 +00004970 # Shape
4971 "add_shape": {
4972 "op": Op.ADD_SHAPE,
4973 "operands": (2, 0),
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00004974 "rank": (1, 1),
Won Jeon74342e52024-01-09 00:34:40 +00004975 "build_fcn": (
4976 build_shape_op,
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00004977 TosaTensorGen.tgBasic,
Won Jeon74342e52024-01-09 00:34:40 +00004978 TosaTensorValuesGen.tvgAddSub,
4979 TosaArgGen.agNone,
4980 ),
4981 "types": [DType.SHAPE],
4982 "error_if_validators": (TosaErrorValidator.evDimensionMismatch,),
4983 },
4984 "sub_shape": {
4985 "op": Op.SUB_SHAPE,
4986 "operands": (2, 0),
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00004987 "rank": (1, 1),
Won Jeon74342e52024-01-09 00:34:40 +00004988 "build_fcn": (
4989 build_shape_op,
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00004990 TosaTensorGen.tgBasic,
Won Jeon74342e52024-01-09 00:34:40 +00004991 TosaTensorValuesGen.tvgAddSub,
4992 TosaArgGen.agNone,
4993 ),
4994 "types": [DType.SHAPE],
4995 "error_if_validators": (TosaErrorValidator.evDimensionMismatch,),
4996 },
4997 "mul_shape": {
4998 "op": Op.MUL_SHAPE,
4999 "operands": (2, 0),
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00005000 "rank": (1, 1),
Won Jeon74342e52024-01-09 00:34:40 +00005001 "build_fcn": (
5002 build_shape_op,
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00005003 TosaTensorGen.tgBasic,
Won Jeon74342e52024-01-09 00:34:40 +00005004 TosaTensorValuesGen.tvgMul,
5005 TosaArgGen.agNone,
5006 ),
5007 "types": [DType.SHAPE],
5008 "error_if_validators": (TosaErrorValidator.evDimensionMismatch,),
5009 },
5010 "div_shape": {
5011 "op": Op.DIV_SHAPE,
5012 "operands": (2, 0),
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00005013 "rank": (1, 1),
Won Jeon74342e52024-01-09 00:34:40 +00005014 "build_fcn": (
5015 build_shape_op,
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00005016 TosaTensorGen.tgBasic,
Won Jeon74342e52024-01-09 00:34:40 +00005017 TosaTensorValuesGen.tvgIntDiv,
5018 TosaArgGen.agNone,
5019 ),
5020 "types": [DType.SHAPE],
5021 "error_if_validators": (TosaErrorValidator.evDimensionMismatch,),
5022 },
5023 "concat_shape": {
5024 "op": Op.CONCAT_SHAPE,
5025 "operands": (2, 0),
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00005026 "rank": (1, 1),
Won Jeon74342e52024-01-09 00:34:40 +00005027 "build_fcn": (
5028 build_concat,
5029 TosaTensorGen.tgConcat,
5030 TosaTensorValuesGen.tvgConcat,
5031 TosaArgGen.agNone,
5032 ),
5033 "types": [DType.SHAPE],
5034 "error_if_validators": (),
5035 },
5036 "const_shape": {
5037 "op": Op.CONST_SHAPE,
5038 "operands": (0, 1),
Jeremy Johnsonfc4bde92024-01-25 12:53:21 +00005039 "rank": (1, 1),
Won Jeon74342e52024-01-09 00:34:40 +00005040 "build_fcn": (
5041 build_const,
5042 TosaTensorGen.tgBasic,
evacha0198477222024-01-26 12:25:32 +00005043 TosaTensorValuesGen.tvgLazyGenDefault,
5044 TosaArgGen.agNone,
Won Jeon74342e52024-01-09 00:34:40 +00005045 ),
5046 "types": [DType.SHAPE],
5047 },
Eric Kunzee5e26762020-10-13 16:11:07 -07005048 }
5049
Kevin Cheng550ccc52021-03-03 11:21:43 -08005050
Eric Kunzee5e26762020-10-13 16:11:07 -07005051class OutputShaper:
5052 # Methods in this class compute the expected output shape and datatype
5053 # for common classes of operations
5054 def __init__(self):
5055 pass
5056
5057 # These methods return arguments that can be used for
5058 # creating a new output tensor
5059 @staticmethod
Matthew Haddoneacff9a2021-09-24 14:42:13 +01005060 def binaryBroadcastOp(ser, rng, a, b, error_name=None):
5061 if error_name != ErrorIf.RankMismatch:
5062 assert len(a.shape) == len(b.shape)
Kevin Cheng550ccc52021-03-03 11:21:43 -08005063 assert a.dtype == b.dtype
Eric Kunzee5e26762020-10-13 16:11:07 -07005064
Jeremy Johnson18a379d2024-03-28 15:53:21 +00005065 # Work out broadcasted output shape (when not ERRORIF test)
Eric Kunzee5e26762020-10-13 16:11:07 -07005066 shape = []
5067 for i in range(len(a.shape)):
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005068 if a.shape[i] == 1 and error_name is None:
Eric Kunzee5e26762020-10-13 16:11:07 -07005069 shape.append(b.shape[i])
5070 else:
5071 shape.append(a.shape[i])
5072
Jeremy Johnson18a379d2024-03-28 15:53:21 +00005073 if len(shape) > 0 and error_name == ErrorIf.DimensionMismatch:
5074 # Can only create this error for rank > 0
5075 fuzz_idx = rng.integers(0, len(shape))
Jerry Ge135c9552023-05-23 20:59:32 +00005076 shape[fuzz_idx] += 1
5077
Matthew Haddoneacff9a2021-09-24 14:42:13 +01005078 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005079 all_dtypes = [
5080 DType.INT8,
5081 DType.INT16,
5082 DType.INT32,
5083 DType.INT48,
James Ward24dbc422022-10-19 12:20:31 +01005084 DType.FP16,
5085 DType.BF16,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005086 DType.FP32,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005087 ]
Matthew Haddoneacff9a2021-09-24 14:42:13 +01005088 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5089 outputDType = rng.choice(wrong_dtypes)
5090 else:
5091 outputDType = a.dtype
5092
5093 return ser.addOutput(shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005094
5095 @staticmethod
5096 def binaryNonBroadcastOp(ser, a, b):
Kevin Cheng550ccc52021-03-03 11:21:43 -08005097 assert len(a.shape) == len(b.shape)
5098 assert a.dtype == b.dtype
Eric Kunzee5e26762020-10-13 16:11:07 -07005099
5100 shape = []
5101 for i in range(len(a.shape)):
Kevin Cheng550ccc52021-03-03 11:21:43 -08005102 assert a.shape[i] == b.shape[i]
Eric Kunzee5e26762020-10-13 16:11:07 -07005103 shape.append(a.shape[i])
5104
Kevin Cheng550ccc52021-03-03 11:21:43 -08005105 return ser.addOutput(shape, a.dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005106
5107 @staticmethod
Matthew Haddone4ecdb22021-09-28 11:38:21 +01005108 def unaryOp(ser, rng, a, error_name=None):
5109 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005110 all_dtypes = [
5111 DType.INT8,
5112 DType.INT16,
5113 DType.INT32,
5114 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005115 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005116 DType.FP16,
5117 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005118 ]
Matthew Haddone4ecdb22021-09-28 11:38:21 +01005119 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5120 outputDType = rng.choice(wrong_dtypes)
5121 else:
5122 outputDType = a.dtype
5123
5124 return ser.addOutput(a.shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005125
5126 @staticmethod
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005127 def selectOp(ser, rng, cond, a, b, error_name=None):
Jeremy Johnson7e9ac9a2021-11-08 18:10:51 +00005128 if error_name != ErrorIf.RankMismatch:
5129 assert len(a.shape) == len(b.shape) and len(a.shape) == len(cond.shape)
Kevin Cheng550ccc52021-03-03 11:21:43 -08005130 assert a.dtype == b.dtype
Eric Kunzee5e26762020-10-13 16:11:07 -07005131
Jeremy Johnson18a379d2024-03-28 15:53:21 +00005132 # Work out broadcasted output shape (when not ERRORIF test)
Eric Kunzee5e26762020-10-13 16:11:07 -07005133 shape = []
Jeremy Johnson7e9ac9a2021-11-08 18:10:51 +00005134 for i in range(len(cond.shape)):
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005135 if cond.shape[i] == 1 and error_name is None:
Jeremy Johnson7e9ac9a2021-11-08 18:10:51 +00005136 shape.append(max(cond.shape[i], a.shape[i], b.shape[i]))
5137 else:
5138 shape.append(cond.shape[i])
Eric Kunzee5e26762020-10-13 16:11:07 -07005139
Jeremy Johnson18a379d2024-03-28 15:53:21 +00005140 if len(shape) > 0 and error_name == ErrorIf.DimensionMismatch:
5141 # Can only create this error for rank > 0
5142 fuzz_idx = rng.integers(0, len(shape))
Jerry Ge135c9552023-05-23 20:59:32 +00005143 shape[fuzz_idx] += 1
5144
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005145 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005146 all_dtypes = [
5147 DType.INT8,
5148 DType.INT16,
5149 DType.INT32,
5150 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005151 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005152 DType.FP16,
5153 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005154 ]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005155 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5156 outputDType = rng.choice(wrong_dtypes)
5157 else:
5158 outputDType = a.dtype
5159
5160 return ser.addOutput(shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005161
5162 @staticmethod
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005163 def binaryComparisonOp(ser, rng, a, b, error_name=None):
Jeremy Johnson7e9ac9a2021-11-08 18:10:51 +00005164 if error_name != ErrorIf.RankMismatch:
5165 assert len(a.shape) == len(b.shape)
Kevin Cheng550ccc52021-03-03 11:21:43 -08005166 assert a.dtype == b.dtype
Eric Kunzee5e26762020-10-13 16:11:07 -07005167
Jeremy Johnson18a379d2024-03-28 15:53:21 +00005168 # Work out broadcasted output shape
Eric Kunzee5e26762020-10-13 16:11:07 -07005169 shape = []
5170 for i in range(len(a.shape)):
Eric Kunzea1d49852022-01-04 10:07:29 -08005171 if a.shape[i] == 1 and len(b.shape) > i:
Eric Kunzee5e26762020-10-13 16:11:07 -07005172 shape.append(b.shape[i])
5173 else:
5174 shape.append(a.shape[i])
5175
Jeremy Johnson18a379d2024-03-28 15:53:21 +00005176 if len(shape) > 0 and error_name == ErrorIf.DimensionMismatch:
5177 # Can only create this error for rank > 0
5178 fuzz_idx = rng.integers(0, len(shape))
Jerry Ge135c9552023-05-23 20:59:32 +00005179 shape[fuzz_idx] += 1
5180
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005181 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005182 wrong_dtypes = [
5183 DType.INT8,
5184 DType.INT16,
5185 DType.INT32,
5186 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005187 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005188 DType.FP16,
5189 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005190 ]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005191 outputDType = rng.choice(wrong_dtypes)
5192 else:
5193 outputDType = DType.BOOL
5194
5195 return ser.addOutput(shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005196
5197 @staticmethod
Matthew Haddond6ce7252021-09-29 15:35:44 +01005198 def reduceOp(ser, rng, a, axis, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005199 shape = a.shape.copy()
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005200 if error_name not in [
5201 ErrorIf.AxisSmallerZero,
5202 ErrorIf.AxisLargerRank,
5203 ErrorIf.ShapeOfAxisNotOne,
5204 ]:
Matthew Haddond6ce7252021-09-29 15:35:44 +01005205 shape[axis] = 1
5206 if error_name == ErrorIf.ShapeOfAxisNotOne and shape[axis] == 1:
5207 shape[axis] = rng.integers(2, 10)
Eric Kunzee5e26762020-10-13 16:11:07 -07005208
Matthew Haddond6ce7252021-09-29 15:35:44 +01005209 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005210 all_dtypes = [
5211 DType.INT8,
5212 DType.INT16,
5213 DType.INT32,
5214 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005215 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005216 DType.FP16,
5217 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005218 ]
Matthew Haddond6ce7252021-09-29 15:35:44 +01005219 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5220 outputDType = rng.choice(wrong_dtypes)
5221 else:
5222 outputDType = a.dtype
Eric Kunzee5e26762020-10-13 16:11:07 -07005223
Matthew Haddond6ce7252021-09-29 15:35:44 +01005224 return ser.addOutput(shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005225
5226 @staticmethod
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005227 def argmaxOp(ser, rng, a, axis, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005228 shape = a.shape.copy()
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005229
5230 if error_name not in [ErrorIf.AxisSmallerZero, ErrorIf.AxisLargerRank]:
5231 del shape[axis]
5232
5233 if error_name == ErrorIf.ArgmaxOutputRankMismatch:
5234 remove = rng.choice([True, False])
5235 if remove and len(shape) > 1:
5236 del shape[0]
5237 else:
5238 shape.append(1)
5239 elif error_name == ErrorIf.ArgmaxOutputShapeMismatch:
5240 for i in range(len(shape)):
5241 shape[i] = shape[i] + rng.integers(1, 10)
5242
5243 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005244 all_dtypes = [
5245 DType.INT8,
5246 DType.INT16,
5247 DType.INT32,
5248 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005249 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005250 DType.FP16,
5251 DType.BF16,
Won Jeon2c34b462024-02-06 18:37:00 +00005252 DType.FP8E4M3,
5253 DType.FP8E5M2,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005254 ]
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005255 wrong_dtypes = list(set(all_dtypes) - set([DType.INT32]))
5256 outputDType = rng.choice(wrong_dtypes)
5257 else:
5258 outputDType = DType.INT32
5259
5260 return ser.addOutput(shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005261
5262 @staticmethod
Tai Lyf36f2562024-03-14 16:21:29 +00005263 def _get_conv_output_type(input_dtype):
5264 if input_dtype in (DType.FP16, DType.BF16, DType.FP32):
5265 return input_dtype
5266 elif input_dtype in (DType.FP8E4M3, DType.FP8E5M2):
5267 return DType.FP16
5268 elif input_dtype in (DType.INT8, DType.INT4):
5269 return DType.INT32
5270 elif input_dtype in (DType.INT16,):
5271 return DType.INT48
5272 assert True, f"Unsupported convolution data type {input_dtype}"
5273
5274 @staticmethod
James Ward8b390432022-08-12 20:48:56 +01005275 def conv2dOp(
5276 ser, rng, ifm, filter, accum_dtype, strides, padding, dilations, error_name=None
5277 ):
Eric Kunzee5e26762020-10-13 16:11:07 -07005278
5279 # IFM: NHWC
5280 # Filter: OHWI
5281 # OFM: NHWC
5282
Kevin Cheng550ccc52021-03-03 11:21:43 -08005283 h = (
5284 ifm.shape[1]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005285 - 1
Kevin Cheng550ccc52021-03-03 11:21:43 -08005286 + padding[0]
5287 + padding[1]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005288 - (filter.shape[1] - 1) * dilations[0]
Kevin Cheng550ccc52021-03-03 11:21:43 -08005289 ) // strides[0] + 1
Eric Kunzee5e26762020-10-13 16:11:07 -07005290
Kevin Cheng550ccc52021-03-03 11:21:43 -08005291 w = (
5292 ifm.shape[2]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005293 - 1
Kevin Cheng550ccc52021-03-03 11:21:43 -08005294 + padding[2]
5295 + padding[3]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005296 - (filter.shape[2] - 1) * dilations[1]
Kevin Cheng550ccc52021-03-03 11:21:43 -08005297 ) // strides[1] + 1
Eric Kunzee5e26762020-10-13 16:11:07 -07005298
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005299 if error_name == ErrorIf.ConvOutputShapeMismatch:
5300 choices = [1, 2, 3]
5301 change = rng.choice(choices)
5302 # increment in multiples of stride to not hit non-integer error case
5303 if change in [1, 3]:
5304 h = h + (rng.choice(choices) * strides[0])
5305 if change in [2, 3]:
5306 w = w + (rng.choice(choices) * strides[1])
Les Bell0e027d42021-11-09 14:42:14 +00005307
Eric Kunzee5e26762020-10-13 16:11:07 -07005308 ofm_shape = [ifm.shape[0], h, w, filter.shape[0]]
5309
James Ward8b390432022-08-12 20:48:56 +01005310 if error_name == ErrorIf.WrongInputType:
Les Bell0e027d42021-11-09 14:42:14 +00005311 # Pick some potentially correct output dtype if input type is incorrect
5312 out_dtype = DType.INT32
Eric Kunzee5e26762020-10-13 16:11:07 -07005313 else:
Tai Lyf36f2562024-03-14 16:21:29 +00005314 out_dtype = OutputShaper._get_conv_output_type(ifm.dtype)
Les Bell0e027d42021-11-09 14:42:14 +00005315
5316 if error_name == ErrorIf.WrongOutputType:
James Ward8b390432022-08-12 20:48:56 +01005317 if ifm.dtype == DType.FP16:
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005318 excludes = [DType.FP16, DType.FP32]
Jeremy Johnson80fd9b82024-03-12 11:46:50 +00005319 elif ifm.dtype in [DType.FP8E4M3, DType.FP8E5M2]:
Won Jeon2c34b462024-02-06 18:37:00 +00005320 excludes = [DType.FP16]
James Ward8b390432022-08-12 20:48:56 +01005321 else:
5322 excludes = [out_dtype]
Jeremy Johnson1271c442023-09-05 11:39:26 +01005323 wrong_dtypes = list(gtu.usableDTypes(excludes=excludes))
Les Bell0e027d42021-11-09 14:42:14 +00005324 out_dtype = rng.choice(wrong_dtypes)
Eric Kunzee5e26762020-10-13 16:11:07 -07005325
Kevin Cheng550ccc52021-03-03 11:21:43 -08005326 return ser.addOutput(ofm_shape, out_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005327
5328 @staticmethod
James Ward8b390432022-08-12 20:48:56 +01005329 def conv3dOp(
5330 ser, rng, ifm, filter, accum_dtype, strides, padding, dilations, error_name=None
5331 ):
Kevin Cheng1533b852021-09-01 12:51:58 -07005332
5333 # IFM: NDHWC
5334 # Filter: ODHWI
5335 # OFM: NDHWC
5336
5337 d = (
5338 ifm.shape[1]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005339 - 1
Kevin Cheng1533b852021-09-01 12:51:58 -07005340 + padding[0]
5341 + padding[1]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005342 - (filter.shape[1] - 1) * dilations[0]
Kevin Cheng1533b852021-09-01 12:51:58 -07005343 ) // strides[0] + 1
5344
5345 h = (
5346 ifm.shape[2]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005347 - 1
Kevin Cheng1533b852021-09-01 12:51:58 -07005348 + padding[2]
5349 + padding[3]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005350 - (filter.shape[2] - 1) * dilations[1]
Kevin Cheng1533b852021-09-01 12:51:58 -07005351 ) // strides[1] + 1
5352
5353 w = (
5354 ifm.shape[3]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005355 - 1
Kevin Cheng1533b852021-09-01 12:51:58 -07005356 + padding[4]
5357 + padding[5]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005358 - (filter.shape[3] - 1) * dilations[2]
Kevin Cheng1533b852021-09-01 12:51:58 -07005359 ) // strides[2] + 1
5360
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005361 if error_name == ErrorIf.ConvOutputShapeMismatch:
5362 choices = [1, 2, 3, 4]
5363 change = rng.choice(choices)
5364 # increment in multiples of stride to not hit non-integer error case
5365 if change in [1, 4]:
5366 d = d + (rng.choice(choices) * strides[0])
5367 if change in [2, 4]:
5368 h = h + (rng.choice(choices) * strides[1])
5369 if change in [3, 4]:
5370 w = w + (rng.choice(choices) * strides[2])
Les Bell0e027d42021-11-09 14:42:14 +00005371
Kevin Cheng1533b852021-09-01 12:51:58 -07005372 ofm_shape = [ifm.shape[0], d, h, w, filter.shape[0]]
5373
James Ward8b390432022-08-12 20:48:56 +01005374 if error_name == ErrorIf.WrongInputType:
Les Bell0e027d42021-11-09 14:42:14 +00005375 # Pick some potentially correct output dtype if input type is incorrect
5376 out_dtype = DType.INT32
Kevin Cheng1533b852021-09-01 12:51:58 -07005377 else:
Tai Lyf36f2562024-03-14 16:21:29 +00005378 out_dtype = OutputShaper._get_conv_output_type(ifm.dtype)
Les Bell0e027d42021-11-09 14:42:14 +00005379
5380 if error_name == ErrorIf.WrongOutputType:
James Ward8b390432022-08-12 20:48:56 +01005381 if ifm.dtype == DType.FP16:
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005382 excludes = [DType.FP16, DType.FP32]
James Ward8b390432022-08-12 20:48:56 +01005383 else:
5384 excludes = [out_dtype]
Jeremy Johnson1271c442023-09-05 11:39:26 +01005385 wrong_dtypes = list(gtu.usableDTypes(excludes=excludes))
Les Bell0e027d42021-11-09 14:42:14 +00005386 out_dtype = rng.choice(wrong_dtypes)
Kevin Cheng1533b852021-09-01 12:51:58 -07005387
5388 return ser.addOutput(ofm_shape, out_dtype)
5389
5390 @staticmethod
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005391 def depthwiseConv2dOp(
James Ward8b390432022-08-12 20:48:56 +01005392 ser, rng, ifm, filter, accum_dtype, strides, padding, dilations, error_name=None
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005393 ):
Eric Kunzee5e26762020-10-13 16:11:07 -07005394 # IFM: NHWC
5395 # Filter: HWCM
5396 # OFM: NHW C*M
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005397
Kevin Cheng550ccc52021-03-03 11:21:43 -08005398 h = (
5399 ifm.shape[1]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005400 - 1
Kevin Cheng550ccc52021-03-03 11:21:43 -08005401 + padding[0]
5402 + padding[1]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005403 - (filter.shape[0] - 1) * dilations[0]
Kevin Cheng550ccc52021-03-03 11:21:43 -08005404 ) // strides[0] + 1
Eric Kunzee5e26762020-10-13 16:11:07 -07005405
Kevin Cheng550ccc52021-03-03 11:21:43 -08005406 w = (
5407 ifm.shape[2]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005408 - 1
Kevin Cheng550ccc52021-03-03 11:21:43 -08005409 + padding[2]
5410 + padding[3]
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005411 - (filter.shape[1] - 1) * dilations[1]
Kevin Cheng550ccc52021-03-03 11:21:43 -08005412 ) // strides[1] + 1
Eric Kunzee5e26762020-10-13 16:11:07 -07005413
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005414 if error_name == ErrorIf.ConvOutputShapeMismatch:
5415 choices = [1, 2, 3]
5416 change = rng.choice(choices)
5417 # increment in multiples of stride to not hit non-integer error case
5418 if change in [1, 3]:
5419 h = h + (rng.choice(choices) * strides[0])
5420 if change in [2, 3]:
5421 w = w + (rng.choice(choices) * strides[1])
Les Bell0e027d42021-11-09 14:42:14 +00005422
Eric Kunzee5e26762020-10-13 16:11:07 -07005423 ofm_shape = [ifm.shape[0], h, w, filter.shape[2] * filter.shape[3]]
5424
James Ward8b390432022-08-12 20:48:56 +01005425 if error_name == ErrorIf.WrongInputType:
Les Bell0e027d42021-11-09 14:42:14 +00005426 # Pick some potentially correct output dtype if input type is incorrect
5427 out_dtype = DType.INT32
Eric Kunzee5e26762020-10-13 16:11:07 -07005428 else:
Tai Lyf36f2562024-03-14 16:21:29 +00005429 out_dtype = OutputShaper._get_conv_output_type(ifm.dtype)
Les Bell0e027d42021-11-09 14:42:14 +00005430
5431 if error_name == ErrorIf.WrongOutputType:
James Ward8b390432022-08-12 20:48:56 +01005432 if ifm.dtype == DType.FP16:
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005433 excludes = [DType.FP16, DType.FP32]
James Ward8b390432022-08-12 20:48:56 +01005434 else:
5435 excludes = [out_dtype]
Jeremy Johnson1271c442023-09-05 11:39:26 +01005436 wrong_dtypes = list(gtu.usableDTypes(excludes=excludes))
Les Bell0e027d42021-11-09 14:42:14 +00005437 out_dtype = rng.choice(wrong_dtypes)
Eric Kunzee5e26762020-10-13 16:11:07 -07005438
Kevin Cheng550ccc52021-03-03 11:21:43 -08005439 return ser.addOutput(ofm_shape, out_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005440
5441 @staticmethod
Matthew Haddonb6b59e32021-10-07 17:19:20 +01005442 def pool2dOp(ser, rng, ifm, kernel, stride, pad, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005443 # input: NHWC
Matthew Haddonb6b59e32021-10-07 17:19:20 +01005444 if stride[0] <= 0 or stride[1] <= 0 or min(pad) < 0:
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005445 # If an incorrect stride is used set dimensions to 1, test is invalid anyway.
Matthew Haddonb6b59e32021-10-07 17:19:20 +01005446 h = 1
5447 w = 1
5448 else:
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005449 h = (ifm.shape[1] + pad[0] + pad[1] - kernel[0]) // stride[0] + 1
5450 w = (ifm.shape[2] + pad[2] + pad[3] - kernel[1]) // stride[1] + 1
Matthew Haddonb6b59e32021-10-07 17:19:20 +01005451
5452 if error_name == ErrorIf.PoolingOutputShapeMismatch:
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005453 choices = [1, 2, 3]
5454 change = rng.choice(choices)
5455 # increment in multiples of stride to not hit non-integer error case
5456 if change in [1, 3]:
5457 h = h + (rng.choice(choices) * stride[0])
5458 if change in [2, 3]:
5459 w = w + (rng.choice(choices) * stride[1])
Eric Kunzee5e26762020-10-13 16:11:07 -07005460 ofm_shape = [ifm.shape[0], h, w, ifm.shape[3]]
Matthew Haddonb6b59e32021-10-07 17:19:20 +01005461
5462 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005463 all_dtypes = [
5464 DType.INT8,
5465 DType.INT16,
5466 DType.INT32,
5467 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005468 DType.FP32,
James Ward8b390432022-08-12 20:48:56 +01005469 DType.FP16,
James Ward24dbc422022-10-19 12:20:31 +01005470 DType.BF16,
Won Jeon2c34b462024-02-06 18:37:00 +00005471 DType.FP8E4M3,
5472 DType.FP8E5M2,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005473 ]
Matthew Haddonb6b59e32021-10-07 17:19:20 +01005474 wrong_dtypes = list(set(all_dtypes) - set([ifm.dtype]))
5475 outputDType = rng.choice(wrong_dtypes)
5476 else:
5477 outputDType = ifm.dtype
5478
5479 return ser.addOutput(ofm_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005480
5481 @staticmethod
James Ward8b390432022-08-12 20:48:56 +01005482 def fullyConnectedOp(ser, rng, input, filter, accum_dtype, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005483 # input: N, IC
5484 # filter: OC, IC
5485 # output: N, OC
5486
5487 output_shape = [input.shape[0], filter.shape[0]]
5488
James Ward8b390432022-08-12 20:48:56 +01005489 # Validated in arg_gen (also invalidated for ErrorIf)
5490 out_dtype = accum_dtype
Eric Kunzee5e26762020-10-13 16:11:07 -07005491
Kevin Cheng550ccc52021-03-03 11:21:43 -08005492 return ser.addOutput(output_shape, out_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005493
5494 @staticmethod
James Ward8b390432022-08-12 20:48:56 +01005495 def matmulOp(ser, rng, a, b, accum_dtype, error_name=None):
Kevin Cheng2d60f002021-06-09 14:18:32 -07005496 # a: N, H, C
5497 # b: N, C, W
5498 # out: N, H, W
Eric Kunzee5e26762020-10-13 16:11:07 -07005499
Kevin Cheng2d60f002021-06-09 14:18:32 -07005500 output_shape = [a.shape[0], a.shape[1], b.shape[2]]
Eric Kunzee5e26762020-10-13 16:11:07 -07005501
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005502 if error_name == ErrorIf.WrongOutputType:
5503 if a.dtype == DType.INT8:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005504 incorrect_types = (
5505 DType.INT4,
5506 DType.INT8,
5507 DType.INT16,
5508 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005509 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005510 DType.FP16,
5511 DType.BF16,
Won Jeon2c34b462024-02-06 18:37:00 +00005512 DType.FP8E4M3,
5513 DType.FP8E5M2,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005514 )
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005515 elif a.dtype == DType.INT16:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005516 incorrect_types = (
5517 DType.INT4,
5518 DType.INT8,
5519 DType.INT16,
5520 DType.INT32,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005521 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005522 DType.FP16,
5523 DType.BF16,
Won Jeon2c34b462024-02-06 18:37:00 +00005524 DType.FP8E4M3,
5525 DType.FP8E5M2,
5526 )
5527 elif a.dtype == DType.FP8E4M3 or a.dtype == DType.FP8E5M2:
5528 incorrect_types = (
5529 DType.INT4,
5530 DType.INT8,
5531 DType.INT16,
5532 DType.INT32,
5533 DType.INT48,
5534 DType.FP32,
5535 DType.BF16,
5536 DType.FP8E4M3,
5537 DType.FP8E5M2,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005538 )
James Ward24dbc422022-10-19 12:20:31 +01005539 elif (
5540 a.dtype == DType.FP32 or a.dtype == DType.FP16 or a.dtype == DType.BF16
5541 ):
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005542 incorrect_types = (
5543 DType.INT4,
5544 DType.INT8,
5545 DType.INT16,
5546 DType.INT32,
5547 DType.INT48,
Won Jeon2c34b462024-02-06 18:37:00 +00005548 DType.FP8E4M3,
5549 DType.FP8E5M2,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005550 )
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005551 out_dtype = rng.choice(a=incorrect_types)
Matthew Haddonc4cf0372021-10-11 09:38:10 +01005552 elif error_name == ErrorIf.WrongInputType:
5553 # Pick some potentially correct output dtype if input type is incorrect
5554 out_dtype = DType.INT32
Eric Kunzee5e26762020-10-13 16:11:07 -07005555 else:
James Ward8b390432022-08-12 20:48:56 +01005556 out_dtype = accum_dtype # Validated in arg_gen
Eric Kunzee5e26762020-10-13 16:11:07 -07005557
Kevin Cheng550ccc52021-03-03 11:21:43 -08005558 return ser.addOutput(output_shape, out_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005559
5560 @staticmethod
Jeremy Johnsonbfc53032023-11-01 11:29:56 +00005561 def concatOp(ser, rng, axis, inputs, error_name=None):
5562 input1 = inputs[0]
5563 remaining_inputs = inputs[1:]
Eric Kunzee5e26762020-10-13 16:11:07 -07005564
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005565 # calculate the output shape, if possible, otherwise just use the first input shape
Matthew Haddon818ab902021-07-27 09:12:49 +01005566 output_shape = input1.shape.copy()
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005567 if not (
5568 # unable to concat tensors of different ranks
5569 error_name == ErrorIf.ConcatInputRankMismatch
5570 # unable to concat tensors along an invalid axis
5571 or error_name in [ErrorIf.AxisLargerRank, ErrorIf.AxisSmallerZero]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005572 ):
5573 for tensor in remaining_inputs:
5574 output_shape[axis] += tensor.shape[axis]
Eric Kunzee5e26762020-10-13 16:11:07 -07005575
Matthew Haddon01c359d2021-10-15 16:30:48 +01005576 if error_name == ErrorIf.ConcatShapeSumMismatch:
5577 output_shape[axis] += rng.integers(5, 10)
5578
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005579 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005580 all_dtypes = {
5581 DType.INT8,
5582 DType.INT16,
5583 DType.INT32,
5584 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005585 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005586 DType.FP16,
5587 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005588 }
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005589 wrong_dtypes = list(all_dtypes - set([input1.dtype]))
5590 outputDType = rng.choice(wrong_dtypes)
5591 else:
5592 outputDType = input1.dtype
Matthew Haddon818ab902021-07-27 09:12:49 +01005593
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005594 return ser.addOutput(output_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005595
5596 @staticmethod
Matthew Haddone807aae2021-10-11 18:12:58 +01005597 def padOp(ser, rng, a, padding, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005598
5599 output_shape = a.shape.copy()
5600
5601 for i in range(len(output_shape)):
5602 output_shape[i] = padding[i][0] + padding[i][1] + output_shape[i]
5603
Jeremy Johnsond32c6da2022-08-24 17:09:09 +01005604 if error_name == ErrorIf.PadOutputShapeMismatch:
5605 bad_dim = rng.choice(range(len(output_shape)))
Tai Lye095da72024-01-25 22:00:18 +00005606 output_shape[bad_dim] += rng.choice([1, 2])
Luke Huttona4e48ca2023-02-22 11:53:48 +00005607 elif error_name == ErrorIf.RankMismatch:
Jeremy Johnson1271c442023-09-05 11:39:26 +01005608 output_shape = gtu.get_rank_mismatch_shape(rng, output_shape)
Jeremy Johnsond32c6da2022-08-24 17:09:09 +01005609
Matthew Haddone807aae2021-10-11 18:12:58 +01005610 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005611 all_dtypes = [
5612 DType.INT8,
5613 DType.INT16,
5614 DType.INT32,
5615 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005616 DType.FP32,
James Ward8b390432022-08-12 20:48:56 +01005617 DType.FP16,
James Ward24dbc422022-10-19 12:20:31 +01005618 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005619 ]
Matthew Haddone807aae2021-10-11 18:12:58 +01005620 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5621 outputDType = rng.choice(wrong_dtypes)
5622 else:
5623 outputDType = a.dtype
5624
5625 return ser.addOutput(output_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005626
5627 @staticmethod
Won Jeona21b2e82023-08-10 10:33:01 +00005628 def dimOp(ser, rng, a, axis, error_name=None):
Tai Ly8690a082023-12-18 20:40:24 +00005629 output_shape = [1]
Won Jeona21b2e82023-08-10 10:33:01 +00005630
5631 if error_name == ErrorIf.WrongOutputType:
5632 all_dtypes = [
5633 DType.INT8,
5634 DType.INT16,
5635 DType.INT32,
5636 DType.INT48,
5637 DType.FP32,
5638 DType.FP16,
5639 DType.BF16,
5640 ]
5641 wrong_dtypes = list(set(all_dtypes))
5642 outputDType = rng.choice(wrong_dtypes)
5643 else:
5644 outputDType = DType.SHAPE
5645
5646 return ser.addOutput(output_shape, outputDType)
5647
5648 @staticmethod
Matthew Haddone807aae2021-10-11 18:12:58 +01005649 def reshapeOp(ser, rng, a, shape, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005650 output_shape = shape.copy()
5651
Matthew Haddone807aae2021-10-11 18:12:58 +01005652 if error_name == ErrorIf.TensorSizeInputOutputMismatch:
5653 for i in range(len(output_shape)):
5654 output_shape[i] = output_shape[i] + rng.integers(1, 10)
5655
5656 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005657 all_dtypes = [
5658 DType.INT8,
5659 DType.INT16,
5660 DType.INT32,
5661 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005662 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005663 DType.FP16,
5664 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005665 ]
Matthew Haddone807aae2021-10-11 18:12:58 +01005666 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5667 outputDType = rng.choice(wrong_dtypes)
5668 else:
5669 outputDType = a.dtype
5670
5671 return ser.addOutput(output_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005672
5673 @staticmethod
Luke Huttona4e48ca2023-02-22 11:53:48 +00005674 def sliceOp(ser, rng, input, start, size, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005675
Matthew Haddone807aae2021-10-11 18:12:58 +01005676 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005677 all_dtypes = [
5678 DType.INT8,
5679 DType.INT16,
5680 DType.INT32,
5681 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005682 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005683 DType.FP16,
5684 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005685 ]
Luke Huttona4e48ca2023-02-22 11:53:48 +00005686 wrong_dtypes = list(set(all_dtypes) - set([input.dtype]))
Matthew Haddone807aae2021-10-11 18:12:58 +01005687 outputDType = rng.choice(wrong_dtypes)
5688 else:
Luke Huttona4e48ca2023-02-22 11:53:48 +00005689 outputDType = input.dtype
Matthew Haddone807aae2021-10-11 18:12:58 +01005690
Luke Huttona4e48ca2023-02-22 11:53:48 +00005691 output_shape = size.copy()
Matthew Haddone807aae2021-10-11 18:12:58 +01005692 if error_name == ErrorIf.SizeOutputShapeMismatch:
Matthew Haddone807aae2021-10-11 18:12:58 +01005693 for index in range(len(output_shape)):
5694 if output_shape[index] <= 2:
5695 output_shape[index] = output_shape[index] + rng.choice([1, 2])
5696 else:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005697 output_shape[index] = output_shape[index] + rng.choice(
5698 [-2, -1, 1, 2]
5699 )
Luke Huttona4e48ca2023-02-22 11:53:48 +00005700 elif error_name == ErrorIf.InputSizeStartLengthMismatch:
5701 output_shape = input.shape.copy()
5702 elif error_name == ErrorIf.RankMismatch:
Jeremy Johnson1271c442023-09-05 11:39:26 +01005703 output_shape = gtu.get_rank_mismatch_shape(rng, output_shape)
Matthew Haddone807aae2021-10-11 18:12:58 +01005704
5705 return ser.addOutput(output_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005706
5707 @staticmethod
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005708 def tileOp(ser, rng, a, multiples, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005709
5710 output_shape = a.shape.copy()
Kevin Cheng550ccc52021-03-03 11:21:43 -08005711 assert len(multiples) == len(output_shape)
Eric Kunzee5e26762020-10-13 16:11:07 -07005712
5713 for i in range(len(output_shape)):
5714 output_shape[i] = a.shape[i] * multiples[i]
5715
Luke Huttona4e48ca2023-02-22 11:53:48 +00005716 if error_name == ErrorIf.RankMismatch:
Jeremy Johnson1271c442023-09-05 11:39:26 +01005717 output_shape = gtu.get_rank_mismatch_shape(rng, output_shape)
Luke Huttona4e48ca2023-02-22 11:53:48 +00005718
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005719 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005720 all_dtypes = [
5721 DType.INT8,
5722 DType.INT16,
5723 DType.INT32,
5724 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005725 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005726 DType.FP16,
5727 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005728 ]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005729 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5730 outputDType = rng.choice(wrong_dtypes)
5731 else:
5732 outputDType = a.dtype
5733
5734 return ser.addOutput(output_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005735
5736 @staticmethod
Matthew Haddone807aae2021-10-11 18:12:58 +01005737 def transposeOp(ser, rng, a, perms, error_name=None):
Eric Kunzee5e26762020-10-13 16:11:07 -07005738 output_shape = a.shape.copy()
Matthew Haddone807aae2021-10-11 18:12:58 +01005739
Kevin Cheng550ccc52021-03-03 11:21:43 -08005740 assert len(perms) == len(output_shape)
Eric Kunzee5e26762020-10-13 16:11:07 -07005741
Luke Huttona4e48ca2023-02-22 11:53:48 +00005742 if error_name not in [ErrorIf.IndexOutsideBounds, ErrorIf.IndexUsedTwice]:
Matthew Haddone807aae2021-10-11 18:12:58 +01005743 for i in range(len(output_shape)):
5744 output_shape[i] = a.shape[perms[i]]
Eric Kunzee5e26762020-10-13 16:11:07 -07005745
Luke Huttona4e48ca2023-02-22 11:53:48 +00005746 if error_name == ErrorIf.TensorSizeInputOutputMismatch:
5747 for i in range(len(output_shape)):
5748 output_shape[i] += rng.integers(1, 10)
5749 elif error_name == ErrorIf.RankMismatch:
Jeremy Johnson1271c442023-09-05 11:39:26 +01005750 output_shape = gtu.get_rank_mismatch_shape(rng, output_shape)
Luke Huttona4e48ca2023-02-22 11:53:48 +00005751
Matthew Haddone807aae2021-10-11 18:12:58 +01005752 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005753 all_dtypes = [
5754 DType.INT8,
5755 DType.INT16,
5756 DType.INT32,
5757 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005758 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005759 DType.FP16,
5760 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005761 ]
Matthew Haddone807aae2021-10-11 18:12:58 +01005762 wrong_dtypes = list(set(all_dtypes) - set([a.dtype]))
5763 outputDType = rng.choice(wrong_dtypes)
5764 else:
5765 outputDType = a.dtype
5766
5767 return ser.addOutput(output_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005768
5769 @staticmethod
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005770 def gatherOp(ser, rng, values, indices, error_name=None):
Jeremy Johnson3ca02a72021-11-18 12:18:39 +00005771 if error_name != ErrorIf.WrongRank:
5772 assert len(values.shape) == 3
Kevin Cheng77d0f762020-11-24 10:26:32 -08005773 assert len(indices.shape) == 2
5774 assert values.shape[0] == indices.shape[0]
Eric Kunzee5e26762020-10-13 16:11:07 -07005775
Kevin Cheng77d0f762020-11-24 10:26:32 -08005776 output_shape = [values.shape[0], indices.shape[1], values.shape[2]]
5777
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005778 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005779 all_dtypes = [
5780 DType.INT8,
5781 DType.INT16,
5782 DType.INT32,
5783 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005784 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005785 DType.FP16,
5786 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005787 ]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005788 wrong_dtypes = list(set(all_dtypes) - set([values.dtype]))
5789 outputDType = rng.choice(wrong_dtypes)
5790 else:
5791 outputDType = values.dtype
5792
5793 return ser.addOutput(output_shape, outputDType)
Kevin Cheng77d0f762020-11-24 10:26:32 -08005794
5795 @staticmethod
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005796 def scatterOp(ser, rng, values_in, indices, input, error_name=None):
Jeremy Johnson3ca02a72021-11-18 12:18:39 +00005797 if error_name != ErrorIf.WrongRank:
5798 assert len(values_in.shape) == 3
Kevin Cheng77d0f762020-11-24 10:26:32 -08005799 assert len(indices.shape) == 2
5800 assert len(input.shape) == 3
Kevin Cheng550ccc52021-03-03 11:21:43 -08005801 assert values_in.shape[0] == indices.shape[0] # N
5802 assert input.shape[1] == indices.shape[1] # W
5803 assert values_in.shape[2] == input.shape[2] # C
Kevin Cheng77d0f762020-11-24 10:26:32 -08005804
5805 output_shape = values_in.shape
5806
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005807 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005808 all_dtypes = [
5809 DType.INT8,
5810 DType.INT16,
5811 DType.INT32,
5812 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005813 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005814 DType.FP16,
5815 DType.BF16,
Won Jeon2c34b462024-02-06 18:37:00 +00005816 DType.FP8E4M3,
5817 DType.FP8E5M2,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005818 ]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005819 wrong_dtypes = list(set(all_dtypes) - set([values_in.dtype]))
5820 outputDType = rng.choice(wrong_dtypes)
5821 else:
5822 outputDType = values_in.dtype
5823
5824 return ser.addOutput(output_shape, outputDType)
Eric Kunzee5e26762020-10-13 16:11:07 -07005825
5826 @staticmethod
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005827 def tableOp(ser, rng, input, error_name=None):
5828 # Same shape as the input, dtype dependent on input dtype
5829 if error_name != ErrorIf.WrongInputType:
5830 assert input.dtype == DType.INT16 or input.dtype == DType.INT8
Kevin Chengfe392ce2021-10-18 21:51:55 +00005831 output_dtype = DType.INT32 if input.dtype == DType.INT16 else DType.INT8
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005832 if error_name == ErrorIf.WrongOutputType:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005833 wrong_dtypes = [
5834 DType.INT8,
5835 DType.INT16,
5836 DType.INT32,
5837 DType.INT48,
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005838 DType.FP32,
James Ward24dbc422022-10-19 12:20:31 +01005839 DType.FP16,
5840 DType.BF16,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005841 ]
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005842 wrong_dtypes.remove(output_dtype)
5843 output_dtype = rng.choice(wrong_dtypes)
Jeremy Johnsonf54d8a22021-07-20 16:01:06 +01005844 return ser.addOutput(input.shape, output_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005845
5846 @staticmethod
Kevin Cheng550ccc52021-03-03 11:21:43 -08005847 def resizeOp(
Matthew Haddon693ba9e2021-09-22 11:24:37 +01005848 serializer,
5849 rng,
Kevin Cheng550ccc52021-03-03 11:21:43 -08005850 input,
5851 mode,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005852 scale,
Kevin Cheng550ccc52021-03-03 11:21:43 -08005853 offset,
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005854 border,
Kevin Cheng550ccc52021-03-03 11:21:43 -08005855 input_dtype,
5856 output_dtype,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005857 error_name=None,
Kevin Cheng550ccc52021-03-03 11:21:43 -08005858 ):
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005859 # Calculate OH, OW
5860 scale_y_n = scale[0]
5861 scale_y_d = scale[1]
5862 scale_x_n = scale[2]
5863 scale_x_d = scale[3]
5864 if error_name == ErrorIf.ScaleSmallerEqualZero:
5865 scale_y_n = max(scale_y_n, 1)
5866 scale_y_d = max(scale_y_d, 1)
5867 scale_x_n = max(scale_x_n, 1)
5868 scale_x_d = max(scale_x_d, 1)
5869
5870 oh = ((input.shape[1] - 1) * scale_y_n - offset[0] + border[0]) // scale_y_d + 1
5871 ow = ((input.shape[2] - 1) * scale_x_n - offset[1] + border[1]) // scale_x_d + 1
5872
5873 if error_name is not None:
5874 # Make sure the output tensor is valid, which can occur when
5875 # scale, offset or border have been changed for ERROR_IFs
5876 oh = max(oh, 1)
5877 ow = max(ow, 1)
5878 if error_name != ErrorIf.MaxDimExceeded:
Jeremy Johnson1271c442023-09-05 11:39:26 +01005879 oh = min(oh, gtu.MAX_RESIZE_DIMENSION - 1)
5880 ow = min(ow, gtu.MAX_RESIZE_DIMENSION - 1)
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005881
5882 if error_name == ErrorIf.ResizeOutputShapeMismatch:
5883 choices = [1, 2, 3]
5884 change = rng.choice(choices)
5885 # increment in multiples of scale_y/x_d so we don't hit non-integer error case
5886 if change in [1, 3]:
Jeremy Johnson1271c442023-09-05 11:39:26 +01005887 if oh + scale_y_d >= gtu.MAX_RESIZE_DIMENSION:
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005888 oh -= scale_y_d
5889 assert oh > 0 # Should have been caught in agResize
5890 else:
5891 oh += scale_y_d
5892 if change in [2, 3]:
Jeremy Johnson1271c442023-09-05 11:39:26 +01005893 if ow + scale_x_d >= gtu.MAX_RESIZE_DIMENSION:
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005894 ow -= scale_x_d
5895 assert ow > 0 # Should have been caught in agResize
5896 else:
5897 ow += scale_x_d
5898
Matthew Haddon848efb42021-09-09 12:30:53 +01005899 if error_name == ErrorIf.WrongRank:
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005900 output_dims = [
5901 input.shape[0],
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005902 oh,
5903 ow,
Jeremy Johnson5c1364c2022-01-13 15:04:21 +00005904 input.shape[0],
5905 ]
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005906 elif error_name == ErrorIf.BatchMismatch:
5907 output_dims = [
5908 input.shape[0] + rng.integers(1, 10),
5909 oh,
5910 ow,
5911 input.shape[3],
5912 ]
5913 elif error_name == ErrorIf.ChannelMismatch:
5914 output_dims = [
5915 input.shape[0],
5916 oh,
5917 ow,
5918 input.shape[3] + rng.integers(1, 10),
5919 ]
Matthew Haddon848efb42021-09-09 12:30:53 +01005920 else:
Jeremy Johnsona0e03f32022-06-13 17:48:09 +01005921 output_dims = [input.shape[0], oh, ow, input.shape[3]]
Eric Kunzee5e26762020-10-13 16:11:07 -07005922
Matthew Haddon693ba9e2021-09-22 11:24:37 +01005923 return serializer.addOutput(output_dims, output_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005924
5925 @staticmethod
Matthew Haddonbb5676f2021-10-13 11:30:30 +01005926 def typeConversionOp(ser, rng, val, out_dtype, error_name=None):
Kevin Cheng550ccc52021-03-03 11:21:43 -08005927 return ser.addOutput(val.shape, out_dtype)
Eric Kunzee5e26762020-10-13 16:11:07 -07005928
5929 @staticmethod
James Ward8b390432022-08-12 20:48:56 +01005930 def transposeConv2DOp(ser, rng, ifm, output_shape, accum_dtype, error_name=None):
Jeremy Johnson4a6fb9b2022-04-26 15:47:21 +01005931 if error_name == ErrorIf.ConvOutputShapeMismatch:
5932 choices = [1, 2, 3]
5933 change = rng.choice(choices)
5934 if change in [1, 3]:
5935 output_shape[1] = output_shape[1] + rng.choice(choices)
5936 if change in [2, 3]:
5937 output_shape[2] = output_shape[2] + rng.choice(choices)
5938
James Ward8b390432022-08-12 20:48:56 +01005939 if error_name == ErrorIf.WrongInputType:
Les Bell0e027d42021-11-09 14:42:14 +00005940 # Pick some potentially correct output dtype if input type is incorrect
5941 out_dtype = DType.INT32
Eric Kunzee5e26762020-10-13 16:11:07 -07005942 else:
Tai Lyf36f2562024-03-14 16:21:29 +00005943 out_dtype = OutputShaper._get_conv_output_type(ifm.dtype)
Les Bell0e027d42021-11-09 14:42:14 +00005944
5945 if error_name == ErrorIf.WrongOutputType:
James Ward8b390432022-08-12 20:48:56 +01005946 if ifm.dtype == DType.FP16:
Jeremy Johnsonbc2a3db2022-09-27 13:50:00 +01005947 excludes = [DType.FP16, DType.FP32]
James Ward8b390432022-08-12 20:48:56 +01005948 else:
5949 excludes = [out_dtype]
Jeremy Johnson1271c442023-09-05 11:39:26 +01005950 wrong_dtypes = list(gtu.usableDTypes(excludes=excludes))
Les Bell0e027d42021-11-09 14:42:14 +00005951 out_dtype = rng.choice(wrong_dtypes)
Eric Kunzee5e26762020-10-13 16:11:07 -07005952
Kevin Cheng550ccc52021-03-03 11:21:43 -08005953 return ser.addOutput(output_shape, out_dtype)
Luke Hutton261b7b62023-01-10 14:50:31 +00005954
5955 @staticmethod
Luke Hutton57287132023-02-06 14:54:18 +00005956 def fft2dOp(serializer, rng, ifm1, ifm2, error_name=None):
5957 outputs = []
5958
5959 assert ifm1.dtype == ifm2.dtype
5960 input_dtype = ifm1.dtype
5961
5962 if error_name != ErrorIf.FFTInputShapeMismatch:
5963 assert ifm1.shape == ifm2.shape
5964
5965 input_shape = ifm1.shape
5966 if error_name != ErrorIf.WrongRank:
5967 assert len(input_shape) == 3
5968
5969 output_shape = input_shape.copy()
5970 output_dtype = input_dtype
5971
5972 if error_name == ErrorIf.WrongOutputType:
5973 excludes = [DType.FP32]
Jeremy Johnson1271c442023-09-05 11:39:26 +01005974 wrong_dtypes = list(gtu.usableDTypes(excludes=excludes))
Luke Hutton57287132023-02-06 14:54:18 +00005975 output_dtype = rng.choice(wrong_dtypes)
5976 elif error_name == ErrorIf.BatchMismatch:
5977 output_shape[0] += rng.integers(1, 10)
5978 elif error_name == ErrorIf.FFTOutputShapeMismatch:
5979 modify_dim = rng.choice([1, 2])
5980 output_shape[modify_dim] += rng.integers(1, 10)
5981
5982 outputs.append(serializer.addOutput(output_shape, output_dtype))
5983 outputs.append(serializer.addOutput(output_shape, output_dtype))
5984 return outputs
5985
5986 @staticmethod
Luke Hutton261b7b62023-01-10 14:50:31 +00005987 def rfft2dOp(serializer, rng, value, error_name=None):
5988 outputs = []
5989
5990 input_shape = value.shape
5991 if error_name != ErrorIf.WrongRank:
5992 assert len(input_shape) == 3
5993
5994 output_shape = [*input_shape[:-1], input_shape[-1] // 2 + 1]
5995
5996 output_dtype = value.dtype
5997 if error_name == ErrorIf.WrongOutputType:
5998 excludes = [DType.FP32]
Jeremy Johnson1271c442023-09-05 11:39:26 +01005999 wrong_dtypes = list(gtu.usableDTypes(excludes=excludes))
Luke Hutton261b7b62023-01-10 14:50:31 +00006000 output_dtype = rng.choice(wrong_dtypes)
6001 elif error_name == ErrorIf.BatchMismatch:
Luke Hutton57287132023-02-06 14:54:18 +00006002 output_shape[0] += rng.integers(1, 10)
6003 elif error_name == ErrorIf.FFTOutputShapeMismatch:
6004 modify_dim = rng.choice([1, 2])
6005 output_shape[modify_dim] += rng.integers(1, 10)
Luke Hutton261b7b62023-01-10 14:50:31 +00006006
6007 outputs.append(serializer.addOutput(output_shape, output_dtype))
6008 outputs.append(serializer.addOutput(output_shape, output_dtype))
6009 return outputs
Won Jeon74342e52024-01-09 00:34:40 +00006010
6011 @staticmethod
6012 def addShapeOp(ser, rng, a, b, error_name=None):
6013 if error_name != ErrorIf.RankMismatch:
6014 assert len(a.shape) == len(b.shape)
6015 assert a.dtype == b.dtype
6016
Jeremy Johnson18a379d2024-03-28 15:53:21 +00006017 shape = a.shape.copy()
Won Jeon74342e52024-01-09 00:34:40 +00006018
Jeremy Johnson18a379d2024-03-28 15:53:21 +00006019 # Do not expect rank 0 tests!
6020 assert len(shape) > 0
Won Jeon74342e52024-01-09 00:34:40 +00006021 if error_name == ErrorIf.DimensionMismatch:
Jeremy Johnson18a379d2024-03-28 15:53:21 +00006022 # Can only create this error for rank > 0
6023 fuzz_idx = rng.integers(0, len(shape))
Won Jeon74342e52024-01-09 00:34:40 +00006024 shape[fuzz_idx] += 1
6025
6026 if error_name == ErrorIf.WrongOutputType:
6027 wrong_dtypes = gtu.get_wrong_output_type(a.dtype)
6028 outputDType = rng.choice(wrong_dtypes)
6029 else:
6030 outputDType = DType.SHAPE
6031 return ser.addOutput(shape, outputDType)