UnPad
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
√ |
|
x |
|
x |
Function Usage
Unpads a two-dimensional tensor (height x width) in the width direction. If the width of the tensor is not 32-byte aligned, this API should not be called for unpadding. This API is used in the following scenario: The width of the tensor is already 32-byte aligned. Take half as an example, for example, 16 x 16, and unpad it to 16 x 15.
Prototype
Due to the complex computation involved in the internal implementation of this API, additional temporary space is required to store intermediate variables generated during computation. The method of obtaining the temporary space size (BufferSize) is as follows: Obtain the required maximum and minimum temporary space sizes using the GetUnPadMaxMinTmpSize API provided in UnPad Tiling. The minimum space can ensure correct functionality, while the maximum space is used to improve performance.
The temporary space can be allocated through the API framework or passed by developers through the sharedTmpBuffer input parameter. Therefore, there are two types of function prototypes for the UnPad API.
- Pass the temporary space through the sharedTmpBuffer input parameter.
1 2
template <typename T> __aicore__ inline void UnPad(const LocalTensor<T>& dstTensor, const LocalTensor<T>& srcTensor, UnPadParams& unPadParams, LocalTensor<uint8_t>& sharedTmpBuffer, UnPadTiling& tiling)
This method requires you to allocate and manage the temporary buffer space on your own, and reuse the buffer after calling the API, so that the buffer is not repeatedly allocated or deallocated, improving the flexibility and buffer utilization.
- Allocate the temporary space through the API framework.
1 2
template <typename T> __aicore__ inline void UnPad(const LocalTensor<T>& dstTensor, const LocalTensor<T>& srcTensor, UnPadParams& unPadParams, UnPadTiling& tiling)
When using this method, you do not need to allocate the space, but must reserve the required temporary space.
Parameters
Parameter |
Description |
|---|---|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are int16_t, uint16_t, half, int32_t, uint32_t, and float. For the For the For the |
Parameter |
Input/Output |
Description |
||
|---|---|---|---|---|
dstTensor |
Output |
Destination operand, with a two-dimensional shape. For details about the definition of the LocalTensor data structure, see LocalTensor. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. |
||
srcTensor |
Input |
Source operand, with a two-dimensional shape. For details about the definition of the LocalTensor data structure, see LocalTensor. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. |
||
UnPadParams |
Input |
Detailed UnPad parameters of the UnPadParams data type. The specific parameters of the struct are as follows:
The definition of the UnPadParams struct is as follows:
|
||
sharedTmpBuffer |
Input |
Shared buffer, which is used to store temporary data generated during internal API computation. This enables you to manage the sharedTmpBuffer space and reuse the buffer after calling the API, so that the buffer is not repeatedly allocated and deallocated, improving the flexibility and buffer utilization. For details about how to obtain the size of the shared buffer, see UnPad Tiling. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. |
||
tiling |
Input |
Tiling information required for computation. For details about how to obtain the tiling information, see UnPad Tiling. |
Returns
None
Constraints
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
Examples
In this sample, the width of the tensor is already 32-byte aligned. Take half as an example: For instance, 16 x 16 becomes 16 x 15 after unpadding. The input data type is half.
For details about the complete example, see UnPad operator sample.
1 2 3 4 5 | // dstLocal: output tensor // srcLocal: input tensor // unPadParams: unpadding parameters AscendC::UnPadParams unPadParams{0, 1}; // Remove 0 columns from the left and 1 column from the right. Currently, unpadding on the left is not supported. AscendC::UnPad(srcOutLocal, dstLocal, unPadParams, tilingData.unpadTilingData); |