TransdataOperation

Description

Converts data formats. Converts the ACL_FORMAT_ND format to the ACL_FORMAT_FRACTAL_NZ format, or converts the ACL_FORMAT_FRACTAL_NZ format to the ACL_FORMAT_ND format.

  • Equivalents: ND and ACL_FORMAT_ND
  • Equivalents: NZ, ACL_FORMAT_FRACTAL_NZ, FRACTAL_NZ
  • ACL_FORMAT_ND
    • Description in aclFormat

      ACL_FORMAT_ND = 2: any format, applicable to operators that take singular inputs, such as Square and Tanh.

    • Detailed description

      Format is the physical layout of data and defines the dimensions for interpreting data. The ND format indicates 1D, 2D, 3D, and 4D. For example, in 4D format, N indicates the number of batches, H indicates the height of the feature map, W indicates the width of the feature map, and C indicates the channel of the feature map.

      In 2D format, data is stored in row-first order.

      Figure 1 Example of the ACL_FORMAT_ND format
  • ACL_FORMAT_FRACTAL_NZ
    • Description in aclFormat

      ACL_FORMAT_FRACTAL_NZ = 29: a format for internal use only.

    • Detailed description

      FRACTAL_NZ is a fractal format (NW1H1H0W0). The entire matrix is divided into (H1*W1) fractals, and each fractal has (H0*W0) elements for each N layers.

      Figure 2 Example of the ACL_FORMAT_FRACTAL_NZ format

      N=1, W1=4, H1=4.

Definition

struct TransdataParam {
     enum TransdataType : int { 
         UNDEFINED = 0, 
         FRACTAL_NZ_TO_ND, 
         ND_TO_FRACTAL_NZ 
     };
     TransdataType transdataType = UNDEFINED;
     SVector<int64_t> outCrops = {0, 0};
     uint8_t rsv[8] = {0};
};

Parameters

Member

Type

Default Value

Description

transdataType

TransdataType

UNDEFINED

Data format conversion type. Conversion between FRACTAL_NZ and ND is supported.

  • UNDEFINED: default format
  • FRACTAL_NZ_TO_ND: from FRACTAL_NZ to ND
  • ND_TO_FRACTAL_NZ: from ND to FRACTAL_NZ

outCrops

SVector<int64_t>

{0,0}

Last two dimensions of the shape in the original ND data format. This parameter is used only when FRACTAL_NZ is converted to ND

rsv[8]

uint8_t

{0}

Reserved

Input and Output of ND-to-NZ Conversion

Parameter

Dimension

Data Type

Format

Description

x

  1. [batch, m, n]
  2. [m, n]

float16/int8

ND

Input tensor

y

[batch, n1, m1m0, n0]

float16/int8

NZ

An output tensor of the same data type as the input tensor.

  • When the input tensor is of type float16, n0 and m0 are 16.
  • When the input tensor is of type int8, n0 is 32 and m0 is 16.
  • When the input tensor is 2-dimensional, the batch of the output tensor is 1.

Input and Output of NZ-to-ND Conversion

Parameter

Dimension

Data Type

Format

Description

x

[batch, n1, m1m0, n0]

float16

NZ

Input tensor

y

[batch, m, n]

float16

ND

An output tensor of the same data type as the input tensor

Functions

  • Converts a tensor in the ACL_FORMAT_ND data format to the ACL_FORMAT_FRACTAL_NZ data format.
    • The data type is float16.
      • 2D tensor input

        Input a tensor with shape [m,n], m0 = n0 = 16. The shape of the output tensor is [1,⌈n/n0⌉,⌈m/m0⌉∗m0,n0].

      • 3D tensor input

        Input a tensor with shape [batch,m,n], m0 = n0 = 16. The shape of the output tensor is [batch,⌈n/n0⌉,⌈m/m0⌉∗m0,n0].

    • The data type is int8.
      • 2D tensor input

        Input a tensor with shape [m,n], m0 = 16, n0 = 32. The shape of the output tensor is [1,⌈n/n0⌉,⌈m/m0⌉∗m0,n0].

      • 3D tensor input

        Input a tensor with shape [batch,m,n], m0 = 16, n0 = 32. The shape of the output tensor is [batch,⌈n/n0⌉,⌈m/m0⌉∗m0,n0].

  • Converts a tensor from the ACL_FORMAT_FRACTAL_NZ data format to the ACL_FORMAT_ND data format.
    • The data type is float16.

      Input a tensor with shape [b, n1, m1m0, n0], outCrops = {m, n}. The shape of the output tensor is [b, m, n]. The value range of m is (, ], and the value range of n is (, ]).

Restrictions

  • The NZ dimensions are expressed in the format of {b, n1, m1m0, n0}. The corresponding ND dimensions are {b, m, n}. b indicates the batch. If the batch size is 1, the dimension value is 1 and cannot be omitted. If there are multiple batches, this dimension is the result of merging all batch dimensions.

    m0 and n0 indicate the alignment bits. When float16 is used, n0 and m0 are both 16. When int8 is used, n0 is 32 and m0 is 16. m1m0 indicates that the original ND dimension m is aligned upward through the alignment bits. n1 indicates the quotient of dividing the original ND dimension n by n0 after the upward alignment through the alignment bits. For example, if the original ND dimensions are {8, 100, 30}, the corresponding NZ dimensions are {8, 2, 112, 16}.

  • The length of outCrops must be 2. The value must meet the following requirements:
    • If m0m1 falls within (k1 x 16, (k1 + 1) x 16] (where k1 is a positive integer), this interval is the value range of outCrops[0].
    • If n0 x n1 falls within (k2 x 16, (k2 + 1) x 16] (where k2 is a positive integer), this interval is the value range of outCrops[1].
  • In-place write is not supported.