/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup NNRt
* @{
*
* @brief Provides a unified interface for AI chip drivers to access OpenHarmony. * Neural Network Runtime (NNRt) is cross-chip inference computing runtime oriented to the AI field.
* It serves as a bridge between the upper-layer AI inference framework and the underlying acceleration chip to implement cross-chip inference computing of AI models.
* @since 3.2
* @version 1.0
*/
/**
* @file NodeAttrTypes.idl
*
* @brief Defines the parameters and functions of AI model operators.
*
* All structures in this file declare only operator attributes and do not contain the interfaces for executing operator functions.
* - 1. The operators in the file are in one-to-one correspondence with a {@link NodeType}. In model inference, {@link NodeType} is stored in nodeType of {@link Node}.
* - 2. Each operator has at least one input and one output. The input is the tensor received by the operator, and the output is the tensor obtained after the operator operation. The relationship between the input, operator, and output is determined by inputIndex and outIndex of the {@link Node} structure.
*
* @since 3.2
* @version 1.0
*/
/**
* @brief Defines the package path of the NNRt module.
*
* @since 3.2
* @version 1.0
*/
package ohos.hdi.nnrt.v1_0;
import ohos.hdi.nnrt.v1_0.NnrtTypes;
/**
* @brief Defines the operator of the activation type. All activation functions belong to this operator. The specific activation function type is determined by the parameters.
*
* The {@link NodeType} of this operator is NODE_TYPE_ACTIVATION.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * A tensor returned after the activation function is executed.
*
* @since 3.2
* @version 1.0
*/
struct Activation
{
/** Activation function type. */
enum ActivationType activationType;
/** Size factor, used for LeakyReLU and ELU activation functions. */
float alpha;
/** Minimum value, used for the HardTanh activation function. */
float minVal;
/** Maximum value, used for the HardTanh activation function. */
float maxVal;
/** Whether to use the approximation algorithm. It is used for the GRLU activation function. */
boolean approximate;
};
/**
* @brief Adds tensors.
*
* The {@link NodeType} of this operator is NODE_TYPE_ADD_FUSION.
*
* Inputs:
*
* * x, the first input tensor.
* * y, the second input tensor. The data type must be the same as that of the first tensor.
*
* * Outputs:
*
* * Sum of the elements of x and y. The data shape is the same as the one after broadcasting, and the data type is the one with higher precision of the two inputs.
* If activationType is configured, the specified activation function will be called before the output is returned.
*
* @since 3.2
* @version 1.0
*/
struct AddFusion
{
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Returns the first K indices or values of a cross-axis tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_ARGMAX_FUSION.
*
*
* Inputs:
*
* * x, a tensor of shape (N,*), where * indicates any number of additional dimensions.
*
* Outputs:
*
* * First K indices or values before the maximum input tensor on the axis.
*
* @since 3.2
* @version 1.0
*/
struct ArgMaxFusion
{
/** Target axis where the maximum indices or values are obtained. */
long axis;
/** First K maximum values on the axis. */
long topK;
/** Whether to keep the output dimensions the same as the input dimensions. */
boolean keepDims;
/** Return the index if the value is false. Return the value if the value is true. The default value is false. */
boolean outMaxValue;
};
/**
* @brief Applies a 2D average pooling on the input tensor. The int8 quantization input is supported.
*
* The {@link NodeType} of this operator is NODE_TYPE_AVGPOOL_FUSION.
*
* When padMode==PAD_MODE_PAD, padList must be greater than or equal to 0. In other cases, padding must be 0.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * Tensor after average pooling.
*
* @since 3.2
* @version 1.0
*/
struct AvgPoolFusion
{
/**
* Kernel size used to obtain the average value. It is an int array [kernel_height, kernel_weight] with length of 2.
* The first number indicates the kernel height, and the second number indicates the kernel width.
*/
long[] kernelSize;
/**
* Distance of kernel moving. The value is an int array [stride_height, stride_weight] with length of 2.
* The first number indicates the moving size in height, and the second number indicates the moving size in width.
*/
long[] strides;
/** x is padded with an int array [top, bottom, left, right] with length of 4, and the nearest neighbor values are used for padding. */
long[] pad;
/** Padding method */
enum PadMode padMode;
/** Numerical operation mode of the output tensor */
enum RoundMode roundMode;
/** Format of the data during calculation. For details, see {@link Format}. */
enum Format format;
/** Whether to do global pooling */
boolean global;
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Divides the batch dimension of a 4D tensor into small blocks by block_shape, and interleaves these blocks back into the spatial dimension.
*
* The {@link NodeType} of this operator is NODE_TYPE_BATCH_TO_SPACE_ND.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * Output tensor. Assume that the shape of x is (n,h,w,c) and the shape of output is (n',h',w',c'):
* \f$ n' = n / (block_shape[0] * block_shape[1])\f$
* \f$ h' = h * block_shape[0] - crops[0][0] - crops[0][1] \f$
* \f$ w' = w * block_shape[1] - crops[1][0] - crops[1][1] \f$
* \f$ c'= c \f$
*
* @since 3.2
* @version 1.0
*/
struct BatchToSpaceND
{
/** Block size, which is an array [height_block, weight_block] with length of 2. */
long[] blockShape;
/**
* Crop values for the spatial dimension.
* It is a 2D array [crop0_start, crop0_end], [crop1_start, crop1_end] with the shape of (2, 2).
*/
long[][] crops;
};
/**
* @brief Offsets the data in each dimension of the input tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_BIAS_ADD.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * bias, the bias tensor.
*
* Outputs:
*
* * Output tensor, which is the sum of the input tensor and the bias in each dimension.
*
* @since 3.2
* @version 1.0
*/
struct BiasAdd
{
};
/**
* @brief Converts the tensor data type.
*
* The {@link NodeType} of this operator is NODE_TYPE_CAST.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * type, the target type of the data.
*
* Outputs:
*
* * A tensor with the specified data type.
*
* @since 3.2
* @version 1.0
*/
struct Cast
{
};
/**
* @brief Connects tensors in the specified axis or connects input tensors along with the given axis.
*
* The {@link NodeType} of this operator is NODE_TYPE_CONCAT.
*
* Inputs:
*
* * Tensors with the same dimension.
*
* Outputs:
*
* * Result of the tensors connected.
*
* @since 3.2
* @version 1.0
*/
struct Concat
{
/** Axis specified. The value must be less than the number of dimensions of the input tensor. */
long axis;
};
/**
* @brief Calculates the 2D convolution on a 4D tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_CONV2D_FUSION.
*
* When padMode==PAD_MODE_PAD, padList must be greater than or equal to 0. In other cases, padding must be 0.
*
* Inputs:
*
* * x, a 4D tensor in NHWC format.
* * weight, a convolution weight in [outChannel, kernelHeight, kernelWidth, inChannel/group] format.
* The value of inChannel divided by groupmust be an integer.
* * bias: bias of the convolution. It is an array with length of [outChannel]. In the quantization scenario, bias does not need to be quantized.
* If quantization is required, the input data must be of the int32 type. The actual quantization parameter is determined by x and weight.
*
* Outputs:
*
* * Convolution output.
*
* @since 3.2
* @version 1.0
*/
struct Conv2DFusion
{
/** Size (height and width) of the convolution kernel */
long[] kernelSize;
/** Movement stride of the convolution kernel in height and weight. It is an int array [strideHeight, strideWidth] with length of 2. */
long[] stride;
/**
* Dilation size of the convolution kernel in height and weight. It is an int array [dilationHeight, dilationWidth].
* The value must be greater than or equal to 1 and cannot exceed the height and width of x.
*/
long[] dilation;
/** Padding mode. For details, see {@link PadMode}. */
enum PadMode padMode;
/** Padding around x in the height and width directions. It is an int array [top, bottom, left, right] with length of 4. */
long[] padList;
/**
* Splits x into groups by inChannel. The group value is of the int type.
* If group is 1, it is a conventional convolution.
* If group is inChannel, it is depthwiseConv2d. In this case, group==in_channel==out_channel.
* If group is greater than 1 and less than inChannel, it is group convolution. In this case, out_channel==group.
*/
long group;
/** Number of input channels. */
long inChannel;
/** Number of output channels. */
long outChannel;
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Calculates a 2D transposed convolution on a 4D tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_CONV2D_TRANSPOSE_FUSION.
*
* When padMode==PAD_MODE_PAD, padList must be greater than or equal to 0. In other cases, padding must be 0.
*
* Inputs:
*
* * x, a 4D tensor in NHWC format.
* * weight, a convolution weight in [outChannel, kernelHeight, kernelWidth, inChannel/group] format.
* The value of inChannel divided by groupmust be an integer.
* * bias: bias of the convolution. It is an array with length of [outChannel]. In the quantization scenario, bias does not need to be quantized.
* If quantization is required, the input data must be of the int32 type. The actual quantization parameter is determined by x and weight.
*
* Outputs:
*
* * N-dimensional tensor.
*
* @since 3.2
* @version 1.0
*/
struct Conv2dTransposeFusion
{
/** Size (height and width) of the convolution kernel */
long[] kernelSize;
/** Movement stride of the convolution kernel in height and weight. It is an int array [strideHeight, strideWidth] with length of 2. */
long[] stride;
/** Dilation size of the convolution kernel in height and weight. It is an int array [dilationHeight, dilationWidth] with length of 2.
* The value must be greater than or equal to 1 and cannot exceed the height and width of x.
*/
long[] dilation;
/** Padding mode. For details, see {@link PadMode}. */
enum PadMode padMode;
/** Padding around the input x in the height and width directions. It is an int array [top, bottom, left, right] with length of 4. */
long[] padList;
/**
* Splits x into groups by inChannel.
* If group is 1, it is a conventional convolution.
* If group is greater than 1 and less than or equal to inChannel, this is a group convolution.
*/
long group;
/** Number of input channels. */
long inChannel;
/** Number of output channels. */
long outChannel;
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
/**
* A list of integer array with two elements, specifying the paddings along the height and width of the output tensor.
*/
long[] outputPaddings;
};
/**
* @brief Divides the first tensor by the second tensor element-wise.
*
* The {@link NodeType} of this operator is NODE_TYPE_DIV_FUSION.
*
* Inputs:
*
* * x1, a tensor of the int or float type.
* * x2, a tensor of the int or float type.
*
* Outputs:
*
* * Quotient of the two inputs.
*
* @since 3.2
* @version 1.0
*/
struct DivFusion
{
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Performs an element-wise operation.
*
* The {@link NodeType} of this operator is NODE_TYPE_ELTWISE.
*
* Inputs:
*
* * x1, the first input tensor.
* * x2, the second input tensor.
*
* Outputs:
*
* * A tensor with the same data type and shape as x1.
*
* @since 3.2
* @version 1.0
*/
struct Eltwise
{
/** Element-wise operation type. For details, see {@link EltwiseMode}. */
enum EltwiseMode mode;
};
/**
* @brief Adds an additional dimension to a tensor at the given axis.
*
* The {@link NodeType} of this operator is NODE_TYPE_EXPAND_DIMS.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * axis, index of the dimension to add. The value is of the int32_t type and must be a constant in the range [-dim-1, dim].
*
* Outputs:
*
* * Operator with an additional dimension at the given axis.
*
* @since 3.2
* @version 1.0
*/
struct ExpandDims
{
};
/**
* @brief Creates a tensor of the specified dimensions and fills it with a scalar.
*
* The {@link NodeType} of this operator is NODE_TYPE_FILL.
*
* Inputs:
*
* * value, a scalar used to fill the tensor.
* * shape, which specifies the dimensions of the tensor to create.
* Outputs:
*
* * Tensor filled by the scaler.
*
* @since 3.2
* @version 1.0
*/
struct Fill
{
};
/**
* @brief Applies full connection for the input data.
*
* The {@link NodeType} of this operator is NODE_TYPE_FULL_CONNECTION.
*
* When useAxis is true, axis must be set. When useAxis is false, axis is 0.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * weight, a weight tensor for a full connection.
* * bias, a full-connection bias. In quantization scenarios, a quantized parameter is not required. If quantization is required, the data must be of the int32 type. The actual quantization parameter is determined by x and weight.
* *
* Outputs:
*
* * Normalized tensor.
*
* @since 3.2
* @version 1.0
*/
struct FullConnection
{
/** Whether to use the bias. */
boolean hasBias;
/** Whether to use the axis. */
boolean useAxis;
/** Axis specified for the full connection. The specified axis and its following axes are converted into a 1D tensor and then apply the full connection. */
long axis;
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Performs batch normalization for a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_FUSED_BATCH_NORM.
*
* Inputs:
*
* * x: a tensor of shape [N, ..., C], that is, the nth dimension is the number of channels.
* * scale, a 1D tensor of the scaling factor used to scale the first normalized tensor.
* * offset, a 1D tensor used to move to the first normalized tensor.
* * mean, a 1D tensor of the overall mean value. It is used only for inference. In case of training, this parameter must be left empty.
* * variance, a 1D tensor used for the overall variance. It is used only for inference. In case of training, this parameter must be left empty.
*
* Outputs:
*
* * Normalized tensor.
*
* @since 3.2
* @version 1.0
*/
struct FusedBatchNorm
{
/** A small value close to zero. It is used to ensure that the divisor is not 0. */
float epsilon;
};
/**
* @brief Returns the slice of the input tensor based on the specified index and axis.
*
* The {@link NodeType} of this operator is NODE_TYPE_GATHER.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * inputIndices, indices of elements of the original tensor. The value is an array of the int type and must be in the range [0, x.shape[axis]).
* * axis, the axis on which x is sliced. The value is an array with one element of the int32_t type.
*
* Outputs:
*
* * Sliced tensor.
*
* @since 3.2
* @version 1.0
*/
struct Gather
{
};
/**
* @brief Applies layer normalization for a tensor from the specified axis.
*
* The {@link NodeType} of this operator is NODE_TYPE_LAYER_NORM_FUSION.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * gamma, an m-dimensional tensor. The dimensions of gamma must be the same as the shape of the part of the input tensor to normalize.
* * beta, an m-dimensional tensor with the same shape as gamma.
*
* Outputs:
*
* * An n-dimensional tensor, with the same data type and shape as the input tensor.
*
* @since 3.2
* @version 1.0
*/
struct LayerNormFusion
{
/** Start axis of x to apply layer normalization. */
long beginNormAxis;
/** A value added to the denominator for numerical stability. */
float epsilon;
/** Whether to perform an element-wise operation. */
boolean elementwiseAffine;
/** Start axis of the parameter input (gamma, beta) to apply layer normalization. The value must be in the range [-n, n). */
long beginParamsAxis;
};
/**
* @brief Calculates the result of x1 <= x2 element-wise.
*
* The {@link NodeType} of this operator is NODE_TYPE_LESS_EQUAL.
*
* Inputs:
*
* * x1, which can be a number, a Boolean value, or a tensor whose data type is number or Boolean.
* * x2, which can be a number or a Boolean value if x1 is a tensor; or a tensor with the data type of number or Boolean if x1 is not a tensor.
*
* Outputs:
*
* * A tensor with the data type of Boolean. When a quantization model is used, the quantization parameters of the output cannot be omitted. However, values of the quantization parameters do not affect the result.
*
* @since 3.2
* @version 1.0
*/
struct LessEqual
{
};
/**
* @brief Calculates the matrix product of x1 and x2.
*
* The {@link NodeType} of this operator is NODE_TYPE_MATMUL_FUSION.
*
* Inputs:
*
* * x1, an n-dimensional tensor, whose data type can be number or Boolean.
* * x2, an n-dimensional tensor, whose data type can be number or Boolean.
*
* Outputs:
*
* * Matrix product of the inputs. When type! When = DATA_TYPE_UNKNOWN, the data type of the output is determined by type. When type==DATA_TYPE_UNKNOWN,
* the data type of the output depends on the data type converted during the calculation of x1 and x2.
*
* @since 3.2
* @version 1.0
*/
struct MatMulFusion
{
/** Whether to transpose the x1 matrix. */
boolean transposeA;
/** Whether to transpose the x2 matrix. */
boolean transposeB;
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Calculates the maximum of x1 and x2 element-wise. The inputs of x1 and x2 comply with the implicit type conversion rules to make the data types are consistent.
*
* The inputs must be two tensors or one tensor and one scalar. When the input is two tensors, the data types cannot be Boolean at the same time, and their shapes
* can be broadcast to the same. When the inputs are one tensor and one scalar, the scalar must be a constant.
*
* The {@link NodeType} of this operator is NODE_TYPE_MAXIMUM.
*
* Inputs:
*
* * x1, an n-dimensional tensor, whose data type can be number or Boolean.
* * x2, an n-dimensional tensor, whose data type can be number or Boolean.
*
* Outputs:
*
* * Maximum value of the elements of the two tensors.
*
* @since 3.2
* @version 1.0
*/
struct Maximum
{
};
/**
* @brief Applies a 2D maximum pooling over an input tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_MAX_POOL_FUSION.
*
* When padMode==PAD_MODE_PAD, padList must be greater than or equal to 0. In other cases, padding must be 0.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * Maximum value of the elements of the two tensors.
*
* @since 3.2
* @version 1.0
*/
struct MaxPoolFusion
{
/** Size of the kernel used to take the maximum value. It is an int array [kernel_height, kernel_weight] with length of 2. */
long[] kernelSize;
/** Distance of kernel moving. It is an int array with two elements. */
long[] strides;
/** Array to pad. */
long[] pad;
/** Padding mode. For details, see {@link PadMode}. */
enum PadMode padMode;
/** Format of the tensor data. For details, see {@link Format}. */
enum Format format;
/** Whether to do global pooling */
boolean global;
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Multiplies the elements in the same position of x1 and x2 to obtain output.
*
* If the shapes of x1 and x2 are different, expand x1 and x2 to the same shape through broadcast and then perform the multiplication.
* The {@link NodeType} of this operator is NODE_TYPE_MUL_FUSION.
*
* Inputs:
*
* * x1, a tensor of the int or float type.
* * x2, a tensor of the int or float type.
*
* Outputs:
*
* * Product of each element of x1 and x2.
*
* @since 3.2
* @version 1.0
*/
struct MulFusion
{
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Generates a one-hot tensor based on the specified locations.
*
* The locations specified by indices are determined by on_value, and other locations are determined by off_value.
*
* The {@link NodeType} of this operator is NODE_TYPE_ONE_HOT.
*
* Inputs:
*
* * indices, an n-dimensional tensor. Each element in indices determines the location of on_value in each one-hot vector.
* * depth, an integer scalar that determines the depth of the one-hot vector. The value of depth must be greater than 0.
* * on_value, a scalar that specifies a valid value in the one-hot vector.
* * off_value, a scalar that specifies the values of other locations in the one-hot vector except the valid value.
*
* Outputs:
*
* * An (n+1)-dimensional tensor if indices is an n-dimensional tensor. The output shape is determined by indices and axis.
*
* @since 3.2
* @version 1.0
*/
struct OneHot
{
/**
* An integer scalar that specifies the dimension for inserting the one-hot. Assume that the shape of indices is [N, C], and the value of depth is D.
* When axis is 0, the shape of the output is [D, N, C].
* When axis is -1, the shape of the output is [N, C, D].
* When axis is -1, the shape of the output is [N, D, C].
*
*/
long axis;
};
/**
* @brief Pads the input tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_PAD_FUSION.
*
* When paddingMode==PADDING_MODE_CONSTANT, constantValue must be set. The default value of constantValue is 0.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * paddings, a 2D tensor that specifies the length to add in each dimension. The shape is [n, 2]. paddings[i][0] indicates the number of paddings to add before the input tensor in ith dimension.
* paddings[i][1] indicates the number of paddings to add after the input tensor in ith dimension.
*
* Outputs:
*
* * An n-dimensional tensor after padding, with the same dimensions and data type as x. The shape is determined by x and paddings.
* output.shape[i] = input.shape[i] + paddings[i][0]+paddings[i][1].
*
* @since 3.2
* @version 1.0
*/
struct PadFusion
{
/**
* A 2D tensor, specifying the length to add in each dimension. The shape is [n, 2]. paddings[i][0] indicates the number of paddings to add before the input x in the ith dimension.
* paddings[i][1] indicates the number of paddings to add after the input x in the ith dimension.
* The meaning of this parameter is the same as that of paddings input.
*/
long[][] paddings;
/**
* Padding mode.
* For details, see {@link PaddingMode}.
*/
enum PaddingMode paddingMode;
/**
* A constant with the same data type as x. It specifies the value to add in the pad operation.
* This parameter is valid only when paddingMode==PADDING_MODE_CONSTANT. The default value is 0.
*/
float constantValue;
};
/**
* @brief Calculates the y power of each element in x. The inputs must be two tensors or one tensor and one scalar.
*
* When the inputs are two tensors, their data types cannot be Boolean at the same time, and their shapes must be the same. When the inputs are one tensor and one scalar, the scalar must be a constant.
*
* The {@link NodeType} of this operator is NODE_TYPE_POW_FUSION.
*
* The x' = scale*x+shift operation is performed for each element of x, and then the y power of x' is calculated.
*
* Inputs:
*
* * x, a number, a Boolean value, or a tensor whose data type is number or Boolean.
* * y, a number, a Boolean value, or a tensor whose data type is number or Boolean.
*
* Outputs:
*
* * A tensor, whose shape is determined by the shape of x and y after broadcasting.
*
* @since 3.2
* @version 1.0
*/
struct PowFusion
{
/** Scale the value of x. */
float scale;
/** Increase or decrease the value of x after scaling. */
float shift;
};
/**
* @brief Applies the PReLU activation of x and weight.
*
* The {@link NodeType} of this operator is NODE_TYPE_PRELU_FUSION.
*
* Inputs:
*
* * x, an n-dimensional tensor. If n is greater than or equal to 2, x must be [BatchSize, ..., Channels]. The second dimension is the number of channels.
* * weight, a 1D tensor. The length of weight must be 1 or equal to the number of channels. If the length of weight is 1, all channels share the same weight.
* If the length of weight is equal to the number of channels, each channel exclusively has a weight. If n of x is less than 2, the weight length must be 1.
*
* Outputs:
*
* * PReLU activation value of x, with the same shape and data type as x.
*
* @since 3.2
* @version 1.0
*/
struct PReLUFusion
{
/**
* Whether to enable weight sharing for the parameter validity check.
* If the length of weight is 1, channelShared must be true. Otherwise, channelShared is false.
*/
boolean channelShared;
};
/**
* @brief Converts the data type.
*
* The {@link NodeType} of this operator is NODE_TYPE_QUANT_DTYPE_CAST.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * Tensor after the data type conversion.
*
* @since 3.2
* @version 1.0
*/
struct QuantDTypeCast
{
/** Data type of the input tensor. */
long srcT;
/** Data type of the output tensor. */
long dstT;
};
/**
* @brief Reduces the dimensions of a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_REDUCE_FUSION.
*
If mode is REDUCE_ALL, REDUCE_PROD, or REDUCE_MEAN and reduce_to_end is true, the output is the reduced value multiplied by coeff.
*
* Inputs:
*
* * x, an n-dimensional tensor, where n is less than 8.
* * axis, a 1D tensor that specifies the dimension to reduce. The value range of each element in axis is [–n, n).
*
* Outputs:
*
* * An m-dimensional tensor, with the same data type as x. If keepDims is false, m < n. If keepDims is true, m==n.
*
* @since 3.2
* @version 1.0
*/
struct ReduceFusion
{
/** Whether to keep the dimensions remain unchanged. */
boolean keepDims;
/** Algorithm used to reduce the tensor dimensions. For details, see {@link ReduceMode}. */
enum ReduceMode mode;
/**
* If this parameter is set to true, the first element is obtained from axis and set to i,
* and then axis will be changed to [i,i+1, ...,n-1,n].
* For example, if reduceToEnd is true, axis is [2,4], and the number of dimensions of x is 7, then axis will be [2,3,4,5,6].
*/
boolean reduceToEnd;
/** Coefficient. */
float coeff;
};
/**
* @brief Reshapes a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_RESHAPE.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * InputShape, a 1D tensor that specifies the shape of the output tensor. It must be a constant.
*
* Outputs:
*
* * A tensor of the specified shape. The data type is the same as that of x.
*
* @since 3.2
* @version 1.0
*/
struct Reshape
{
};
/**
* @brief Resizes a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_RESIZE.
*
* The parameter combination of this operator can implement the Resize function.
* For example, to implement bilinear interpolation on the four corners of an image that is precisely aligned, set:
* method = RESIZE_METHOD_LINEAR
* coordinateTransformMode = COORDINATE_TRANSFORM_MODE_ALIGN_CORNERS
*
* Inputs:
*
* * x, a 4D tensor in the [batchSize, height, width, channels] (NHWC) format.
*
* Outputs:
*
* * An n-dimensional tensor, with the same shape and data type as x.
*
* @since 3.2
* @version 1.0
*/
struct Resize
{
/** Method used for resizing. For details, see {@link ResizeMethod}. */
enum ResizeMethod method;
/** Height of the 4D tensor after resizing. */
long newHeight;
/** Width of the 4D tensor after resizing. */
long newWidth;
/** Whether to maintain the height/width ratio of x after resizing. */
boolean preserveAspectRatio;
/**
* Coordinate transformation method. For details, see {@link CoordinateTransformMode}.
*/
enum CoordinateTransformMode coordinateTransformMode;
/** Cubic coefficient, used when method is RESIZE_METHOD_CUBIC. */
float cubicCoeff;
/** When excludeOutside==1, the sampling weight that exceeds the boundary of x is set to 0, and other weights are normalized. */
long excludeOutside;
/** Value to interpolate, which is used only when x is cropped. The sampling weight that exceeds the boundary is set to extrapolationValue. */
float extrapolationValue;
/** Nearest neighbor interpolation algorithm, used when method is RESIZE_METHOD_NEAREST. For details, see {@link NearestMode}. */
enum NearestMode nearestMode;
};
/**
* @brief Calculates the reciprocal of the square root of a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_RSQRT.
*
* Inputs:
*
* *x, an n-dimensional tensor, where n is less than 8. Each element of the tensor cannot be less than 0.
*
* Outputs:
*
* * An n-dimensional tensor, with the same shape and data type as x.
*
* @since 3.2
* @version 1.0
*/
struct Rsqrt
{
};
/**
* @brief Scales a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_SCALE_FUSION.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * scale, the scaling tensor.
* * bias, the bias tensor.
*
* Outputs:
*
* * An n-dimensional tensor scaled, whose data type is the same as that of xx and shape is determined by axis.
*
* @since 3.2
* @version 1.0
*/
struct ScaleFusion
{
/** Dimensions to scale. */
long axis;
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Returns the share of the input tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_SHAPE.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * An integer array representing the dimensions of x.
*
* @since 3.2
* @version 1.0
*/
struct Shape
{
};
/**
* @brief Slices a tensor of the specified size.
*
* The {@link NodeType} of this operator is NODE_TYPE_SLICE_FUSION.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * begin, an array of integers greater than or equal to 0, specifying the start of the slice.
* * size, an array of integers greater than or equal to 0, specifying the length of the slice. Assume that a dimension is i and 1<=size[i]<=input.shape[i]-begin[i].
*
* Outputs:
*
* * An n-dimensional tensor obtained.
*
* @since 3.2
* @version 1.0
*/
struct SliceFusion
{
/** Dimensions on which the tensor is sliced. */
long[] axes;
};
/**
* @brief Applies the softmax operation on a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_SOFTMAX.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * Result of the softmax operation. It is an n-dimensional tensor with the same data type and shape as x.
*
* @since 3.2
* @version 1.0
*/
struct Softmax
{
/** Dimensions on which the softmax operation is performed. It is an integer in the range [-n, n). */
long[] axis;
};
/**
* @brief Splits a 4D tensor into multiple blocks in the spatial dimension and then concatenates these blocks in the batch dimension.
*
* The {@link NodeType} of this operator is NODE_TYPE_SPACE_TO_BATCH_ND.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* A 4D tensor with the same data type as x. The shape is determined by input, blockShape, and paddings. Assume that the input shape is [n,c,h,w], then:
* \f$ output.shape[0] = n * blockShape[0] * blockShape[1]\f$
* \f$ output.shape[1] = c \f$
* \f$ output.shape[2] = (h + paddings[0][0] + paddings[0][1]) / blockShape[0] \f$
* \f$ output.shape[3] = (w + paddings[1][0] + paddings[1][1]) / blockShape[1] \f$
* \f$ (h + paddings[0][0] + paddings[0][1]) must be an integer multiple of \f$ blockShape[0]\f$, and (w + paddings[1][0] + paddings[1][1]) \f$ must be an integer multiple of \f$ blockShape[1] \f$.
*
* @since 3.2
* @version 1.0
*/
struct SpaceToBatchND
{
/** Number of blocks. The value must be greater than 1. */
long[] blockShape;
/** Padding size for spatial dimensions. */
long[][] paddings;
};
/**
* @brief Splits a tensor into multiple tensors along the axis dimension. The number of tensors is specified by outputNum.
*
* The {@link NodeType} of this operator is NODE_TYPE_SPLIT.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * An array of n-dimensional tensors, with the same data type and dimensions. The data type of each tensor is the same as that of x.
*
* @since 3.2
* @version 1.0
*/
struct Split
{
/** Number of output sensors. */
long outputNum;
/**
* Size of each tensor to output.
* If size_splits is empty, x will be evenly split into tensors of the same size. In this case, x.shape[axis] must be an integer multiple of outputNum.
* If size_splits is not empty, the sum of all elements must be equal to x.shape[axis].
*/
long[] sizeSplits;
/** Target axis on which x is split. The data type is int. */
long axis;
};
/**
* @brief Calculates the square root of a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_SQRT.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * An n-dimensional tensor, with the same data type and shape as x.
*
* @since 3.2
* @version 1.0
*/
struct Sqrt
{
};
/**
* @brief Calculates the square of the difference between two tensors. The SquaredDifference operator supports subtraction between tensors.
*
* The {@link NodeType} of this operator is NODE_TYPE_SQUEEZE.
*
* Inputs:
*
* * x, a tensor representing the minuend, which can be a number or a Boolean value.
* * x, a tensor representing the subtrahend, which can be a number or a Boolean value.
*
* Outputs:
*
* * A tensor obtained. The shape of the output is determined by x and y. If x and y are of the same shape,
* the shape of the output is the same as that of x and y. If x and y are of different types, you need to perform the broadcast operation on x and y first.
* The precision of the output is the same as the input tensor with higher precision.
*
* @since 3.2
* @version 1.0
*/
struct SquaredDifference
{
};
/**
* @brief Removes the dimension with length of 1 from the specified axis. The int8 quantization input is supported.
*
* Assume that the shape of x is [2, 1, 1, 2, 2] and axis is [0,1], the shape of the output tensor must be [2, 1, 2, 2]. That is, the dimension with one element between the 0th and 1st dimensions is removed.
*
* The {@link NodeType} of this operator is NODE_TYPE_SQUARED_DIFFERENCE.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* *Tensor obtained.
*
* @since 3.2
* @version 1.0
*/
struct Squeeze
{
/** Axis on which the dimension of length 1 is to be removed. The value can be an integer or an array. The value range of the integer is [-n, n). */
long[] axis;
};
/**
* @brief Stacks multiple tensors along the specified axis. If the number of dimensions of each tensor is n before stacking, the number of dimensions of the output tensor is n+1.
*
* The {@link NodeType} of this operator is NODE_TYPE_STACK.
*
* Inputs:
*
* * Multiple n-dimensional tensors, which are of the same data type and shape.
*
* Outputs:
*
* * An n+1D tensor along the specified axis, with the same data type and precision as the input tensors.
*
* @since 3.2
* @version 1.0
*/
struct Stack
{
/** An integer that specifies the dimension for tensor stacking. The value range is [-(n+1),(n+1)), which means a negative number is allowed. */
long axis;
};
/**
* @brief Slices a tensor at the specified intervals.
*
* The {@link NodeType} of this operator is NODE_TYPE_STRIDED_SLICE.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * begin, a 1D tensor that specifies the position from which the tensor is sliced. The length of begin is n. begin[i] specifies the start point to slice in the ith dimension.
* * end, a 1D tensor that specifies the end to which the tensor is sliced. The length of end is n. end[i] specifies the end point to slice in the ith dimension.
* * strides, a 1D tensor that specifies the intervals for slicing. The length of strides is n. strides[i] specifies the intervals at which the tensor is sliced in the ith dimension. Negative values are allowed.
*
* For the input tensor, the shapes of begin, end, and strides must be the same. The indices of begin and end start from 0. The elements of strides cannot be 0.
*
* Outputs:
*
* * A tensor, with the same data type as x. The number of dimensions of the output tensor is rank (x[0])+1.
*
* @since 3.2
* @version 1.0
*/
struct StridedSlice
{
/**
* Mask of begin.
* beginMask identifies different dimensions of x in binary code. For example, if bit i of beginMask is set to 1, the setting of begin in the ith dimension will be invalid, which means the start index of that dimension is 0. The default value is 0.
*/
long beginMask;
/**
* Mask of end. The parameter is similar to begin_mask.
* endMask identifies different dimensions of x in binary code. For example, if bit i of endMask is set to 1, the setting of end in the ith dimension will be invalid, which means the tensor will be sliced till the end in that dimension. The default value is 0.
*/
long endMask;
/**
* An integer used to mask begin and end.
* The tensor does not need to be sliced in the non-zero dimensions.
* ellipsisMask is represented in binary code. If bit i of ellipsisMask is 1, elements are sliced from the first element at strides[i] in the ith dimension until the tensor boundary.
*/
long ellipsisMask;
/**
* Used to add a dimension.
* newAxisMask identifies different dimensions of x in binary code. If bit i is 1, the settings of begin, end, and strides are invalid for all dimensions, and a dimension with size of 1 is added to bit i.
*/
long newAxisMask;
/**
* Used to shrink the specified dimension.
* shrinkAxisMask is represented in binary code. If the ith bit of the shrinkAxisMask is 1, all elements in the ith dimension will be discarded, and the length of the ith dimension is shrunk to 1.
*/
long shrinkAxisMask;
};
/**
* @brief Calculates the difference between two tensors.
*
* The {@link NodeType} of this operator is NODE_TYPE_SUB_FUSION.
*
* Inputs:
*
* * x, the minuend, which is a tensor of the int or float type.
* * y, the subtrahend, which is a tensor of the int or float type.
*
* Outputs:
*
* * Difference between the two tensors. The output shape is determined byx and y. If x and y are of the same shape, the output tensor has the same shape as x and y.
* If x and y are of different shapes, perform the broadcast operation on x or y first. The precision of the output is the same as the input tensor with higher precision.
*
* @since 3.2
* @version 1.0
*/
struct SubFusion
{
/** Activation function type. For details, see {@link ActivationType}. */
enum ActivationType activationType;
};
/**
* @brief Copies a tensor by the specified times.
*
* The {@link NodeType} of this operator is NODE_TYPE_TILE_FUSION.
*
* Inputs:
*
* * x, an n-dimensional tensor.
* * multiples, a 1D tensor that specifies the number of times that the input tensor is copied in each dimension. The length m is not less than the number of dimensions of x.
*
* Outputs:
*
* * An m-dimensional tensor, with the same data type as x. If the length of x is the same as that of multiples,
* the number of dimensions of the output tensor is the same as that of the x, that is, an n-dimensional tensor is output. If the length of multiples is greater than n, 1s are used to pad the dimensions of x.
* Then, x is copies the specified number of times in each dimension to obtain an m-dimensional tensor.
*
* @since 3.2
* @version 1.0
*/
struct TileFusion
{
/** A 1D tensor that specifies the number of times that data is copied in each dimension. The length m is not less than the number of dimensions of x. */
long[] dims;
};
/**
* @brief Obtains the first K maximum values along the axis and their indices.
*
* The {@link NodeType} of this operator is NODE_TYPE_TOPK_FUSION.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * output0, the first K maximum values in the axis dimension.
* * output1, indices of the first K maximum values.
*
* @since 3.2
* @version 1.0
*/
struct TopKFusion
{
/** The value true means to sort the elements in descending order; the value false means the opposite. */
boolean sorted;
/** Specified axis. */
long axis;
};
/**
* @brief Transposes a tensor.
*
* The {@link NodeType} of this operator is NODE_TYPE_TRANSPOSE.
*
* Inputs:
*
* * x, an n-dimensional tensor to transpose.
* * perm, a 1D tensor that specifies the permutation. Its length is the same as the number of dimensions of x.
*
* Outputs:
*
* * An n-dimensional tensor, which has the same data type and quantization parameters as x. The shape is determined by the shape of x and perm.
*
* @since 3.2
* @version 1.0
*/
struct Transpose
{
};
/**
* @brief Adds a dimension based on the value of axis. *
*
* The {@link NodeType} of this operator is NODE_TYPE_UNSQUEEZE.
*
* Inputs:
*
* * x, an n-dimensional tensor.
*
* Outputs:
*
* * Tensor output.
*
* @since 3.2
* @version 1.0
*/
struct Unsqueeze
{
/** Dimension to add. The value of axis can be an integer or an array of integers. The value range of the integer is [-n, n). */
long[] axis;
};
/** @} */