diff --git a/LICENSE b/LICENSE index c1d7e2e3af..ebbfba1673 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ MIT License Copyright (c) Lutz Roeder +Copyright 2025 Arm Limited and/or its affiliates Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.js b/package.js index 09d15788fb..46647bdc36 100644 --- a/package.js +++ b/package.js @@ -1,3 +1,4 @@ +// SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates import * as child_process from 'child_process'; import * as crypto from 'crypto'; @@ -611,7 +612,8 @@ const update = async () => { 'sentencepiece', 'sklearn', 'tf', 'uff', - 'xmodel' + 'xmodel', + 'tosa' ]; let commands = [ 'sync', diff --git a/publish/electron-builder.json b/publish/electron-builder.json index 103ad1f003..0927da3033 100644 --- a/publish/electron-builder.json +++ b/publish/electron-builder.json @@ -11,6 +11,7 @@ { "ext": "cmf", "name": "CNTK Model" }, { "ext": "dlc", "name": "DLC Model" }, { "ext": "dnn", "name": "CNTK Model" }, + { "ext": "tosa", "name": "TOSA Model" }, { "ext": "gguf", "name": "GGUF Model" }, { "ext": "h5", "name": "Keras Model" }, { "ext": "hd5", "name": "Keras Model" }, @@ -62,6 +63,7 @@ { "ext": "t7", "name": "Torch Model" }, { "ext": "tfl", "name": "TensorFlow Lite Model" }, { "ext": "tflite", "name": "TensorFlow Lite Model" }, + { "ext": "tosa", "name": "TOSA Model" }, { "ext": "tmfile", "name": "Tengine Model" }, { "ext": "tm", "name": "MegEngine Traced Model" }, { "ext": "tnnproto", "name": "TNN Model" }, diff --git a/source/base.js b/source/base.js index 083319a121..4257c34d37 100644 --- a/source/base.js +++ b/source/base.js @@ -1,3 +1,4 @@ +// SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates const base = {}; @@ -240,6 +241,28 @@ DataView.prototype.getUintBits = DataView.prototype.getUintBits || function(offs return value & ((1 << bits) - 1); }; +DataView.prototype.getInt48 = DataView.prototype.getInt48 || function(offset, littleEndian) { + const bits = 48n; + const shift = littleEndian ? 0n : 16n; + let value = 0n; + if (this.byteLength - offset < 8) { + const buffer = new ArrayBuffer(8); + const view = new DataView(buffer); + for (let i = 0; i < 6; i++) { + view.setUint8(i, this.getUint8(offset + i)); + } + value = view.getBigUint64(0, littleEndian); + } else { + value = this.getBigUint64(offset, littleEndian); + } + value >>= shift; + value &= (1n << bits) - 1n; + if (value & (1n << (bits - 1n))) { + value -= 1n << bits; + } + return value; +}; + DataView.prototype.getComplex64 = DataView.prototype.getComplex64 || function(byteOffset, littleEndian) { const real = littleEndian ? this.getFloat32(byteOffset, littleEndian) : this.getFloat32(byteOffset + 4, littleEndian); const imaginary = littleEndian ? this.getFloat32(byteOffset + 4, littleEndian) : this.getFloat32(byteOffset, littleEndian); @@ -611,7 +634,7 @@ base.Tensor = class { ['qint8', 1], ['qint16', 2], ['qint32', 4], ['quint8', 1], ['quint16', 2], ['quint32', 4], ['xint8', 1], - ['int8', 1], ['int16', 2], ['int32', 4], ['int64', 8], + ['int8', 1], ['int16', 2], ['int32', 4], ['int48', 6], ['int64', 8], ['uint8', 1], ['uint16', 2], ['uint32', 4,], ['uint64', 8], ['float16', 2], ['float32', 4], ['float64', 8], ['bfloat16', 2], ['complex64', 8], ['complex128', 16], @@ -871,6 +894,11 @@ base.Tensor = class { results.push(view.getInt32(offset, this._littleEndian)); } break; + case 'int48': + for (; offset < max; offset += stride) { + results.push(view.getInt48(offset, this._littleEndian)); + } + break; case 'int64': for (; offset < max; offset += stride) { results.push(view.getBigInt64(offset, this._littleEndian)); @@ -1274,7 +1302,8 @@ base.Metadata = class { 'ptl', 't7', 'dlc', 'uff', 'armnn', 'kann', 'kgraph', 'mnn', 'ms', 'ncnn', 'om', 'tm', 'mge', 'tmfile', 'tnnproto', 'xmodel', 'kmodel', 'rknn', - 'tar', 'zip' + 'tar', 'zip', + 'tosa' ]; } }; diff --git a/source/tosa-metadata-v0.80.json b/source/tosa-metadata-v0.80.json new file mode 100644 index 0000000000..0f5b70bdad --- /dev/null +++ b/source/tosa-metadata-v0.80.json @@ -0,0 +1,2046 @@ +[ + { + "name": "ARGMAX", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis in range from 0 to rank(shape1) - 1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor, with rank = rank(shape1) - 1" + } + ] + }, + { + "name": "AVG_POOL2D", + "category": "pool", + "attributes": [ + { + "name": "kernel", + "type": "i32_t", + "description": "[kernel_y, kernel_x]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "accum_dtype", + "type": "acc_type_t", + "description": "Enumerated type, must be one of INT32, FP16, FP32, as defined in the Supported Data Types table for this operation" + }, + { + "name": "input_zp", + "type": "in_out_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "output_zp", + "type": "in_out_t", + "description": "Output tensor zero point. Must be zero for non-int8 types." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor 4D" + } + ] + }, + { + "name": "CONV2D", + "category": "layer", + "attributes": [ + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "dilation", + "type": "i32_t", + "description": "[dilation_y, dilation_x]" + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KH x KW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "CONV3D", + "category": "layer", + "attributes": [ + { + "name": "pad", + "type": "i32_t", + "description": "[pad_d0, pad_d1, pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_d, stride_y, stride_x]" + }, + { + "name": "dilation", + "type": "i32_t", + "description": "[dilation_d, dilation_y, dilation_x]" + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KDxKHxKW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "DEPTHWISE_CONV2D", + "category": "layer", + "attributes": [ + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "dilation", + "type": "i32_t", + "description": "[dilation_y, dilation_x]" + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KH x KW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "FFT2D", + "attributes": [ + { + "name": "inverse", + "type": "bool_t", + "description": "false for forward FFT, true for inverse FFT" + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input_real", + "type": "in_out_t", + "description": "Real part of the complex input. H,W must be powers of two." + }, + { + "name": "input_imag", + "type": "in_out_t", + "description": "Imaginary part of the complex input. H,W must be powers of two." + } + ], + "outputs": [ + { + "name": "output_real", + "type": "in_out_t", + "description": "Real part of the complex output." + }, + { + "name": "output_imag", + "type": "in_out_t", + "description": "Imaginary part of the complex output." + } + ] + }, + { + "name": "FULLY_CONNECTED", + "category": "layer", + "attributes": [ + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weights" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "MATMUL", + "attributes": [ + { + "name": "a_zp", + "type": "in_t", + "description": "Input tensor A zero point. Must be zero for non-int8 types." + }, + { + "name": "b_zp", + "type": "in_t", + "description": "Input tensor B zero point. Must be zero for non-int8 types." + } + ], + "inputs": [ + { + "name": "A", + "type": "in_t", + "description": "Input tensor A, N matrices of size HxC" + }, + { + "name": "B", + "type": "in_t", + "description": "Input tensor B, N matrices of size CxW" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor, N matrices of size HxW" + } + ] + }, + { + "name": "MAX_POOL2D", + "category": "pool", + "attributes": [ + { + "name": "kernel", + "type": "i32_t", + "description": "[kernel_y, kernel_x]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor 4D" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor 4D" + } + ] + }, + { + "name": "RFFT2D", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Real input. H,W must be powers of two." + } + ], + "outputs": [ + { + "name": "output_real", + "type": "in_out_t", + "description": "Real part of the complex output" + }, + { + "name": "output_imag", + "type": "in_out_t", + "description": "Imaginary part of the complex output." + } + ] + }, + { + "name": "TRANSPOSE_CONV2D", + "category": "layer", + "attributes": [ + { + "name": "out_pad", + "type": "i32_t", + "description": "[out_pad_top, out_pad_bottom, out_pad_left, out_pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "out_shape", + "type": "i32_t", + "description": "[N,OH,OW,OC]" + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KH x KW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "CLAMP", + "category": "activation", + "attributes": [ + { + "name": "min_int", + "type": "in_out_t", + "description": "Minimum clip value" + }, + { + "name": "max_int", + "type": "in_out_t", + "description": "Maximum clip value" + }, + { + "name": "min_fp", + "type": "in_out_t", + "description": "Minimum clip value" + }, + { + "name": "max_fp", + "type": "in_out_t", + "description": "Maximum clip value" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "ERF", + "category": "activation", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "SIGMOID", + "category": "activation", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "TANH", + "category": "activation", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "ADD", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "ARITHMETIC_RIGHT_SHIFT", + "attributes": [ + { + "name": "round", + "type": "bool_t", + "description": "If true then the shift is rounded" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "BITWISE_AND", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "BITWISE_OR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "BITWISE_XOR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "INTDIV", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "LOGICAL_AND", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "LOGICAL_LEFT_SHIFT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "LOGICAL_RIGHT_SHIFT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "LOGICAL_OR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "LOGICAL_XOR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "MAXIMUM", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "MINIMUM", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "MUL", + "attributes": [ + { + "name": "shift", + "type": "i8_t", + "description": "Result right shift (i32_t data type only)" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + }, + { + "name": "shift", + "type": "i8_t", + "description": "Result right shift (i32_t data type only)" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "POW", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "SUB", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "TABLE", + "attributes": [ + { + "name": "table", + "type": "table_t", + "description": "Lookup table tensor" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "table", + "type": "table_t", + "description": "Lookup table tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "ABS", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "BITWISE_NOT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "CEIL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "CLZ", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "EXP", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "FLOOR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "LOG", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "LOGICAL_NOT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "NEGATE", + "attributes": [ + { + "name": "input1_zp", + "type": "in_out_t", + "description": "Input 1 zero point. Must be zero for non-int8 types." + }, + { + "name": "output_zp", + "type": "in_out_t", + "description": "Output zero point. Must be zero for non-int8 types." + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "RECIPROCAL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "RSQRT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "SELECT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "bool_t", + "description": "Input selector tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input value tensor if input1 is True" + }, + { + "name": "input3", + "type": "in_out_t", + "description": "Input value tensor if input1 is False" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type as input2 and input3, with broadcast shape if necessary" + } + ] + }, + { + "name": "EQUAL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "GREATER", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "GREATER_EQUAL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor with broadcast shape if necessary" + } + ] + }, + { + "name": "REDUCE_ALL", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_ANY", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_MAX", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_MIN", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_PRODUCT", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_SUM", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor with rank from 1 to 4" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "CONCAT", + "category": "tensor", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis along which concatenation is to occur, in range from 0 to rank(shape)-1" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "List of input tensors. All inputs must have the same rank and data type" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "PAD", + "category": "tensor", + "attributes": [ + { + "name": "pad_const", + "type": "in_out_t", + "description": "Constant value to be used as padding" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "padding", + "type": "shape_t", + "description": "Number of pad elements at the start and end of each dimension" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type as the input tensor" + } + ] + }, + { + "name": "DIM", + "category": "shape", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis in range from 0 to rank(shape) - 1" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "shape_t", + "description": "Output rank 0 tensor giving the size of the shape for the given axis" + } + ] + }, + { + "name": "RESHAPE", + "category": "shape", + "attributes": [ + { + "name": "new_shape", + "type": "shape_t", + "description": "The new shape." + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "shape", + "type": "shape_t", + "description": "1D shape tensor giving the new shape." + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "REVERSE", + "category": "tensor", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reverse, in range from 0 to rank(shape)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same shape as input tensor" + } + ] + }, + { + "name": "SLICE", + "category": "tensor", + "attributes": [ + { + "name": "start", + "type": "index_t", + "description": "List of integer coordinates, of length equal to the rank of input1. Start coordinate for slicing." + }, + { + "name": "size", + "type": "index_t", + "description": "List of integer size values, of length equal to the rank of input1. Size of the input to be used." + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type as the input tensor" + } + ] + }, + { + "name": "TILE", + "category": "tensor", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "multiples", + "type": "shape_t", + "description": "Number of times to replicate input1 in each dimension" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, rank as the input tensor" + } + ] + }, + { + "name": "TRANSPOSE", + "category": "transform", + "attributes": [ + { + "name": "perms", + "type": "i32_t", + "description": "List of integers of length equal to the rank of input1. Values must be valid dimensions within shape1, and may not be repeated." + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, rank as the input tensor" + } + ] + }, + { + "name": "GATHER", + "category": "transform", + "attributes": [], + "inputs": [ + { + "name": "values", + "type": "in_out_t", + "description": "3D value tensor" + }, + { + "name": "indices", + "type": "index_t", + "description": "2D index tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "3D output tensor" + } + ] + }, + { + "name": "SCATTER", + "category": "transform", + "attributes": [], + "inputs": [ + { + "name": "values_in", + "type": "in_out_t", + "description": "3D values in tensor" + }, + { + "name": "indices", + "type": "index_t", + "description": "2D index tensor" + }, + { + "name": "input", + "type": "in_out_t", + "description": "3D input tensor" + } + ], + "outputs": [ + { + "name": "values_out", + "type": "in_out_t", + "description": "3D output tensor" + } + ] + }, + { + "name": "RESIZE", + "attributes": [ + { + "name": "mode", + "type": "resize_mode_t", + "description": "BILINEAR or NEAREST" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "scale", + "type": "shape_t", + "description": "[scale_y_n, scale_y_d, scale_x_n, scale_x_d]" + }, + { + "name": "offset", + "type": "shape_t", + "description": "[offset_y, offset_x]" + }, + { + "name": "border", + "type": "shape_t", + "description": "[border_y, border_x]" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "CAST", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "RESCALE", + "category": "quantization", + "attributes": [ + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. int8/uint8 can have zero point within their valid range. uint16 zero point must be either 0 or 32768. All other types must have zero point equal to 0." + }, + { + "name": "output_zp", + "type": "out_t", + "description": "Output tensor zero point.int8/uint8 can have zero point within their valid range. uint16 zero point must be either 0 or 32768. All other types must have zero point equal to 0." + }, + { + "name": "multiplier", + "type": "mul_t", + "description": "Scaling multiplier array" + }, + { + "name": "shift", + "type": "i8_t", + "description": "Scaling shift array" + }, + { + "name": "scale32", + "type": "bool_t", + "description": "if (scale32) mul_t=i32_t else mul_t=i16_t" + }, + { + "name": "double_round", + "type": "bool_t", + "description": "Select double round mode" + }, + { + "name": "per_channel", + "type": "bool_t", + "description": "if (per_channel) NC=shape[rank(shape)-1] else NC=1" + }, + { + "name": "input_unsigned", + "type": "bool_t", + "description": "If True, treat the input values as unsigned." + }, + { + "name": "output_unsigned", + "type": "bool_t", + "description": "If True, treat the output values as unsigned." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "multiplier", + "type": "mul_t", + "description": "Scaling multiplier array" + }, + { + "name": "shift", + "type": "i8_t", + "description": "Scaling shift array" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor with the same shape as input" + } + ] + }, + { + "name": "CONST", + "category": "constant", + "attributes": [ + { + "name": "values", + "type": "out_t", + "description": "Constant values" + } + ], + "inputs": [], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor of the same type, size as the input tensor" + } + ] + }, + { + "name": "IDENTITY", + "category": "tensor", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of the same type, size as the input tensor" + } + ] + }, + { + "name": "CUSTOM", + "category": "custom", + "attributes": [ + { + "name": "operator", + "type": "String", + "description": "String which tells the backend which custom operator is being called" + }, + { + "name": "domain", + "type": "String", + "description": "String idenifier which can help avoid name collisions on the operator field. Different implementations of a given operator would be in different domains. Implementations can choose which domains they want to support." + }, + { + "name": "implementation_attrs", + "type": "String", + "description": "String value containing implementation specific attributes which apply to the operation" + } + ], + "inputs": [ + { + "name": "input_list", + "type": "tensor_list_t", + "description": "List of input tensors" + } + ], + "outputs": [ + { + "name": "output_list", + "type": "tensor_list_t", + "description": "List of output tensors" + } + ] + }, + { + "name": "COND_IF", + "attributes": [ + { + "name": "then_branch", + "type": "tosa_graph_t", + "description": "TOSA graph to execute if condition is true" + }, + { + "name": "else_branch", + "type": "tosa_graph_t", + "description": "TOSA graph to execute if condition is false" + } + ], + "inputs": [ + { + "name": "condition", + "type": "bool_t", + "description": "Input condition as a size 1 tensor" + }, + { + "name": "input_list", + "type": "tensor_list_t", + "description": "List of input tensors" + } + ], + "outputs": [ + { + "name": "output_list", + "type": "tensor_list_t", + "description": "List of output tensors" + } + ] + }, + { + "name": "WHILE_LOOP", + "attributes": [ + { + "name": "cond_branch", + "type": "tosa_graph_t", + "description": "TOSA graph to evaluate the condition" + }, + { + "name": "body_branch", + "type": "tosa_graph_t", + "description": "TOSA graph to execute the loop body" + } + ], + "inputs": [ + { + "name": "input_list", + "type": "tensor_list_t", + "description": "List of input tensors" + } + ], + "outputs": [ + { + "name": "output_list", + "type": "tensor_list_t", + "description": "List of output tensors" + } + ] + }, + { + "name": "VARIABLE", + "attributes": [ + { + "name": "uid", + "type": "i32_t", + "description": "Globally unique identifier for the declared variable tensor." + }, + { + "name": "var_shape", + "type": "index_t", + "description": "The variable tensor shape" + }, + { + "name": "type", + "type": "var_t", + "description": "Type of the tensor variable elements." + }, + { + "name": "initial_value", + "type": "in_t", + "description": "Initial value of the variable tensor. This argument is optional with default value NULL." + } + ], + "inputs": [], + "outputs": [] + }, + { + "name": "VARIABLE_WRITE", + "attributes": [ + { + "name": "uid", + "type": "i32_t", + "description": "Globally unique identifier of the variable tensor that is writing to" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + } + ], + "outputs": [] + }, + { + "name": "VARIABLE_READ", + "attributes": [ + { + "name": "uid", + "type": "i32_t", + "description": "Globally unique identifier of the variable tensor that is reading from" + } + ], + "inputs": [], + "outputs": [ + { + "name": "output1", + "type": "out_t", + "description": "Output tensor" + } + ] + } +] \ No newline at end of file diff --git a/source/tosa-metadata-v1.0.json b/source/tosa-metadata-v1.0.json new file mode 100644 index 0000000000..2858e041f6 --- /dev/null +++ b/source/tosa-metadata-v1.0.json @@ -0,0 +1,2052 @@ +[ + { + "name": "ARGMAX", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis in range from 0 to rank(shape1) - 1" + }, + { + "name": "nan_mode", + "type": "nan_propagation_mode_t", + "description": "PROPAGATE or IGNORE. Set to PROPAGATE by default. This attribute affects the floating-point NaN propagation approach. This attribute is ignored by non floating-point types." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor, with rank = rank(shape1) - 1" + } + ] + }, + { + "name": "AVG_POOL2D", + "category": "pool", + "attributes": [ + { + "name": "kernel", + "type": "i32_t", + "description": "[kernel_y, kernel_x]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "acc_type", + "type": "acc_type_t", + "description": "Enumerated type, must be one of INT32, FP16, FP32 matching the type of acc_t in the Supported Data Types table for this operation" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input_zp", + "type": "in_out_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "output_zp", + "type": "in_out_t", + "description": "Output tensor zero point. Must be zero for non-int8 types." + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor 4D" + } + ] + }, + { + "name": "CONV2D", + "category": "layer", + "attributes": [ + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "dilation", + "type": "i32_t", + "description": "[dilation_y, dilation_x]" + }, + { + "name": "acc_type", + "type": "acc_type_t", + "description": "Enumerated type, must be one of INT32, INT48, FP16, FP32 matching the type of acc_t in the Supported Data Types table for this operation" + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KH x KW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data. Bias data will be broadcast if BC == 1." + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "CONV3D", + "category": "layer", + "attributes": [ + { + "name": "pad", + "type": "i32_t", + "description": "[pad_d0, pad_d1, pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_d, stride_y, stride_x]" + }, + { + "name": "dilation", + "type": "i32_t", + "description": "[dilation_d, dilation_y, dilation_x]" + }, + { + "name": "acc_type", + "type": "acc_type_t", + "description": "Enumerated type, must be one of INT32, INT48, FP16, FP32 matching the type of acc_t in the Supported Data Types table for this operation" + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KDxKHxKW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data. Bias data will be broadcast if BC == 1." + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "DEPTHWISE_CONV2D", + "category": "layer", + "attributes": [ + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "dilation", + "type": "i32_t", + "description": "[dilation_y, dilation_x]" + }, + { + "name": "acc_type", + "type": "acc_type_t", + "description": "Enumerated type, must be one of INT32, INT48, FP16, FP32 matching the type of acc_t in the Supported Data Types table for this operation" + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KH x KW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data. Bias data will be broadcast if BC == 1." + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "FFT2D", + "attributes": [ + { + "name": "inverse", + "type": "bool_t", + "description": "false for forward FFT, true for inverse FFT" + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input_real", + "type": "in_out_t", + "description": "Real part of the complex input. H,W must be powers of two." + }, + { + "name": "input_imag", + "type": "in_out_t", + "description": "Imaginary part of the complex input. H,W must be powers of two." + } + ], + "outputs": [ + { + "name": "output_real", + "type": "in_out_t", + "description": "Real part of the complex output." + }, + { + "name": "output_imag", + "type": "in_out_t", + "description": "Imaginary part of the complex output." + } + ] + }, + { + "name": "MATMUL", + "attributes": [], + "inputs": [ + { + "name": "A", + "type": "in_t", + "description": "Input tensor A, N matrices of size HxC" + }, + { + "name": "B", + "type": "in_t", + "description": "Input tensor B, N matrices of size CxW" + }, + { + "name": "A_zp", + "type": "in_t", + "description": "Input tensor A zero point. Must be zero for non-int8 types." + }, + { + "name": "B_zp", + "type": "in_t", + "description": "Input tensor B zero point. Must be zero for non-int8 types." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor, N matrices of size HxW" + } + ] + }, + { + "name": "MAX_POOL2D", + "category": "pool", + "attributes": [ + { + "name": "kernel", + "type": "i32_t", + "description": "[kernel_y, kernel_x]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "pad", + "type": "i32_t", + "description": "[pad_top, pad_bottom, pad_left, pad_right]" + }, + { + "name": "nan_mode", + "type": "nan_propagation_mode_t", + "description": "PROPAGATE or IGNORE. Set to PROPAGATE by default. This attribute affects the floating-point NaN propagation approach. This attribute is ignored by non floating-point types." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor 4D" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor 4D" + } + ] + }, + { + "name": "RFFT2D", + "attributes": [ + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input_real", + "type": "in_out_t", + "description": "Real input. H,W must be powers of two." + } + ], + "outputs": [ + { + "name": "output_real", + "type": "in_out_t", + "description": "Real part of the complex output" + }, + { + "name": "output_imag", + "type": "in_out_t", + "description": "Imaginary part of the complex output." + } + ] + }, + { + "name": "TRANSPOSE_CONV2D", + "category": "layer", + "attributes": [ + { + "name": "out_pad", + "type": "i32_t", + "description": "[out_pad_top, out_pad_bottom, out_pad_left, out_pad_right]" + }, + { + "name": "stride", + "type": "i32_t", + "description": "[stride_y, stride_x]" + }, + { + "name": "acc_type", + "type": "acc_type_t", + "description": "Enumerated type, must be one of INT32, INT48, FP16, FP32 matching the type of acc_t in the Supported Data Types table for this operation" + }, + { + "name": "local_bound", + "type": "bool_t", + "description": "This optional attribute affects the floating-point compliance error bound. The default of false allows for direct and transform based, fast convolution algorithms. Only set to true if direct dot-product calculation precision is required." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "weight", + "type": "weight_t", + "description": "Weight kernel size KH x KW" + }, + { + "name": "bias", + "type": "out_t", + "description": "Per output channel bias data. Bias data will be broadcast if BC == 1." + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. Must be zero for non-int8 types." + }, + { + "name": "weight_zp", + "type": "weight_t", + "description": "Weight zero point. Must be zero for non-int8 types." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "CLAMP", + "category": "activation", + "attributes": [ + { + "name": "min_val", + "type": "in_out_t", + "description": "Minimum clip value" + }, + { + "name": "max_val", + "type": "in_out_t", + "description": "Maximum clip value" + }, + { + "name": "nan_mode", + "type": "nan_propagation_mode_t", + "description": "PROPAGATE or IGNORE. Set to PROPAGATE by default. This attribute affects the floating-point NaN propagation approach. This attribute is ignored by non floating-point types." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "ERF", + "category": "activation", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "SIGMOID", + "category": "activation", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "TANH", + "category": "activation", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "ADD", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "ARITHMETIC_RIGHT_SHIFT", + "attributes": [ + { + "name": "round", + "type": "bool_t", + "description": "If true then the shift is rounded" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "BITWISE_AND", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "BITWISE_OR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "BITWISE_XOR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "INTDIV", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "LOGICAL_AND", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "LOGICAL_LEFT_SHIFT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "LOGICAL_RIGHT_SHIFT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "LOGICAL_OR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "LOGICAL_XOR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "MAXIMUM", + "attributes": [ + { + "name": "nan_mode", + "type": "nan_propagation_mode_t", + "description": "PROPAGATE or IGNORE. Set to PROPAGATE by default. This attribute affects the floating-point NaN propagation approach. This attribute is ignored by non floating-point types." + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "MINIMUM", + "attributes": [ + { + "name": "nan_mode", + "type": "nan_propagation_mode_t", + "description": "PROPAGATE or IGNORE. Set to PROPAGATE by default. This attribute affects the floating-point NaN propagation approach. This attribute is ignored by non floating-point types." + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "MUL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + }, + { + "name": "shift", + "type": "i8_t", + "description": "Result right shift (used only when in_t is i32_t)" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "POW", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "SUB", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "TABLE", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "table", + "type": "table_t", + "description": "Lookup table tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "ABS", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "BITWISE_NOT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "CEIL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "CLZ", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "COS", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "EXP", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "FLOOR", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "LOG", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "LOGICAL_NOT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "NEGATE", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "input1_zp", + "type": "in_out_t", + "description": "Input 1 zero point. Must be zero for non-int8 types." + }, + { + "name": "output_zp", + "type": "in_out_t", + "description": "Output zero point. Must be zero for non-int8 types." + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "RECIPROCAL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "RSQRT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "SIN", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type and shape as input" + } + ] + }, + { + "name": "SELECT", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "bool_t", + "description": "Input selector tensor" + }, + { + "name": "input2", + "type": "in_out_t", + "description": "Input value tensor if input1 is True" + }, + { + "name": "input3", + "type": "in_out_t", + "description": "Input value tensor if input1 is False" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type as input2 and input3" + } + ] + }, + { + "name": "EQUAL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "GREATER", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "GREATER_EQUAL", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "input2", + "type": "in_t", + "description": "Input tensor with the same rank as input1" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "REDUCE_ALL", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_ANY", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_MAX", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + }, + { + "name": "nan_mode", + "type": "nan_propagation_mode_t", + "description": "PROPAGATE or IGNORE. Set to PROPAGATE by default. This attribute affects the floating-point NaN propagation approach. This attribute is ignored by non floating-point types." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_MIN", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + }, + { + "name": "nan_mode", + "type": "nan_propagation_mode_t", + "description": "PROPAGATE or IGNORE. Set to PROPAGATE by default. This attribute affects the floating-point NaN propagation approach. This attribute is ignored by non floating-point types." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_PRODUCT", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "REDUCE_SUM", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reduce, in range from 0 to rank(shape1)-1" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same rank as the input tensor." + } + ] + }, + { + "name": "CONCAT", + "category": "tensor", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis along which concatenation is to occur, in range from 0 to rank(shape)-1" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "List of input tensors. All inputs must have the same rank and data type" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "PAD", + "category": "tensor", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "padding", + "type": "shape_t", + "description": "Number of pad elements at the start and end of each dimension. The values in padding are interpreted as start, end of each dimension. As an example for rank 2, the values would be interpreted as [start_dim0, end_dim0, start_dim1, end_dim1]." + }, + { + "name": "pad_const", + "type": "in_out_t", + "description": "The value to be used as padding." + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type as the input tensor" + } + ] + }, + { + "name": "RESHAPE", + "category": "shape", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "shape", + "type": "shape_t", + "description": "shape_t giving the new shape." + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, size as the input tensor" + } + ] + }, + { + "name": "REVERSE", + "category": "tensor", + "attributes": [ + { + "name": "axis", + "type": "i32_t", + "description": "Axis to reverse, in range from 0 to rank(shape)-1" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor. Same shape as input tensor" + } + ] + }, + { + "name": "SLICE", + "category": "tensor", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "start", + "type": "shape_t", + "description": "List of integer coordinates, of length equal to the rank of input1. Start coordinate for slicing." + }, + { + "name": "size", + "type": "shape_t", + "description": "List of integer size values, of length equal to the rank of input1. Size of the input to be used." + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type as the input tensor" + } + ] + }, + { + "name": "TILE", + "category": "tensor", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + }, + { + "name": "multiples", + "type": "shape_t", + "description": "Number of times to replicate input1 in each dimension" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, rank as the input tensor" + } + ] + }, + { + "name": "TRANSPOSE", + "category": "transform", + "attributes": [ + { + "name": "perms", + "type": "i32_t", + "description": "List of integers of length equal to the rank of input1. Values must be valid dimensions within shape1, and may not be repeated." + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of same type, rank as the input tensor" + } + ] + }, + { + "name": "GATHER", + "category": "transform", + "attributes": [], + "inputs": [ + { + "name": "values", + "type": "in_out_t", + "description": "3D value tensor" + }, + { + "name": "indices", + "type": "index_t", + "description": "2D index tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "3D output tensor" + } + ] + }, + { + "name": "SCATTER", + "category": "transform", + "attributes": [], + "inputs": [ + { + "name": "values_in", + "type": "in_out_t", + "description": "3D values in tensor" + }, + { + "name": "indices", + "type": "index_t", + "description": "2D index tensor" + }, + { + "name": "input", + "type": "in_out_t", + "description": "3D input tensor" + } + ], + "outputs": [ + { + "name": "values_out", + "type": "in_out_t", + "description": "3D output tensor" + } + ] + }, + { + "name": "RESIZE", + "attributes": [ + { + "name": "mode", + "type": "resize_mode_t", + "description": "BILINEAR or NEAREST" + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "scale", + "type": "shape_t", + "description": "[scale_y_n, scale_y_d, scale_x_n, scale_x_d]" + }, + { + "name": "offset", + "type": "shape_t", + "description": "[offset_y, offset_x]" + }, + { + "name": "border", + "type": "shape_t", + "description": "[border_y, border_x]" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "CAST", + "attributes": [], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "RESCALE", + "category": "quantization", + "attributes": [ + { + "name": "scale32", + "type": "bool_t", + "description": "if (scale32) mul_t=i32_t else mul_t=i16_t" + }, + { + "name": "rounding_mode", + "type": "rounding_mode_t", + "description": "Select rounding mode" + }, + { + "name": "per_channel", + "type": "bool_t", + "description": "if (per_channel) NC=shape[rank(shape)-1] else NC=1" + }, + { + "name": "input_unsigned", + "type": "bool_t", + "description": "If True, treat the input values as unsigned." + }, + { + "name": "output_unsigned", + "type": "bool_t", + "description": "If True, treat the output values as unsigned." + } + ], + "inputs": [ + { + "name": "input", + "type": "in_t", + "description": "Input tensor" + }, + { + "name": "multiplier", + "type": "mul_t", + "description": "Scaling multiplier array" + }, + { + "name": "shift", + "type": "i8_t", + "description": "Scaling shift array" + }, + { + "name": "input_zp", + "type": "in_t", + "description": "Input tensor zero point. int8/uint8 can have zero point within their valid range. uint16 zero point must be either 0 or 32768. All other types must have zero point equal to 0." + }, + { + "name": "output_zp", + "type": "out_t", + "description": "Output tensor zero point.int8/uint8 can have zero point within their valid range. uint16 zero point must be either 0 or 32768. All other types must have zero point equal to 0." + } + ], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor with the same shape as input" + } + ] + }, + { + "name": "CONST", + "category": "constant", + "attributes": [ + { + "name": "values", + "type": "out_t", + "description": "Constant values" + } + ], + "inputs": [], + "outputs": [ + { + "name": "output", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "IDENTITY", + "category": "tensor", + "attributes": [], + "inputs": [ + { + "name": "input1", + "type": "in_out_t", + "description": "Input tensor" + } + ], + "outputs": [ + { + "name": "output", + "type": "in_out_t", + "description": "Output tensor of the same type, size as the input tensor" + } + ] + }, + { + "name": "CUSTOM", + "category": "custom", + "attributes": [ + { + "name": "operator_name", + "type": "String", + "description": "String which tells the backend which custom operator is being called" + }, + { + "name": "domain_name", + "type": "String", + "description": "String identifier which can help avoid name collisions on the operator field. Different implementations of a given operator would be in different domains. Implementations can choose which domains they want to support." + }, + { + "name": "implementation_attrs", + "type": "String", + "description": "String value containing implementation specific attributes which apply to the operation" + } + ], + "inputs": [ + { + "name": "input_list", + "type": "tensor_list_t", + "description": "List of input tensors" + } + ], + "outputs": [ + { + "name": "output_list", + "type": "tensor_list_t", + "description": "List of output tensors" + } + ] + }, + { + "name": "COND_IF", + "attributes": [ + { + "name": "then_graph", + "type": "tosa_graph_t", + "description": "TOSA graph to execute if condition is true" + }, + { + "name": "else_graph", + "type": "tosa_graph_t", + "description": "TOSA graph to execute if condition is false" + } + ], + "inputs": [ + { + "name": "condition", + "type": "bool_t", + "description": "Input condition as a size 1 tensor" + }, + { + "name": "input_list", + "type": "tensor_list_t", + "description": "List of input tensors" + } + ], + "outputs": [ + { + "name": "output_list", + "type": "tensor_list_t", + "description": "List of output tensors" + } + ] + }, + { + "name": "WHILE_LOOP", + "attributes": [ + { + "name": "cond_graph", + "type": "tosa_graph_t", + "description": "TOSA graph to evaluate the condition" + }, + { + "name": "body_graph", + "type": "tosa_graph_t", + "description": "TOSA graph to execute the loop body" + } + ], + "inputs": [ + { + "name": "input_list", + "type": "tensor_list_t", + "description": "List of input tensors" + } + ], + "outputs": [ + { + "name": "output_list", + "type": "tensor_list_t", + "description": "List of output tensors" + } + ] + }, + { + "name": "VARIABLE", + "attributes": [ + { + "name": "name", + "type": "String", + "description": "Globally unique identifier for the declared variable tensor." + }, + { + "name": "var_shape", + "type": "tensor_size_t", + "description": "The variable tensor shape" + }, + { + "name": "type", + "type": "var_t", + "description": "Type of the tensor variable elements." + }, + { + "name": "initial_value", + "type": "in_t", + "description": "Initial value of the variable tensor. This argument is optional with default value NULL." + } + ], + "inputs": [], + "outputs": [] + }, + { + "name": "VARIABLE_WRITE", + "attributes": [ + { + "name": "name", + "type": "String", + "description": "Globally unique identifier of the variable tensor that is writing to" + } + ], + "inputs": [ + { + "name": "input1", + "type": "in_t", + "description": "Input tensor" + } + ], + "outputs": [] + }, + { + "name": "VARIABLE_READ", + "attributes": [ + { + "name": "name", + "type": "String", + "description": "Globally unique identifier of the variable tensor that is reading from" + } + ], + "inputs": [], + "outputs": [ + { + "name": "output1", + "type": "out_t", + "description": "Output tensor" + } + ] + }, + { + "name": "CONST_SHAPE", + "category": "constant", + "attributes": [ + { + "name": "values", + "type": "shape_t", + "description": "Constant shape" + } + ], + "inputs": [], + "outputs": [ + { + "name": "output", + "type": "shape_t", + "description": "Output shape" + } + ] + } +] \ No newline at end of file diff --git a/source/tosa-schema-v0.80.js b/source/tosa-schema-v0.80.js new file mode 100644 index 0000000000..8359badc23 --- /dev/null +++ b/source/tosa-schema-v0.80.js @@ -0,0 +1,724 @@ + +export const tosa = {}; + +tosa.DType = { + UNKNOWN: 0, + BOOL: 1, + UINT8: 2, + INT4: 3, + INT8: 4, + INT16: 5, + INT32: 6, + INT48: 7, + FP32: 8, + UINT16: 9, + FP16: 10, + BF16: 11, + SHAPE: 12 +}; + +tosa.ResizeMode = { + UNKNOWN: 0, + NEAREST: 1, + BILINEAR: 2 +}; + +tosa.Op = { + UNKNOWN: 0, + ARGMAX: 1, + AVG_POOL2D: 2, + CONV2D: 3, + CONV3D: 4, + DEPTHWISE_CONV2D: 5, + FULLY_CONNECTED: 6, + MATMUL: 7, + MAX_POOL2D: 8, + TRANSPOSE_CONV2D: 9, + CLAMP: 10, + RESERVED: 11, + SIGMOID: 12, + TANH: 13, + ADD: 14, + ARITHMETIC_RIGHT_SHIFT: 15, + BITWISE_AND: 16, + BITWISE_OR: 17, + BITWISE_XOR: 18, + INTDIV: 19, + LOGICAL_AND: 20, + LOGICAL_LEFT_SHIFT: 21, + LOGICAL_RIGHT_SHIFT: 22, + LOGICAL_OR: 23, + LOGICAL_XOR: 24, + MAXIMUM: 25, + MINIMUM: 26, + MUL: 27, + POW: 28, + SUB: 29, + TABLE: 30, + ABS: 31, + BITWISE_NOT: 32, + CEIL: 33, + CLZ: 34, + EXP: 35, + FLOOR: 36, + LOG: 37, + LOGICAL_NOT: 38, + NEGATE: 39, + RECIPROCAL: 40, + RSQRT: 41, + SELECT: 42, + EQUAL: 43, + GREATER: 44, + GREATER_EQUAL: 45, + REDUCE_ANY: 46, + REDUCE_ALL: 47, + REDUCE_MAX: 48, + REDUCE_MIN: 49, + REDUCE_PRODUCT: 50, + REDUCE_SUM: 51, + CONCAT: 52, + PAD: 53, + RESHAPE: 54, + REVERSE: 55, + SLICE: 56, + TILE: 57, + TRANSPOSE: 58, + GATHER: 59, + SCATTER: 60, + RESIZE: 61, + CAST: 62, + RESCALE: 63, + CONST: 64, + IDENTITY: 65, + CUSTOM: 66, + COND_IF: 67, + WHILE_LOOP: 68, + FFT2D: 69, + RFFT2D: 70, + ERF: 71, + DIM: 72 +}; + +tosa.Attribute = class { + + static decode(reader, position, type) { + switch (type) { + case 1: return tosa.PoolAttribute.decode(reader, position); + case 2: return tosa.ConvAttribute.decode(reader, position); + case 3: return tosa.TransposeConvAttribute.decode(reader, position); + case 4: return tosa.PadAttribute.decode(reader, position); + case 5: return tosa.AxisAttribute.decode(reader, position); + case 6: return tosa.ReshapeAttribute.decode(reader, position); + case 7: return tosa.SliceAttribute.decode(reader, position); + case 8: return tosa.TileAttribute.decode(reader, position); + case 9: return tosa.ResizeAttribute.decode(reader, position); + case 10: return tosa.ClampAttribute.decode(reader, position); + case 11: return tosa.RescaleAttribute.decode(reader, position); + case 12: return tosa.MulAttribute.decode(reader, position); + case 13: return tosa.ArithmeticRightShiftAttribute.decode(reader, position); + case 14: return tosa.CondIfAttribute.decode(reader, position); + case 15: return tosa.WhileLoopAttribute.decode(reader, position); + case 16: return tosa.TransposeAttribute.decode(reader, position); + case 17: return tosa.TableAttribute.decode(reader, position); + case 18: return tosa.MatMulAttribute.decode(reader, position); + case 19: return tosa.FullyConnectedAttribute.decode(reader, position); + case 20: return tosa.NegateAttribute.decode(reader, position); + case 21: return tosa.CustomAttribute.decode(reader, position); + case 22: return tosa.FFTAttribute.decode(reader, position); + case 23: return tosa.RFFTAttribute.decode(reader, position); + default: return undefined; + } + } + + static decodeText(reader, json, type) { + switch (type) { + case 'PoolAttribute': return tosa.PoolAttribute.decodeText(reader, json); + case 'ConvAttribute': return tosa.ConvAttribute.decodeText(reader, json); + case 'TransposeConvAttribute': return tosa.TransposeConvAttribute.decodeText(reader, json); + case 'PadAttribute': return tosa.PadAttribute.decodeText(reader, json); + case 'AxisAttribute': return tosa.AxisAttribute.decodeText(reader, json); + case 'ReshapeAttribute': return tosa.ReshapeAttribute.decodeText(reader, json); + case 'SliceAttribute': return tosa.SliceAttribute.decodeText(reader, json); + case 'TileAttribute': return tosa.TileAttribute.decodeText(reader, json); + case 'ResizeAttribute': return tosa.ResizeAttribute.decodeText(reader, json); + case 'ClampAttribute': return tosa.ClampAttribute.decodeText(reader, json); + case 'RescaleAttribute': return tosa.RescaleAttribute.decodeText(reader, json); + case 'MulAttribute': return tosa.MulAttribute.decodeText(reader, json); + case 'ArithmeticRightShiftAttribute': return tosa.ArithmeticRightShiftAttribute.decodeText(reader, json); + case 'CondIfAttribute': return tosa.CondIfAttribute.decodeText(reader, json); + case 'WhileLoopAttribute': return tosa.WhileLoopAttribute.decodeText(reader, json); + case 'TransposeAttribute': return tosa.TransposeAttribute.decodeText(reader, json); + case 'TableAttribute': return tosa.TableAttribute.decodeText(reader, json); + case 'MatMulAttribute': return tosa.MatMulAttribute.decodeText(reader, json); + case 'FullyConnectedAttribute': return tosa.FullyConnectedAttribute.decodeText(reader, json); + case 'NegateAttribute': return tosa.NegateAttribute.decodeText(reader, json); + case 'CustomAttribute': return tosa.CustomAttribute.decodeText(reader, json); + case 'FFTAttribute': return tosa.FFTAttribute.decodeText(reader, json); + case 'RFFTAttribute': return tosa.RFFTAttribute.decodeText(reader, json); + default: return undefined; + } + } +}; + +tosa.PoolAttribute = class PoolAttribute { + + static decode(reader, position) { + const $ = new tosa.PoolAttribute(); + $.pad = reader.array(position, 4, Int32Array); + $.kernel = reader.array(position, 6, Int32Array); + $.stride = reader.array(position, 8, Int32Array); + $.input_zp = reader.int32_(position, 10, 0); + $.output_zp = reader.int32_(position, 12, 0); + $.accum_dtype = reader.uint32_(position, 14, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.PoolAttribute(); + $.pad = reader.array(json.pad, Int32Array); + $.kernel = reader.array(json.kernel, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.input_zp = reader.value(json.input_zp, 0); + $.output_zp = reader.value(json.output_zp, 0); + $.accum_dtype = tosa.DType[json.accum_dtype]; + return $; + } +}; + +tosa.ConvAttribute = class ConvAttribute { + + static decode(reader, position) { + const $ = new tosa.ConvAttribute(); + $.pad = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.dilation = reader.array(position, 8, Int32Array); + $.input_zp = reader.int32_(position, 10, 0); + $.weight_zp = reader.int32_(position, 12, 0); + $.local_bound = reader.bool_(position, 14, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ConvAttribute(); + $.pad = reader.array(json.pad, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.dilation = reader.array(json.dilation, Int32Array); + $.input_zp = reader.value(json.input_zp, 0); + $.weight_zp = reader.value(json.weight_zp, 0); + $.local_bound = reader.value(json.local_bound, false); + return $; + } +}; + +tosa.TransposeConvAttribute = class TransposeConvAttribute { + + static decode(reader, position) { + const $ = new tosa.TransposeConvAttribute(); + $.out_pad = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.output_shape = reader.array(position, 8, Int32Array); + $.input_zp = reader.int32_(position, 10, 0); + $.weight_zp = reader.int32_(position, 12, 0); + $.local_bound = reader.bool_(position, 14, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TransposeConvAttribute(); + $.out_pad = reader.array(json.out_pad, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.output_shape = reader.array(json.output_shape, Int32Array); + $.input_zp = reader.value(json.input_zp, 0); + $.weight_zp = reader.value(json.weight_zp, 0); + $.local_bound = reader.value(json.local_bound, false); + return $; + } +}; + +tosa.PadAttribute = class PadAttribute { + + static decode(reader, position) { + const $ = new tosa.PadAttribute(); + $.padding = reader.array(position, 4, Int32Array); + $.pad_const_int = reader.int32_(position, 6, 0); + $.pad_const_fp = reader.array(position, 8, Uint8Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.PadAttribute(); + $.padding = reader.array(json.padding, Int32Array); + $.pad_const_int = reader.value(json.pad_const_int, 0); + $.pad_const_fp = reader.array(json.pad_const_fp, Uint8Array); + return $; + } +}; + +tosa.AxisAttribute = class AxisAttribute { + + static decode(reader, position) { + const $ = new tosa.AxisAttribute(); + $.axis = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.AxisAttribute(); + $.axis = reader.value(json.axis, 0); + return $; + } +}; + +tosa.ReshapeAttribute = class ReshapeAttribute { + + static decode(reader, position) { + const $ = new tosa.ReshapeAttribute(); + $.new_shape = reader.array(position, 4, Int32Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReshapeAttribute(); + $.new_shape = reader.array(json.new_shape, Int32Array); + return $; + } +}; + +tosa.SliceAttribute = class SliceAttribute { + + static decode(reader, position) { + const $ = new tosa.SliceAttribute(); + $.start = reader.array(position, 4, Int32Array); + $.size = reader.array(position, 6, Int32Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.SliceAttribute(); + $.start = reader.array(json.start, Int32Array); + $.size = reader.array(json.size, Int32Array); + return $; + } +}; + +tosa.TileAttribute = class TileAttribute { + + static decode(reader, position) { + const $ = new tosa.TileAttribute(); + $.multiples = reader.array(position, 4, Int32Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TileAttribute(); + $.multiples = reader.array(json.multiples, Int32Array); + return $; + } +}; + +tosa.ResizeAttribute = class ResizeAttribute { + + static decode(reader, position) { + const $ = new tosa.ResizeAttribute(); + $.scale = reader.array(position, 4, Int16Array); + $.offset = reader.array(position, 6, Int16Array); + $.border = reader.array(position, 8, Int16Array); + $.mode = reader.uint32_(position, 10, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ResizeAttribute(); + $.scale = reader.array(json.scale, Int16Array); + $.offset = reader.array(json.offset, Int16Array); + $.border = reader.array(json.border, Int16Array); + $.mode = tosa.ResizeMode[json.mode]; + return $; + } +}; + +tosa.ClampAttribute = class ClampAttribute { + + static decode(reader, position) { + const $ = new tosa.ClampAttribute(); + $.min_int = reader.int32_(position, 4, 0); + $.max_int = reader.int32_(position, 6, 0); + $.min_fp = reader.array(position, 8, Uint8Array); + $.max_fp = reader.array(position, 10, Uint8Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ClampAttribute(); + $.min_int = reader.value(json.min_int, 0); + $.max_int = reader.value(json.max_int, 0); + $.min_fp = reader.array(json.min_fp, Uint8Array); + $.max_fp = reader.array(json.max_fp, Uint8Array); + return $; + } +}; + +tosa.RescaleAttribute = class RescaleAttribute { + + static decode(reader, position) { + const $ = new tosa.RescaleAttribute(); + $.input_zp = reader.int32_(position, 4, 0); + $.output_zp = reader.int32_(position, 6, 0); + $.multiplier = reader.array(position, 8, Int32Array); + $.shift = reader.array(position, 10, Int32Array); + $.scale32 = reader.bool_(position, 12, false); + $.double_round = reader.bool_(position, 14, false); + $.per_channel = reader.bool_(position, 16, false); + $.input_unsigned = reader.bool_(position, 18, false); + $.output_unsigned = reader.bool_(position, 20, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.RescaleAttribute(); + $.input_zp = reader.value(json.input_zp, 0); + $.output_zp = reader.value(json.output_zp, 0); + $.multiplier = reader.array(json.multiplier, Int32Array); + $.shift = reader.array(json.shift, Int32Array); + $.scale32 = reader.value(json.scale32, false); + $.double_round = reader.value(json.double_round, false); + $.per_channel = reader.value(json.per_channel, false); + $.input_unsigned = reader.value(json.input_unsigned, false); + $.output_unsigned = reader.value(json.output_unsigned, false); + return $; + } +}; + +tosa.MulAttribute = class MulAttribute { + + static decode(reader, position) { + const $ = new tosa.MulAttribute(); + $.shift = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.MulAttribute(); + $.shift = reader.value(json.shift, 0); + return $; + } +}; + +tosa.ArithmeticRightShiftAttribute = class ArithmeticRightShiftAttribute { + + static decode(reader, position) { + const $ = new tosa.ArithmeticRightShiftAttribute(); + $.round = reader.bool_(position, 4, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ArithmeticRightShiftAttribute(); + $.round = reader.value(json.round, false); + return $; + } +}; + +tosa.CondIfAttribute = class CondIfAttribute { + + static decode(reader, position) { + const $ = new tosa.CondIfAttribute(); + $.then_branch = reader.string_(position, 4, null); + $.else_branch = reader.string_(position, 6, null); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.CondIfAttribute(); + $.then_branch = reader.value(json.then_branch, null); + $.else_branch = reader.value(json.else_branch, null); + return $; + } +}; + +tosa.WhileLoopAttribute = class WhileLoopAttribute { + + static decode(reader, position) { + const $ = new tosa.WhileLoopAttribute(); + $.cond_branch = reader.string_(position, 4, null); + $.body_branch = reader.string_(position, 6, null); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.WhileLoopAttribute(); + $.cond_branch = reader.value(json.cond_branch, null); + $.body_branch = reader.value(json.body_branch, null); + return $; + } +}; + +tosa.TransposeAttribute = class TransposeAttribute { + + static decode(reader, position) { + const $ = new tosa.TransposeAttribute(); + $.perms = reader.array(position, 4, Int32Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TransposeAttribute(); + $.perms = reader.array(json.perms, Int32Array); + return $; + } +}; + +tosa.TableAttribute = class TableAttribute { + + static decode(reader, position) { + const $ = new tosa.TableAttribute(); + $.table = reader.array(position, 4, Int16Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TableAttribute(); + $.table = reader.array(json.table, Int16Array); + return $; + } +}; + +tosa.MatMulAttribute = class MatMulAttribute { + + static decode(reader, position) { + const $ = new tosa.MatMulAttribute(); + $.a_zp = reader.int32_(position, 4, 0); + $.b_zp = reader.int32_(position, 6, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.MatMulAttribute(); + $.a_zp = reader.value(json.a_zp, 0); + $.b_zp = reader.value(json.b_zp, 0); + return $; + } +}; + +tosa.FullyConnectedAttribute = class FullyConnectedAttribute { + + static decode(reader, position) { + const $ = new tosa.FullyConnectedAttribute(); + $.input_zp = reader.int32_(position, 4, 0); + $.weight_zp = reader.int32_(position, 6, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.FullyConnectedAttribute(); + $.input_zp = reader.value(json.input_zp, 0); + $.weight_zp = reader.value(json.weight_zp, 0); + return $; + } +}; + +tosa.NegateAttribute = class NegateAttribute { + + static decode(reader, position) { + const $ = new tosa.NegateAttribute(); + $.input1_zp = reader.int32_(position, 4, 0); + $.output_zp = reader.int32_(position, 6, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.NegateAttribute(); + $.input1_zp = reader.value(json.input1_zp, 0); + $.output_zp = reader.value(json.output_zp, 0); + return $; + } +}; + +tosa.CustomAttribute = class CustomAttribute { + + static decode(reader, position) { + const $ = new tosa.CustomAttribute(); + $.operator_name = reader.string_(position, 4, null); + $.domain_name = reader.string_(position, 6, null); + $.implementation_attrs = reader.array(position, 8, Uint8Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.CustomAttribute(); + $.operator_name = reader.value(json.operator_name, null); + $.domain_name = reader.value(json.domain_name, null); + $.implementation_attrs = reader.array(json.implementation_attrs, Uint8Array); + return $; + } +}; + +tosa.FFTAttribute = class FFTAttribute { + + static decode(reader, position) { + const $ = new tosa.FFTAttribute(); + $.inverse = reader.bool_(position, 4, false); + $.local_bound = reader.bool_(position, 6, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.FFTAttribute(); + $.inverse = reader.value(json.inverse, false); + $.local_bound = reader.value(json.local_bound, false); + return $; + } +}; + +tosa.RFFTAttribute = class RFFTAttribute { + + static decode(reader, position) { + const $ = new tosa.RFFTAttribute(); + $.local_bound = reader.bool_(position, 4, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.RFFTAttribute(); + $.local_bound = reader.value(json.local_bound, false); + return $; + } +}; + +tosa.Version = class Version { + + static decode(reader, position) { + const $ = new tosa.Version(); + $._major = reader.int32_(position, 4, -1); + $._minor = reader.int32_(position, 6, -1); + $._patch = reader.int32_(position, 8, -1); + $._draft = reader.bool_(position, 10, true); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.Version(); + $._major = reader.value(json._major, -1); + $._minor = reader.value(json._minor, -1); + $._patch = reader.value(json._patch, -1); + $._draft = reader.value(json._draft, true); + return $; + } +}; + +tosa.TosaTensor = class TosaTensor { + + static decode(reader, position) { + const $ = new tosa.TosaTensor(); + $.name = reader.string_(position, 4, null); + $.shape = reader.array(position, 6, Int32Array); + $.type = reader.uint32_(position, 8, 0); + $.data = reader.array(position, 10, Uint8Array); + $.variable = reader.bool_(position, 12, false); + $.is_unranked = reader.bool_(position, 14, false); + $.variable_name = reader.string_(position, 16, null); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaTensor(); + $.name = reader.value(json.name, null); + $.shape = reader.array(json.shape, Int32Array); + $.type = tosa.DType[json.type]; + $.data = reader.array(json.data, Uint8Array); + $.variable = reader.value(json.variable, false); + $.is_unranked = reader.value(json.is_unranked, false); + $.variable_name = reader.value(json.variable_name, null); + return $; + } +}; + +tosa.TosaOperator = class TosaOperator { + + static decode(reader, position) { + const $ = new tosa.TosaOperator(); + $.op = reader.uint32_(position, 4, 0); + $.attribute = reader.union(position, 6, tosa.Attribute); + $.inputs = reader.strings_(position, 10); + $.outputs = reader.strings_(position, 12); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaOperator(); + $.op = tosa.Op[json.op]; + $.attribute = tosa.Attribute.decodeText(reader, json.attribute, json.attribute_type); + $.inputs = reader.array(json.inputs); + $.outputs = reader.array(json.outputs); + return $; + } +}; + +tosa.TosaBasicBlock = class TosaBasicBlock { + + static decode(reader, position) { + const $ = new tosa.TosaBasicBlock(); + $.name = reader.string_(position, 4, null); + $.operators = reader.tables(position, 6, tosa.TosaOperator); + $.tensors = reader.tables(position, 8, tosa.TosaTensor); + $.inputs = reader.strings_(position, 10); + $.outputs = reader.strings_(position, 12); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaBasicBlock(); + $.name = reader.value(json.name, null); + $.operators = reader.objects(json.operators, tosa.TosaOperator); + $.tensors = reader.objects(json.tensors, tosa.TosaTensor); + $.inputs = reader.array(json.inputs); + $.outputs = reader.array(json.outputs); + return $; + } +}; + +tosa.TosaRegion = class TosaRegion { + + static decode(reader, position) { + const $ = new tosa.TosaRegion(); + $.name = reader.string_(position, 4, null); + $.blocks = reader.tables(position, 6, tosa.TosaBasicBlock); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaRegion(); + $.name = reader.value(json.name, null); + $.blocks = reader.objects(json.blocks, tosa.TosaBasicBlock); + return $; + } +}; + +tosa.TosaGraph = class TosaGraph { + + static identifier(reader) { + return reader.identifier === 'TOSA'; + } + + static create(reader) { + return tosa.TosaGraph.decode(reader, reader.root); + } + + static createText(reader) { + return tosa.TosaGraph.decodeText(reader, reader.root); + } + + static decode(reader, position) { + const $ = new tosa.TosaGraph(); + $.version = reader.table(position, 4, tosa.Version); + $.regions = reader.tables(position, 6, tosa.TosaRegion); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaGraph(); + $.version = reader.object(json.version, tosa.Version); + $.regions = reader.objects(json.regions, tosa.TosaRegion); + return $; + } +}; diff --git a/source/tosa-schema-v1.0.js b/source/tosa-schema-v1.0.js new file mode 100644 index 0000000000..0057c2db8e --- /dev/null +++ b/source/tosa-schema-v1.0.js @@ -0,0 +1,1556 @@ + +export const tosa = {}; + +tosa.DType = { + UNKNOWN: 0, + BOOL: 1, + INT4: 2, + INT8: 3, + INT16: 4, + INT32: 5, + INT48: 6, + FP32: 7, + FP16: 8, + BF16: 9, + SHAPE: 10, + FP8E4M3: 11, + FP8E5M2: 12 +}; + +tosa.ResizeMode = { + UNKNOWN: 0, + NEAREST: 1, + BILINEAR: 2 +}; + +tosa.NanPropagationMode = { + UNKNOWN: 0, + PROPAGATE: 1, + IGNORE: 2 +}; + +tosa.RoundingMode = { + UNKNOWN: 0, + SINGLE_ROUND: 1, + INEXACT_ROUND: 2, + DOUBLE_ROUND: 3 +}; + +tosa.Op = { + UNKNOWN: 0, + ARGMAX: 1, + AVG_POOL2D: 2, + CONV2D: 3, + CONV3D: 4, + DEPTHWISE_CONV2D: 5, + FFT2D: 6, + MATMUL: 7, + MAX_POOL2D: 8, + RFFT2D: 9, + TRANSPOSE_CONV2D: 10, + CLAMP: 11, + ERF: 12, + SIGMOID: 13, + TANH: 14, + ADD: 15, + ARITHMETIC_RIGHT_SHIFT: 16, + BITWISE_AND: 17, + BITWISE_OR: 18, + BITWISE_XOR: 19, + INTDIV: 20, + LOGICAL_AND: 21, + LOGICAL_LEFT_SHIFT: 22, + LOGICAL_RIGHT_SHIFT: 23, + LOGICAL_OR: 24, + LOGICAL_XOR: 25, + MAXIMUM: 26, + MINIMUM: 27, + MUL: 28, + POW: 29, + SUB: 30, + TABLE: 31, + ABS: 32, + BITWISE_NOT: 33, + CEIL: 34, + CLZ: 35, + COS: 36, + EXP: 37, + FLOOR: 38, + LOG: 39, + LOGICAL_NOT: 40, + NEGATE: 41, + RECIPROCAL: 42, + RSQRT: 43, + SIN: 44, + SELECT: 45, + EQUAL: 46, + GREATER: 47, + GREATER_EQUAL: 48, + REDUCE_ALL: 49, + REDUCE_ANY: 50, + REDUCE_MAX: 51, + REDUCE_MIN: 52, + REDUCE_PRODUCT: 53, + REDUCE_SUM: 54, + CONCAT: 55, + PAD: 56, + RESHAPE: 57, + REVERSE: 58, + SLICE: 59, + TILE: 60, + TRANSPOSE: 61, + GATHER: 62, + SCATTER: 63, + RESIZE: 64, + CAST: 65, + RESCALE: 66, + CONST: 67, + IDENTITY: 68, + CUSTOM: 69, + COND_IF: 70, + WHILE_LOOP: 71, + VARIABLE: 72, + VARIABLE_WRITE: 73, + VARIABLE_READ: 74, + CONST_SHAPE: 75 +}; + +tosa.Attribute = class { + + static decode(reader, position, type) { + switch (type) { + case 1: return tosa.ArgMaxAttribute.decode(reader, position); + case 2: return tosa.AvgPool2dAttribute.decode(reader, position); + case 3: return tosa.Conv2dAttribute.decode(reader, position); + case 4: return tosa.Conv3dAttribute.decode(reader, position); + case 5: return tosa.DepthwiseConv2dAttribute.decode(reader, position); + case 6: return tosa.FFT2dAttribute.decode(reader, position); + case 7: return tosa.MatMulAttribute.decode(reader, position); + case 8: return tosa.MaxPool2dAttribute.decode(reader, position); + case 9: return tosa.RFFT2dAttribute.decode(reader, position); + case 10: return tosa.TransposeConv2dAttribute.decode(reader, position); + case 11: return tosa.ClampAttribute.decode(reader, position); + case 12: return tosa.ErfAttribute.decode(reader, position); + case 13: return tosa.SigmoidAttribute.decode(reader, position); + case 14: return tosa.TanhAttribute.decode(reader, position); + case 15: return tosa.AddAttribute.decode(reader, position); + case 16: return tosa.ArithmeticRightShiftAttribute.decode(reader, position); + case 17: return tosa.BitwiseAndAttribute.decode(reader, position); + case 18: return tosa.BitwiseOrAttribute.decode(reader, position); + case 19: return tosa.BitwiseXorAttribute.decode(reader, position); + case 20: return tosa.IntDivAttribute.decode(reader, position); + case 21: return tosa.LogicalAndAttribute.decode(reader, position); + case 22: return tosa.LogicalLeftShiftAttribute.decode(reader, position); + case 23: return tosa.LogicalRightShiftAttribute.decode(reader, position); + case 24: return tosa.LogicalOrAttribute.decode(reader, position); + case 25: return tosa.LogicalXorAttribute.decode(reader, position); + case 26: return tosa.MaximumAttribute.decode(reader, position); + case 27: return tosa.MinimumAttribute.decode(reader, position); + case 28: return tosa.MulAttribute.decode(reader, position); + case 29: return tosa.PowAttribute.decode(reader, position); + case 30: return tosa.SubAttribute.decode(reader, position); + case 31: return tosa.TableAttribute.decode(reader, position); + case 32: return tosa.AbsAttribute.decode(reader, position); + case 33: return tosa.BitwiseNotAttribute.decode(reader, position); + case 34: return tosa.CeilAttribute.decode(reader, position); + case 35: return tosa.ClzAttribute.decode(reader, position); + case 36: return tosa.CosAttribute.decode(reader, position); + case 37: return tosa.ExpAttribute.decode(reader, position); + case 38: return tosa.FloorAttribute.decode(reader, position); + case 39: return tosa.LogAttribute.decode(reader, position); + case 40: return tosa.LogicalNotAttribute.decode(reader, position); + case 41: return tosa.NegateAttribute.decode(reader, position); + case 42: return tosa.ReciprocalAttribute.decode(reader, position); + case 43: return tosa.RsqrtAttribute.decode(reader, position); + case 44: return tosa.SinAttribute.decode(reader, position); + case 45: return tosa.SelectAttribute.decode(reader, position); + case 46: return tosa.EqualAttribute.decode(reader, position); + case 47: return tosa.GreaterAttribute.decode(reader, position); + case 48: return tosa.GreaterEqualAttribute.decode(reader, position); + case 49: return tosa.ReduceAllAttribute.decode(reader, position); + case 50: return tosa.ReduceAnyAttribute.decode(reader, position); + case 51: return tosa.ReduceMaxAttribute.decode(reader, position); + case 52: return tosa.ReduceMinAttribute.decode(reader, position); + case 53: return tosa.ReduceProductAttribute.decode(reader, position); + case 54: return tosa.ReduceSumAttribute.decode(reader, position); + case 55: return tosa.ConcatAttribute.decode(reader, position); + case 56: return tosa.PadAttribute.decode(reader, position); + case 57: return tosa.ReshapeAttribute.decode(reader, position); + case 58: return tosa.ReverseAttribute.decode(reader, position); + case 59: return tosa.SliceAttribute.decode(reader, position); + case 60: return tosa.TileAttribute.decode(reader, position); + case 61: return tosa.TransposeAttribute.decode(reader, position); + case 62: return tosa.GatherAttribute.decode(reader, position); + case 63: return tosa.ScatterAttribute.decode(reader, position); + case 64: return tosa.ResizeAttribute.decode(reader, position); + case 65: return tosa.CastAttribute.decode(reader, position); + case 66: return tosa.RescaleAttribute.decode(reader, position); + case 67: return tosa.ConstAttribute.decode(reader, position); + case 68: return tosa.IdentityAttribute.decode(reader, position); + case 69: return tosa.CustomAttribute.decode(reader, position); + case 70: return tosa.CondIfAttribute.decode(reader, position); + case 71: return tosa.WhileLoopAttribute.decode(reader, position); + case 72: return tosa.VariableAttribute.decode(reader, position); + case 73: return tosa.VariableWriteAttribute.decode(reader, position); + case 74: return tosa.VariableReadAttribute.decode(reader, position); + case 75: return tosa.ConstShapeAttribute.decode(reader, position); + default: return undefined; + } + } + + static decodeText(reader, json, type) { + switch (type) { + case 'ArgMaxAttribute': return tosa.ArgMaxAttribute.decodeText(reader, json); + case 'AvgPool2dAttribute': return tosa.AvgPool2dAttribute.decodeText(reader, json); + case 'Conv2dAttribute': return tosa.Conv2dAttribute.decodeText(reader, json); + case 'Conv3dAttribute': return tosa.Conv3dAttribute.decodeText(reader, json); + case 'DepthwiseConv2dAttribute': return tosa.DepthwiseConv2dAttribute.decodeText(reader, json); + case 'FFT2dAttribute': return tosa.FFT2dAttribute.decodeText(reader, json); + case 'MatMulAttribute': return tosa.MatMulAttribute.decodeText(reader, json); + case 'MaxPool2dAttribute': return tosa.MaxPool2dAttribute.decodeText(reader, json); + case 'RFFT2dAttribute': return tosa.RFFT2dAttribute.decodeText(reader, json); + case 'TransposeConv2dAttribute': return tosa.TransposeConv2dAttribute.decodeText(reader, json); + case 'ClampAttribute': return tosa.ClampAttribute.decodeText(reader, json); + case 'ErfAttribute': return tosa.ErfAttribute.decodeText(reader, json); + case 'SigmoidAttribute': return tosa.SigmoidAttribute.decodeText(reader, json); + case 'TanhAttribute': return tosa.TanhAttribute.decodeText(reader, json); + case 'AddAttribute': return tosa.AddAttribute.decodeText(reader, json); + case 'ArithmeticRightShiftAttribute': return tosa.ArithmeticRightShiftAttribute.decodeText(reader, json); + case 'BitwiseAndAttribute': return tosa.BitwiseAndAttribute.decodeText(reader, json); + case 'BitwiseOrAttribute': return tosa.BitwiseOrAttribute.decodeText(reader, json); + case 'BitwiseXorAttribute': return tosa.BitwiseXorAttribute.decodeText(reader, json); + case 'IntDivAttribute': return tosa.IntDivAttribute.decodeText(reader, json); + case 'LogicalAndAttribute': return tosa.LogicalAndAttribute.decodeText(reader, json); + case 'LogicalLeftShiftAttribute': return tosa.LogicalLeftShiftAttribute.decodeText(reader, json); + case 'LogicalRightShiftAttribute': return tosa.LogicalRightShiftAttribute.decodeText(reader, json); + case 'LogicalOrAttribute': return tosa.LogicalOrAttribute.decodeText(reader, json); + case 'LogicalXorAttribute': return tosa.LogicalXorAttribute.decodeText(reader, json); + case 'MaximumAttribute': return tosa.MaximumAttribute.decodeText(reader, json); + case 'MinimumAttribute': return tosa.MinimumAttribute.decodeText(reader, json); + case 'MulAttribute': return tosa.MulAttribute.decodeText(reader, json); + case 'PowAttribute': return tosa.PowAttribute.decodeText(reader, json); + case 'SubAttribute': return tosa.SubAttribute.decodeText(reader, json); + case 'TableAttribute': return tosa.TableAttribute.decodeText(reader, json); + case 'AbsAttribute': return tosa.AbsAttribute.decodeText(reader, json); + case 'BitwiseNotAttribute': return tosa.BitwiseNotAttribute.decodeText(reader, json); + case 'CeilAttribute': return tosa.CeilAttribute.decodeText(reader, json); + case 'ClzAttribute': return tosa.ClzAttribute.decodeText(reader, json); + case 'CosAttribute': return tosa.CosAttribute.decodeText(reader, json); + case 'ExpAttribute': return tosa.ExpAttribute.decodeText(reader, json); + case 'FloorAttribute': return tosa.FloorAttribute.decodeText(reader, json); + case 'LogAttribute': return tosa.LogAttribute.decodeText(reader, json); + case 'LogicalNotAttribute': return tosa.LogicalNotAttribute.decodeText(reader, json); + case 'NegateAttribute': return tosa.NegateAttribute.decodeText(reader, json); + case 'ReciprocalAttribute': return tosa.ReciprocalAttribute.decodeText(reader, json); + case 'RsqrtAttribute': return tosa.RsqrtAttribute.decodeText(reader, json); + case 'SinAttribute': return tosa.SinAttribute.decodeText(reader, json); + case 'SelectAttribute': return tosa.SelectAttribute.decodeText(reader, json); + case 'EqualAttribute': return tosa.EqualAttribute.decodeText(reader, json); + case 'GreaterAttribute': return tosa.GreaterAttribute.decodeText(reader, json); + case 'GreaterEqualAttribute': return tosa.GreaterEqualAttribute.decodeText(reader, json); + case 'ReduceAllAttribute': return tosa.ReduceAllAttribute.decodeText(reader, json); + case 'ReduceAnyAttribute': return tosa.ReduceAnyAttribute.decodeText(reader, json); + case 'ReduceMaxAttribute': return tosa.ReduceMaxAttribute.decodeText(reader, json); + case 'ReduceMinAttribute': return tosa.ReduceMinAttribute.decodeText(reader, json); + case 'ReduceProductAttribute': return tosa.ReduceProductAttribute.decodeText(reader, json); + case 'ReduceSumAttribute': return tosa.ReduceSumAttribute.decodeText(reader, json); + case 'ConcatAttribute': return tosa.ConcatAttribute.decodeText(reader, json); + case 'PadAttribute': return tosa.PadAttribute.decodeText(reader, json); + case 'ReshapeAttribute': return tosa.ReshapeAttribute.decodeText(reader, json); + case 'ReverseAttribute': return tosa.ReverseAttribute.decodeText(reader, json); + case 'SliceAttribute': return tosa.SliceAttribute.decodeText(reader, json); + case 'TileAttribute': return tosa.TileAttribute.decodeText(reader, json); + case 'TransposeAttribute': return tosa.TransposeAttribute.decodeText(reader, json); + case 'GatherAttribute': return tosa.GatherAttribute.decodeText(reader, json); + case 'ScatterAttribute': return tosa.ScatterAttribute.decodeText(reader, json); + case 'ResizeAttribute': return tosa.ResizeAttribute.decodeText(reader, json); + case 'CastAttribute': return tosa.CastAttribute.decodeText(reader, json); + case 'RescaleAttribute': return tosa.RescaleAttribute.decodeText(reader, json); + case 'ConstAttribute': return tosa.ConstAttribute.decodeText(reader, json); + case 'IdentityAttribute': return tosa.IdentityAttribute.decodeText(reader, json); + case 'CustomAttribute': return tosa.CustomAttribute.decodeText(reader, json); + case 'CondIfAttribute': return tosa.CondIfAttribute.decodeText(reader, json); + case 'WhileLoopAttribute': return tosa.WhileLoopAttribute.decodeText(reader, json); + case 'VariableAttribute': return tosa.VariableAttribute.decodeText(reader, json); + case 'VariableWriteAttribute': return tosa.VariableWriteAttribute.decodeText(reader, json); + case 'VariableReadAttribute': return tosa.VariableReadAttribute.decodeText(reader, json); + case 'ConstShapeAttribute': return tosa.ConstShapeAttribute.decodeText(reader, json); + default: return undefined; + } + } +}; + +tosa.ArgMaxAttribute = class ArgMaxAttribute { + + static decode(reader, position) { + const $ = new tosa.ArgMaxAttribute(); + $.axis = reader.int32_(position, 4, 0); + $.nan_mode = reader.uint32_(position, 6, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ArgMaxAttribute(); + $.axis = reader.value(json.axis, 0); + $.nan_mode = tosa.NanPropagationMode[json.nan_mode]; + return $; + } +}; + +tosa.AvgPool2dAttribute = class AvgPool2dAttribute { + + static decode(reader, position) { + const $ = new tosa.AvgPool2dAttribute(); + $.kernel = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.pad = reader.array(position, 8, Int32Array); + $.acc_type = reader.uint32_(position, 10, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.AvgPool2dAttribute(); + $.kernel = reader.array(json.kernel, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.pad = reader.array(json.pad, Int32Array); + $.acc_type = tosa.DType[json.acc_type]; + return $; + } +}; + +tosa.Conv2dAttribute = class Conv2dAttribute { + + static decode(reader, position) { + const $ = new tosa.Conv2dAttribute(); + $.pad = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.dilation = reader.array(position, 8, Int32Array); + $.local_bound = reader.bool_(position, 10, false); + $.acc_type = reader.uint32_(position, 12, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.Conv2dAttribute(); + $.pad = reader.array(json.pad, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.dilation = reader.array(json.dilation, Int32Array); + $.local_bound = reader.value(json.local_bound, false); + $.acc_type = tosa.DType[json.acc_type]; + return $; + } +}; + +tosa.Conv3dAttribute = class Conv3dAttribute { + + static decode(reader, position) { + const $ = new tosa.Conv3dAttribute(); + $.pad = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.dilation = reader.array(position, 8, Int32Array); + $.local_bound = reader.bool_(position, 10, false); + $.acc_type = reader.uint32_(position, 12, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.Conv3dAttribute(); + $.pad = reader.array(json.pad, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.dilation = reader.array(json.dilation, Int32Array); + $.local_bound = reader.value(json.local_bound, false); + $.acc_type = tosa.DType[json.acc_type]; + return $; + } +}; + +tosa.DepthwiseConv2dAttribute = class DepthwiseConv2dAttribute { + + static decode(reader, position) { + const $ = new tosa.DepthwiseConv2dAttribute(); + $.pad = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.dilation = reader.array(position, 8, Int32Array); + $.local_bound = reader.bool_(position, 10, false); + $.acc_type = reader.uint32_(position, 12, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.DepthwiseConv2dAttribute(); + $.pad = reader.array(json.pad, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.dilation = reader.array(json.dilation, Int32Array); + $.local_bound = reader.value(json.local_bound, false); + $.acc_type = tosa.DType[json.acc_type]; + return $; + } +}; + +tosa.FFT2dAttribute = class FFT2dAttribute { + + static decode(reader, position) { + const $ = new tosa.FFT2dAttribute(); + $.inverse = reader.bool_(position, 4, false); + $.local_bound = reader.bool_(position, 6, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.FFT2dAttribute(); + $.inverse = reader.value(json.inverse, false); + $.local_bound = reader.value(json.local_bound, false); + return $; + } +}; + +tosa.MatMulAttribute = class MatMulAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.MatMulAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.MatMulAttribute(); + return $; + } +}; + +tosa.MaxPool2dAttribute = class MaxPool2dAttribute { + + static decode(reader, position) { + const $ = new tosa.MaxPool2dAttribute(); + $.kernel = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.pad = reader.array(position, 8, Int32Array); + $.nan_mode = reader.uint32_(position, 10, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.MaxPool2dAttribute(); + $.kernel = reader.array(json.kernel, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.pad = reader.array(json.pad, Int32Array); + $.nan_mode = tosa.NanPropagationMode[json.nan_mode]; + return $; + } +}; + +tosa.RFFT2dAttribute = class RFFT2dAttribute { + + static decode(reader, position) { + const $ = new tosa.RFFT2dAttribute(); + $.local_bound = reader.bool_(position, 4, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.RFFT2dAttribute(); + $.local_bound = reader.value(json.local_bound, false); + return $; + } +}; + +tosa.TransposeConv2dAttribute = class TransposeConv2dAttribute { + + static decode(reader, position) { + const $ = new tosa.TransposeConv2dAttribute(); + $.out_pad = reader.array(position, 4, Int32Array); + $.stride = reader.array(position, 6, Int32Array); + $.local_bound = reader.bool_(position, 8, false); + $.acc_type = reader.uint32_(position, 10, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TransposeConv2dAttribute(); + $.out_pad = reader.array(json.out_pad, Int32Array); + $.stride = reader.array(json.stride, Int32Array); + $.local_bound = reader.value(json.local_bound, false); + $.acc_type = tosa.DType[json.acc_type]; + return $; + } +}; + +tosa.ClampAttribute = class ClampAttribute { + + static decode(reader, position) { + const $ = new tosa.ClampAttribute(); + $.min_val = reader.array(position, 4, Uint8Array); + $.max_val = reader.array(position, 6, Uint8Array); + $.nan_mode = reader.uint32_(position, 8, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ClampAttribute(); + $.min_val = reader.array(json.min_val, Uint8Array); + $.max_val = reader.array(json.max_val, Uint8Array); + $.nan_mode = tosa.NanPropagationMode[json.nan_mode]; + return $; + } +}; + +tosa.ErfAttribute = class ErfAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ErfAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ErfAttribute(); + return $; + } +}; + +tosa.SigmoidAttribute = class SigmoidAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.SigmoidAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.SigmoidAttribute(); + return $; + } +}; + +tosa.TanhAttribute = class TanhAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.TanhAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.TanhAttribute(); + return $; + } +}; + +tosa.AddAttribute = class AddAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.AddAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.AddAttribute(); + return $; + } +}; + +tosa.ArithmeticRightShiftAttribute = class ArithmeticRightShiftAttribute { + + static decode(reader, position) { + const $ = new tosa.ArithmeticRightShiftAttribute(); + $.round = reader.bool_(position, 4, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ArithmeticRightShiftAttribute(); + $.round = reader.value(json.round, false); + return $; + } +}; + +tosa.BitwiseAndAttribute = class BitwiseAndAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.BitwiseAndAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.BitwiseAndAttribute(); + return $; + } +}; + +tosa.BitwiseOrAttribute = class BitwiseOrAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.BitwiseOrAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.BitwiseOrAttribute(); + return $; + } +}; + +tosa.BitwiseXorAttribute = class BitwiseXorAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.BitwiseXorAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.BitwiseXorAttribute(); + return $; + } +}; + +tosa.IntDivAttribute = class IntDivAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.IntDivAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.IntDivAttribute(); + return $; + } +}; + +tosa.LogicalAndAttribute = class LogicalAndAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.LogicalAndAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.LogicalAndAttribute(); + return $; + } +}; + +tosa.LogicalLeftShiftAttribute = class LogicalLeftShiftAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.LogicalLeftShiftAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.LogicalLeftShiftAttribute(); + return $; + } +}; + +tosa.LogicalRightShiftAttribute = class LogicalRightShiftAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.LogicalRightShiftAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.LogicalRightShiftAttribute(); + return $; + } +}; + +tosa.LogicalOrAttribute = class LogicalOrAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.LogicalOrAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.LogicalOrAttribute(); + return $; + } +}; + +tosa.LogicalXorAttribute = class LogicalXorAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.LogicalXorAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.LogicalXorAttribute(); + return $; + } +}; + +tosa.MaximumAttribute = class MaximumAttribute { + + static decode(reader, position) { + const $ = new tosa.MaximumAttribute(); + $.nan_mode = reader.uint32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.MaximumAttribute(); + $.nan_mode = tosa.NanPropagationMode[json.nan_mode]; + return $; + } +}; + +tosa.MinimumAttribute = class MinimumAttribute { + + static decode(reader, position) { + const $ = new tosa.MinimumAttribute(); + $.nan_mode = reader.uint32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.MinimumAttribute(); + $.nan_mode = tosa.NanPropagationMode[json.nan_mode]; + return $; + } +}; + +tosa.MulAttribute = class MulAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.MulAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.MulAttribute(); + return $; + } +}; + +tosa.PowAttribute = class PowAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.PowAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.PowAttribute(); + return $; + } +}; + +tosa.SubAttribute = class SubAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.SubAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.SubAttribute(); + return $; + } +}; + +tosa.TableAttribute = class TableAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.TableAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.TableAttribute(); + return $; + } +}; + +tosa.AbsAttribute = class AbsAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.AbsAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.AbsAttribute(); + return $; + } +}; + +tosa.BitwiseNotAttribute = class BitwiseNotAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.BitwiseNotAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.BitwiseNotAttribute(); + return $; + } +}; + +tosa.CeilAttribute = class CeilAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.CeilAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.CeilAttribute(); + return $; + } +}; + +tosa.ClzAttribute = class ClzAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ClzAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ClzAttribute(); + return $; + } +}; + +tosa.CosAttribute = class CosAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.CosAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.CosAttribute(); + return $; + } +}; + +tosa.ExpAttribute = class ExpAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ExpAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ExpAttribute(); + return $; + } +}; + +tosa.FloorAttribute = class FloorAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.FloorAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.FloorAttribute(); + return $; + } +}; + +tosa.LogAttribute = class LogAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.LogAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.LogAttribute(); + return $; + } +}; + +tosa.LogicalNotAttribute = class LogicalNotAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.LogicalNotAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.LogicalNotAttribute(); + return $; + } +}; + +tosa.NegateAttribute = class NegateAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.NegateAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.NegateAttribute(); + return $; + } +}; + +tosa.ReciprocalAttribute = class ReciprocalAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ReciprocalAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ReciprocalAttribute(); + return $; + } +}; + +tosa.RsqrtAttribute = class RsqrtAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.RsqrtAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.RsqrtAttribute(); + return $; + } +}; + +tosa.SinAttribute = class SinAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.SinAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.SinAttribute(); + return $; + } +}; + +tosa.SelectAttribute = class SelectAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.SelectAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.SelectAttribute(); + return $; + } +}; + +tosa.EqualAttribute = class EqualAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.EqualAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.EqualAttribute(); + return $; + } +}; + +tosa.GreaterAttribute = class GreaterAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.GreaterAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.GreaterAttribute(); + return $; + } +}; + +tosa.GreaterEqualAttribute = class GreaterEqualAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.GreaterEqualAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.GreaterEqualAttribute(); + return $; + } +}; + +tosa.ReduceAllAttribute = class ReduceAllAttribute { + + static decode(reader, position) { + const $ = new tosa.ReduceAllAttribute(); + $.axis = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReduceAllAttribute(); + $.axis = reader.value(json.axis, 0); + return $; + } +}; + +tosa.ReduceAnyAttribute = class ReduceAnyAttribute { + + static decode(reader, position) { + const $ = new tosa.ReduceAnyAttribute(); + $.axis = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReduceAnyAttribute(); + $.axis = reader.value(json.axis, 0); + return $; + } +}; + +tosa.ReduceMaxAttribute = class ReduceMaxAttribute { + + static decode(reader, position) { + const $ = new tosa.ReduceMaxAttribute(); + $.axis = reader.int32_(position, 4, 0); + $.nan_mode = reader.uint32_(position, 6, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReduceMaxAttribute(); + $.axis = reader.value(json.axis, 0); + $.nan_mode = tosa.NanPropagationMode[json.nan_mode]; + return $; + } +}; + +tosa.ReduceMinAttribute = class ReduceMinAttribute { + + static decode(reader, position) { + const $ = new tosa.ReduceMinAttribute(); + $.axis = reader.int32_(position, 4, 0); + $.nan_mode = reader.uint32_(position, 6, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReduceMinAttribute(); + $.axis = reader.value(json.axis, 0); + $.nan_mode = tosa.NanPropagationMode[json.nan_mode]; + return $; + } +}; + +tosa.ReduceProductAttribute = class ReduceProductAttribute { + + static decode(reader, position) { + const $ = new tosa.ReduceProductAttribute(); + $.axis = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReduceProductAttribute(); + $.axis = reader.value(json.axis, 0); + return $; + } +}; + +tosa.ReduceSumAttribute = class ReduceSumAttribute { + + static decode(reader, position) { + const $ = new tosa.ReduceSumAttribute(); + $.axis = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReduceSumAttribute(); + $.axis = reader.value(json.axis, 0); + return $; + } +}; + +tosa.ConcatAttribute = class ConcatAttribute { + + static decode(reader, position) { + const $ = new tosa.ConcatAttribute(); + $.axis = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ConcatAttribute(); + $.axis = reader.value(json.axis, 0); + return $; + } +}; + +tosa.PadAttribute = class PadAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.PadAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.PadAttribute(); + return $; + } +}; + +tosa.ReshapeAttribute = class ReshapeAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ReshapeAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ReshapeAttribute(); + return $; + } +}; + +tosa.ReverseAttribute = class ReverseAttribute { + + static decode(reader, position) { + const $ = new tosa.ReverseAttribute(); + $.axis = reader.int32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ReverseAttribute(); + $.axis = reader.value(json.axis, 0); + return $; + } +}; + +tosa.SliceAttribute = class SliceAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.SliceAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.SliceAttribute(); + return $; + } +}; + +tosa.TileAttribute = class TileAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.TileAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.TileAttribute(); + return $; + } +}; + +tosa.TransposeAttribute = class TransposeAttribute { + + static decode(reader, position) { + const $ = new tosa.TransposeAttribute(); + $.perms = reader.array(position, 4, Int32Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TransposeAttribute(); + $.perms = reader.array(json.perms, Int32Array); + return $; + } +}; + +tosa.GatherAttribute = class GatherAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.GatherAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.GatherAttribute(); + return $; + } +}; + +tosa.ScatterAttribute = class ScatterAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ScatterAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ScatterAttribute(); + return $; + } +}; + +tosa.ResizeAttribute = class ResizeAttribute { + + static decode(reader, position) { + const $ = new tosa.ResizeAttribute(); + $.mode = reader.uint32_(position, 4, 0); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.ResizeAttribute(); + $.mode = tosa.ResizeMode[json.mode]; + return $; + } +}; + +tosa.CastAttribute = class CastAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.CastAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.CastAttribute(); + return $; + } +}; + +tosa.RescaleAttribute = class RescaleAttribute { + + static decode(reader, position) { + const $ = new tosa.RescaleAttribute(); + $.scale32 = reader.bool_(position, 4, false); + $.rounding_mode = reader.uint32_(position, 6, 0); + $.per_channel = reader.bool_(position, 8, false); + $.input_unsigned = reader.bool_(position, 10, false); + $.output_unsigned = reader.bool_(position, 12, false); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.RescaleAttribute(); + $.scale32 = reader.value(json.scale32, false); + $.rounding_mode = tosa.RoundingMode[json.rounding_mode]; + $.per_channel = reader.value(json.per_channel, false); + $.input_unsigned = reader.value(json.input_unsigned, false); + $.output_unsigned = reader.value(json.output_unsigned, false); + return $; + } +}; + +tosa.ConstAttribute = class ConstAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ConstAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ConstAttribute(); + return $; + } +}; + +tosa.IdentityAttribute = class IdentityAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.IdentityAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.IdentityAttribute(); + return $; + } +}; + +tosa.CustomAttribute = class CustomAttribute { + + static decode(reader, position) { + const $ = new tosa.CustomAttribute(); + $.operator_name = reader.string_(position, 4, null); + $.domain_name = reader.string_(position, 6, null); + $.implementation_attrs = reader.array(position, 8, Uint8Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.CustomAttribute(); + $.operator_name = reader.value(json.operator_name, null); + $.domain_name = reader.value(json.domain_name, null); + $.implementation_attrs = reader.array(json.implementation_attrs, Uint8Array); + return $; + } +}; + +tosa.CondIfAttribute = class CondIfAttribute { + + static decode(reader, position) { + const $ = new tosa.CondIfAttribute(); + $.then_graph = reader.string_(position, 4, null); + $.else_graph = reader.string_(position, 6, null); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.CondIfAttribute(); + $.then_graph = reader.value(json.then_graph, null); + $.else_graph = reader.value(json.else_graph, null); + return $; + } +}; + +tosa.WhileLoopAttribute = class WhileLoopAttribute { + + static decode(reader, position) { + const $ = new tosa.WhileLoopAttribute(); + $.cond_graph = reader.string_(position, 4, null); + $.body_graph = reader.string_(position, 6, null); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.WhileLoopAttribute(); + $.cond_graph = reader.value(json.cond_graph, null); + $.body_graph = reader.value(json.body_graph, null); + return $; + } +}; + +tosa.VariableAttribute = class VariableAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.VariableAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.VariableAttribute(); + return $; + } +}; + +tosa.VariableWriteAttribute = class VariableWriteAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.VariableWriteAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.VariableWriteAttribute(); + return $; + } +}; + +tosa.VariableReadAttribute = class VariableReadAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.VariableReadAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.VariableReadAttribute(); + return $; + } +}; + +tosa.ConstShapeAttribute = class ConstShapeAttribute { + + static decode(/* reader, position */) { + const $ = new tosa.ConstShapeAttribute(); + return $; + } + + static decodeText(/* reader, json */) { + const $ = new tosa.ConstShapeAttribute(); + return $; + } +}; + +tosa.Version = class Version { + + static decode(reader, position) { + const $ = new tosa.Version(); + $._major = reader.int32_(position, 4, -1); + $._minor = reader.int32_(position, 6, -1); + $._patch = reader.int32_(position, 8, -1); + $._draft = reader.bool_(position, 10, true); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.Version(); + $._major = reader.value(json._major, -1); + $._minor = reader.value(json._minor, -1); + $._patch = reader.value(json._patch, -1); + $._draft = reader.value(json._draft, true); + return $; + } +}; + +tosa.TosaTensor = class TosaTensor { + + static decode(reader, position) { + const $ = new tosa.TosaTensor(); + $.name = reader.string_(position, 4, null); + $.shape = reader.array(position, 6, Int32Array); + $.type = reader.uint32_(position, 8, 0); + $.data = reader.array(position, 10, Uint8Array); + $.variable = reader.bool_(position, 12, false); + $.is_unranked = reader.bool_(position, 14, false); + $.variable_name = reader.string_(position, 16, null); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaTensor(); + $.name = reader.value(json.name, null); + $.shape = reader.array(json.shape, Int32Array); + $.type = tosa.DType[json.type]; + $.data = reader.array(json.data, Uint8Array); + $.variable = reader.value(json.variable, false); + $.is_unranked = reader.value(json.is_unranked, false); + $.variable_name = reader.value(json.variable_name, null); + return $; + } +}; + +tosa.TosaShape = class TosaShape { + + static decode(reader, position) { + const $ = new tosa.TosaShape(); + $.name = reader.string_(position, 4, null); + $.rank = reader.uint32_(position, 6, 0); + $.data = reader.array(position, 8, Uint8Array); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaShape(); + $.name = reader.value(json.name, null); + $.rank = reader.value(json.rank, 0); + $.data = reader.array(json.data, Uint8Array); + return $; + } +}; + +tosa.OpLocation = class OpLocation { + + static decode(reader, position) { + const $ = new tosa.OpLocation(); + $.text = reader.string_(position, 4, null); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.OpLocation(); + $.text = reader.value(json.text, null); + return $; + } +}; + +tosa.TosaOperator = class TosaOperator { + + static decode(reader, position) { + const $ = new tosa.TosaOperator(); + $.op = reader.uint32_(position, 4, 0); + $.attribute = reader.union(position, 6, tosa.Attribute); + $.inputs = reader.strings_(position, 10); + $.outputs = reader.strings_(position, 12); + $.location = reader.table(position, 14, tosa.OpLocation); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaOperator(); + $.op = tosa.Op[json.op]; + $.attribute = tosa.Attribute.decodeText(reader, json.attribute, json.attribute_type); + $.inputs = reader.array(json.inputs); + $.outputs = reader.array(json.outputs); + $.location = reader.object(json.location, tosa.OpLocation); + return $; + } +}; + +tosa.TosaBasicBlock = class TosaBasicBlock { + + static decode(reader, position) { + const $ = new tosa.TosaBasicBlock(); + $.name = reader.string_(position, 4, null); + $.operators = reader.tables(position, 6, tosa.TosaOperator); + $.tensors = reader.tables(position, 8, tosa.TosaTensor); + $.inputs = reader.strings_(position, 10); + $.outputs = reader.strings_(position, 12); + $.shapes = reader.tables(position, 14, tosa.TosaShape); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaBasicBlock(); + $.name = reader.value(json.name, null); + $.operators = reader.objects(json.operators, tosa.TosaOperator); + $.tensors = reader.objects(json.tensors, tosa.TosaTensor); + $.inputs = reader.array(json.inputs); + $.outputs = reader.array(json.outputs); + $.shapes = reader.objects(json.shapes, tosa.TosaShape); + return $; + } +}; + +tosa.TosaRegion = class TosaRegion { + + static decode(reader, position) { + const $ = new tosa.TosaRegion(); + $.name = reader.string_(position, 4, null); + $.blocks = reader.tables(position, 6, tosa.TosaBasicBlock); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaRegion(); + $.name = reader.value(json.name, null); + $.blocks = reader.objects(json.blocks, tosa.TosaBasicBlock); + return $; + } +}; + +tosa.TosaGraph = class TosaGraph { + + static identifier(reader) { + return reader.identifier === 'TOSA'; + } + + static create(reader) { + return tosa.TosaGraph.decode(reader, reader.root); + } + + static createText(reader) { + return tosa.TosaGraph.decodeText(reader, reader.root); + } + + static decode(reader, position) { + const $ = new tosa.TosaGraph(); + $.version = reader.table(position, 4, tosa.Version); + $.regions = reader.tables(position, 6, tosa.TosaRegion); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaGraph(); + $.version = reader.object(json.version, tosa.Version); + $.regions = reader.objects(json.regions, tosa.TosaRegion); + return $; + } +}; diff --git a/source/tosa-version.js b/source/tosa-version.js new file mode 100644 index 0000000000..316448a8ee --- /dev/null +++ b/source/tosa-version.js @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates + +export const tosa = {}; + +tosa.Version = class Version { + + static decode(reader, position) { + const $ = new tosa.Version(); + $._major = reader.int32_(position, 4, -1); + $._minor = reader.int32_(position, 6, -1); + $._patch = reader.int32_(position, 8, -1); + $._draft = reader.bool_(position, 10, true); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.Version(); + $._major = reader.value(json._major, -1); + $._minor = reader.value(json._minor, -1); + $._patch = reader.value(json._patch, -1); + $._draft = reader.value(json._draft, true); + return $; + } +}; + +tosa.TosaGraph = class TosaGraph { + + static identifier(reader) { + return reader.identifier === 'TOSA'; + } + + static create(reader) { + return tosa.TosaGraph.decode(reader, reader.root); + } + + static createText(reader) { + return tosa.TosaGraph.decodeText(reader, reader.root); + } + + static decode(reader, position) { + const $ = new tosa.TosaGraph(); + $.version = reader.table(position, 4, tosa.Version); + return $; + } + + static decodeText(reader, json) { + const $ = new tosa.TosaGraph(); + $.version = reader.object(json.version, tosa.Version); + return $; + } +}; diff --git a/source/tosa.js b/source/tosa.js new file mode 100755 index 0000000000..ebe41966d4 --- /dev/null +++ b/source/tosa.js @@ -0,0 +1,310 @@ +// SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates + +/* jshint esversion: 6 */ +import * as version from './tosa-version.js'; + +const tosa = {}; + +tosa.ModelFactory = class { + + async match(context) { + const reader = await context.peek('flatbuffers.binary'); + if (reader && reader.identifier === 'TOSA') { + return context.set('tosa.flatbuffers', reader); + } + const obj = await context.peek('json'); + if (obj && obj.regions && obj.version) { + return context.set('tosa.flatbuffers.json', obj); + } + return null; + } + + async open(context) { + const identifier = context.identifier; + let model = null; + let file_version = null; + let schema_version = null; + const loadSchema = async (version) => { + file_version = [version._major, version._minor, version._patch].join('.'); + schema_version = [version._major, version._minor].join('.'); // Ignore patch version + const schema = await context.require(`./tosa-schema-v${schema_version}`); + return schema.tosa; + }; + try { + switch (context.type) { + case 'tosa.flatbuffers': { + const reader = context.value; + model = version.tosa.TosaGraph.create(reader); + tosa.schema = await loadSchema(model.version); + model = tosa.schema.TosaGraph.create(reader); + break; + } + case 'tosa.flatbuffers.json': { + const reader = await context.read('flatbuffers.text'); + model = version.tosa.TosaGraph.createText(reader); + tosa.schema = await loadSchema(model.version); + model = tosa.schema.TosaGraph.createText(reader); + break; + } + default: { + throw new tosa.Error(`Unsupported TOSA format '${context.type}'.`); + } + } + } catch (error) { + if (error && error.code && error.code === 'ERR_MODULE_NOT_FOUND') { + throw new tosa.Error(`'${identifier}' file version (${file_version}) does not match any available schema version.`); + } else { + const message = error && error.message ? error.message : error.toString(); + throw new tosa.Error(`${message.replace(/\.$/, '')} in '${identifier}'.`); + } + } + tosa.schema.InverseOp = new Map(Object.entries(tosa.schema.Op).map(([key, value]) => [value, key])); + tosa.version = schema_version; + const metadata = await context.metadata(`tosa-metadata-v${schema_version}.json`); + try { + return new tosa.Model(metadata, model, file_version); + } catch (error) { + const message = error && error.message ? error.message : error.toString(); + throw new tosa.Error(`${message.replace(/\.$/, '')} in '${identifier}'.`); + } + } +}; + +tosa.Model = class { + + constructor(metadata, model, version) { + this.format = `TOSA v${version}`; + this.modules = []; + for (const region of model.regions) { + for (const block of region.blocks) { + this.modules.push(new tosa.Graph(metadata, block)); + } + } + } +}; + +tosa.Graph = class { + + constructor(metadata, graph) { + this.name = graph.name; + this.nodes = []; + this.inputs = []; + this.outputs = []; + + // populate tensors + const tensors = Object.fromEntries(graph.tensors.map((tensor, index) => [tensor.name, new tosa.Value(index, tensor)])); + // populate shapes + const shapes = graph.shapes ? Object.fromEntries(graph.shapes.map((shape, index) => [shape.name, new tosa.Value(index, shape)])) : undefined; + // populate operator nodes + this.nodes = graph.operators.map((operator, index) => { + return new tosa.Node(metadata, operator, index.toString(), tensors, shapes); + }).filter((node) => !node.isConst); + + // populate inputs and outputs + this.inputs = graph.inputs.map((input) => new tosa.Parameter(input, [tensors[input]])); + this.outputs = graph.outputs.map((output) => new tosa.Parameter(output, [tensors[output]])); + } +}; + +tosa.Node = class { + + constructor(metadata, operator, identifier, tensors, shapes) { + const opType = tosa.schema.InverseOp.get(operator.op) || 'UNKNOWN'; + this.type = metadata.type(opType); + this.identifier = identifier; + this.outputs = []; + this.inputs = []; + this.attributes = []; + + if (operator) { + const outputs = Array.from(operator.outputs || new Int32Array(0)); + for (let i = 0; i < outputs.length; i++) { + let name = `output-${i}`; + let value = tensors[outputs[i]]; + if (this.type && this.type.outputs && i < this.type.outputs.length) { + const id = outputs[i]; + const output = this.type.outputs[i]; + name = output.name; + if (shapes && output.type === "shape_t" && shapes[id]) { + value = shapes[id]; + } + } + this.outputs.push(new tosa.Parameter(name, [value])); + } + + const inputs = Array.from(operator.inputs || new Int32Array(0)); + for (let i = 0; i < inputs.length; i++) { + let name = `input-${i}`; + let value = tensors[inputs[i]]; + if (this.type && this.type.inputs && i < this.type.inputs.length) { + const id = inputs[i]; + const input = this.type.inputs[i]; + name = input.name; + if (shapes && input.type === "shape_t" && shapes[id]) { + value = shapes[id]; + } + } + this.inputs.push(new tosa.Parameter(name, [value])); + } + + const attributes = operator.attribute; + if (attributes) { + for (const [name, value] of Object.entries(attributes)) { + const schema = metadata.attribute(opType, name); + const type = schema ? schema.type : '?'; + this.attributes.push(new tosa.Attribute(name, type, this.getTypedValue(value, type))); + } + } + } + } + + get isConst() { + return this.type.name.startsWith('CONST'); + } + + getTypedValue(value, type) { + const values = typeof value === 'object' ? Object.values(value) : value; + if (Array.isArray(values) && values.length > 1) { + return `[${values.join(", ")}]`; + } + // Translate type to enum + const tr = new Map([ + ['var_t', 'DType'], + ['acc_type_t', 'DType'], + ['resize_mode_t', 'ResizeMode'], + ['nan_propagation_mode_t', 'NanPropagationMode'], + ['rounding_mode_t', 'RoundingMode'] + ]); + return tosa.Utility.enum(tr.has(type) ? tr.get(type) : type, values); + } +}; + +tosa.Attribute = class { + + constructor(name, type, value) { + this.name = name; + this.value = value; + this.type = type; + } +}; + +tosa.Parameter = class { + + constructor(name, args) { + this.name = name; + this.value = args; + } +}; + +tosa.Value = class { + + constructor(index, arg) { + this.name = arg.name; + this.identifier = index.toString(); + if (Object.getPrototypeOf(arg).constructor.name === 'TosaShape') { + this.initializer = new tosa.ConstShape(arg); + this.type = this.initializer.type; + } else { + if (arg.data && arg.data.length || arg.variable) { + this.initializer = new tosa.ConstTensor(arg); + } + this.type = this.initializer ? this.initializer.type : new tosa.TensorType(arg); + this.visible = arg.variable; + } + } +}; + +tosa.ConstShape = class { + + constructor(shape) { + this.name = shape.name; + this.type = new tosa.TensorType({ 'type': tosa.schema.DType.SHAPE, 'shape': [shape.rank] }); + this.values = shape.data; + } +}; + +tosa.ConstTensor = class { + + constructor(tensor) { + this.name = tensor.name; + this.type = new tosa.TensorType(tensor); + this.values = tensor.data; + this.category = tensor.variable ? 'Variable' : null; + } +}; + +tosa.TensorType = class { + + constructor(tensor) { + this.dataType = tosa.Utility.dataType(tensor.type); + this.shape = new tosa.TensorShape(tensor.shape); + } + + toString() { + return this.dataType + this.shape.toString(); + } +}; + +tosa.TensorShape = class { + + constructor(dimensions) { + this.dimensions = Array.from(dimensions); + } + + toString() { + return `[${this.dimensions.map((dimension) => dimension.toString()).join(',')}]`; + } +}; + +tosa.Utility = class { + + static dataType(type) { + tosa.Utility._tensorTypes = tosa.Utility._tensorTypes || new Map(); + const tensorTypes = tosa.Utility._tensorTypes; + if (!tensorTypes.has(tosa.version)) { + const tr = new Map([ + ['fp', 'float'], + ['bf', 'bfloat'], + ['shape', 'int64'], + ['8e4m3', '8e4m3fn'], + ['bool', 'boolean'] + ]); + const re = new RegExp(Array.from(tr.keys()).join('|'), 'g'); + const map = new Map(Object.entries(tosa.schema.DType).map(([key, value]) => [value, key.toLowerCase().replace(re, (k) => tr.get(k))])); + tensorTypes.set(tosa.version, map); + } + const tt = tensorTypes.get(tosa.version); + return tt.has(type) ? tt.get(type) : '?'; + } + + static enum(name, value) { + const type = name && tosa.schema ? tosa.schema[name] : undefined; + if (type) { + tosa.Utility._enums = tosa.Utility._enums || new Map(); + let enums = tosa.Utility._enums; + if (!enums.has(tosa.version)) { + enums.set(tosa.version, new Map()); + } + enums = enums.get(tosa.version); + if (!enums.has(name)) { + const entries = new Map(Object.entries(type).map(([key, value]) => [value, key])); + enums.set(name, entries); + } + const map = enums.get(name); + if (map.has(value)) { + return map.get(value); + } + } + return value; + } +}; + +tosa.Error = class extends Error { + + constructor(message) { + super(message); + this.name = 'Error loading TOSA model.'; + } +}; + +export const ModelFactory = tosa.ModelFactory; diff --git a/source/view.js b/source/view.js index c6c15e480d..2c16b9515c 100644 --- a/source/view.js +++ b/source/view.js @@ -1,3 +1,4 @@ +// SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates import * as base from './base.js'; import * as grapher from './grapher.js'; @@ -3522,6 +3523,7 @@ view.TensorView = class extends view.Expander { case 'float8e4m3fn': data_type = 'float16'; break; case 'float8e4m3fnuz': data_type = 'float16'; break; case 'int4': data_type = 'int8'; break; + case 'int48': data_type = 'int64'; break; default: data_type = tensor.type.dataType; break; } const python = await import('./python.js'); @@ -6308,6 +6310,7 @@ view.ModelFactoryService = class { this.register('./catboost', ['.cbm']); this.register('./weka', ['.model']); this.register('./qnn', ['.json', '.bin', '.serialized', '.dlc']); + this.register('./tosa', ['.tosa', '.json']); this.register('./kann', ['.kann', '.bin', '.kgraph'], [], [/^....KaNN/]); this.register('./xgboost', ['.xgb', '.xgboost', '.json', '.model', '.bin', '.txt'], [], [/^{L\x00\x00/, /^binf/, /^bs64/, /^\s*booster\[0\]:/]); this.register('./transformers', ['.json']); @@ -6608,6 +6611,7 @@ view.ModelFactoryService = class { { name: 'MindSpore Lite model data', identifier: 'MSL1' }, { name: 'MindSpore Lite model data', identifier: 'MSL2' }, { name: 'MindSpore Lite model data', identifier: 'MSL3' }, + { name: 'TOSA model data', identifier: 'TOSA' }, { name: 'NVDA model data', identifier: 'NVDA' }, { name: 'BSTM model data', identifier: 'BSTM' }, { name: 'onnu model data', identifier: 'onnu' }, diff --git a/tools/tosa b/tools/tosa new file mode 100755 index 0000000000..efbd0c1cde --- /dev/null +++ b/tools/tosa @@ -0,0 +1,62 @@ +#!/bin/bash +# SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates + +set -e +pushd $(cd $(dirname ${0})/..; pwd) > /dev/null + +bold() { + echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" +} + +clean() { + bold "tosa clean" + rm -rf ./third_party/tosa +} + +TOSA_VERSIONS=(v0.80 v1.0) + +sync() { + mkdir -p "./third_party/tosa" + for TOSA_VERSION in ${TOSA_VERSIONS[@]} + do + bold "tosa sync ${TOSA_VERSION}" + curl --silent --show-error --location "https://gitlab.arm.com/tosa/tosa-serialization/-/raw/${TOSA_VERSION}/schema/tosa.fbs" -o ./third_party/tosa/tosa_${TOSA_VERSION}.fbs + curl --silent --show-error --location "https://raw.githubusercontent.com/arm/tosa-specification/refs/heads/${TOSA_VERSION}/tosa.xml" -o ./third_party/tosa/tosa_${TOSA_VERSION}.xml + done +} + +install() { + echo "tosa install" +} + +schema() { + for TOSA_VERSION in ${TOSA_VERSIONS[@]} + do + bold "tosa schema ${TOSA_VERSION}" + [[ $(grep -U $'\x0D' ./source/tosa-schema-${TOSA_VERSION}.js) ]] && crlf=1 + node ./tools/flatc.js --text --root tosa --out ./source/tosa-schema-${TOSA_VERSION}.js ./third_party/tosa/tosa_${TOSA_VERSION}.fbs + if [[ -n ${crlf} ]]; then + unix2dos --newfile ./source/tosa-schema-${TOSA_VERSION}.js ./source/tosa-schema-${TOSA_VERSION}.js + fi + done +} + +metadata() { + for TOSA_VERSION in ${TOSA_VERSIONS[@]} + do + bold "tosa metadata ${TOSA_VERSION}" + python3 ./tools/tosa_metadata.py --xml ./third_party/tosa/tosa_${TOSA_VERSION}.xml > ./source/tosa-metadata-${TOSA_VERSION}.json + done +} + + +while [ "$#" != 0 ]; do + command="$1" && shift + case "${command}" in + "clean") clean;; + "sync") sync;; + "install") install;; + "schema") schema;; + "metadata") metadata;; + esac +done diff --git a/tools/tosa_metadata.py b/tools/tosa_metadata.py new file mode 100644 index 0000000000..5b1f09a17c --- /dev/null +++ b/tools/tosa_metadata.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates + +"""Parsing of tosa.xml to tosa_metadata.json""" + +import argparse +import json +import re +import sys +from xml.etree import ElementTree as ET + +# Add argument parsing +parser = argparse.ArgumentParser(description="TOSA XML to metadata JSON") +parser.add_argument("--xml", help="XML file to parse", required=True) +parser.add_argument("outfile", nargs="?", type=argparse.FileType("w"), + default=sys.stdout) +args = parser.parse_args() + +# read in the XML file +root = ET.parse(args.xml) + +output = [] +# append all operators +operators = root.findall(".//operator") +for o in operators: + name = o.find("name").text + output.append({ + "name": name, + "category": "", + "attributes": [], + "inputs": [], + "outputs": []}) + # add category mapping + if "CONST" in name: + output[-1]["category"] = "constant" + elif "CUSTOM" in name: + output[-1]["category"] = "custom" + elif "POOL" in name: + output[-1]["category"] = "pool" + elif "RESCALE" in name: + output[-1]["category"] = "quantization" + elif any(c in name for c in ["SHAPE", "DIM"]): + output[-1]["category"] = "shape" + elif any(c in name for c in ["CONV", "FULLY_CONNECTED"]): + output[-1]["category"] = "layer" + elif name in ["TRANSPOSE", "GATHER", "SCATTER"]: + output[-1]["category"] = "transform" + elif name in ["CLAMP", "SIGMOID", "TANH", "ERF"]: + output[-1]["category"] = "activation" + elif name in ["CONCAT", "PAD", "REVERSE", "SLICE", "TILE", "IDENTITY"]: + output[-1]["category"] = "tensor" + else: + del output[-1]["category"] + arguments = o.findall(".//argument") + for arg in arguments: + category = arg.attrib["category"] + description = re.sub(r"[\s+]+", " ", arg.find("description").text).strip() + element_type = arg.attrib["tensor-element-type"] + obj = { + "name": arg.attrib["name"], + "type": arg.attrib["type"] if element_type == "-" else element_type, + "description": description + } + # sometimes the same argument can be + # an input or an attribute, depending on profile + # so make sure we match on both + if "attribute" in category: + output[-1]["attributes"].append(obj) + if "input" in category: + output[-1]["inputs"].append(obj) + elif "output" in category: + output[-1]["outputs"].append(obj) + +# write out the JSON file +json.dump(output, args.outfile, indent=2)