Gemm (Deprecated)
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
x |
x |
|
x |
|
x |
|
√ |
|
x |
|
√ |
Function Usage
This API has been deprecated and will be removed in later versions. Do not use this API.
Multiplies two tensors and outputs a result tensor. Multiply matrix A and matrix B to obtain matrix C, and output matrix C.
Prototype
- Functional API:
1 2
template <typename T, typename U, typename S> __aicore__ inline void Gemm(const LocalTensor<T>& dst, const LocalTensor<U>& src0, const LocalTensor<S>& src1, const uint32_t m, const uint32_t k, const uint32_t n, GemmTiling tilling, bool partialsum = true, int32_t initValue = 0)
- Tiling compute API:
1 2
template <typename T> __aicore__ inline GemmTiling GetGemmTiling(uint32_t m, uint32_t k, uint32_t n)
Parameters
Parameter |
Input/Output |
Description |
||
|---|---|---|---|---|
dst |
Output |
Destination operand. For the For the |
||
src0 |
Input |
Source operand. TPosition is set to A1. |
||
src1 |
Input |
Source operand. TPosition is set to B1. |
||
m |
Input |
Valid height of the left matrix Src0Local. The value range is [1, 4096]. Note: m does not need to be rounded up to a multiple of 16. |
||
k |
Input |
Valid width of the left matrix Src0Local and valid height of the right matrix Src1Local.
Note: k does not need to be rounded up to a multiple of 16. |
||
n |
Input |
Valid width of the right matrix Src1Local. The value range is [1, 4096]. Note: n does not need to be rounded up to a multiple of 16. |
||
tilling |
Input |
Tilling rule. The type is GemmTiling. The structure is defined as follows:
For details about the parameter description, see Table 3. |
||
partialsum |
Input |
When the dst parameter's TPosition is set to CO2, this parameter controls whether the computation results are moved out.
|
||
initValue |
Input |
Indicates whether dst needs to be initialized.
|
src0.dtype |
src1.dtype |
dst.dtype |
|---|---|---|
int8_t |
int8_t |
int32_t |
half |
half |
float |
half |
half |
half |
Parameter |
Input/Output |
Description |
||
|---|---|---|---|---|
blockSize |
uint32_t |
Number of elements stored in a dimension. The value is fixed at 16. |
||
loopMode |
LoopMode |
Traversal mode. The structure is defined as follows:
|
||
mNum |
uint32_t |
Equivalent data length of the M axis. The value range is [1, 4096]. |
||
nNum |
uint32_t |
Equivalent data length of the N axis. The value range is [1, 4096]. |
||
kNum |
uint32_t |
Equivalent data length of the K axis.
|
||
roundM |
uint32_t |
Equivalent data length of the M axis. The value is rounded up to an integer multiple of blockSize. The value range is [1, 4096]. |
||
roundN |
uint32_t |
Equivalent data length of the N axis. The value is rounded up to an integer multiple of blockSize. The value range is [1, 4096]. |
||
roundK |
uint32_t |
Equivalent data length of the K axis. The value is rounded up to a multiple of c0Size.
|
||
c0Size |
uint32_t |
Length of a block. The value can be 16 or 32. |
||
dtypeSize |
uint32_t |
Length of the input data, in bytes. The value range is [1, 2]. |
||
mBlockNum |
uint32_t |
Number of blocks on the M axis. mBlockNum = mNum/blockSize |
||
nBlockNum |
uint32_t |
Number of blocks on the N axis. nBlockNum = nNum/blockSize |
||
kBlockNum |
uint32_t |
Number of blocks on the K axis. kBlockNum = kNum/blockSize |
||
mIterNum |
uint32_t |
Number of traversed dimensions. The value range is [1, 4096]. |
||
nIterNum |
uint32_t |
Number of traversed dimensions. The value range is [1, 4096]. |
||
kIterNum |
uint32_t |
Number of traversed dimensions. The value range is [1, 4096]. |
||
mTileBlock |
uint32_t |
Number of split blocks on the M axis. The value range is [1, 4096]. |
||
nTileBlock |
uint32_t |
Number of split blocks on the N axis. The value range is [1, 4096]. |
||
kTileBlock |
uint32_t |
Number of split blocks on the K axis. The value range is [1, 4096]. |
||
kTailBlock |
uint32_t |
Number of tail blocks on the K axis. The value range is [1, 4096]. |
||
mTailBlock |
uint32_t |
Number of tail blocks on the M axis. The value range is [1, 4096]. |
||
nTailBlock |
uint32_t |
Number of tail blocks on the N axis. The value range is [1, 4096]. |
||
kHasTail |
bool |
Indicates whether a tail block exists on the K axis. |
||
mHasTail |
bool |
Indicates whether a tail block exists on the M axis. |
||
nHasTail |
bool |
Indicates whether a tail block exists on the N axis. |
||
kHasTailEle |
bool |
Indicates whether the tail block element exists. |
||
kTailEle |
uint32_t |
Tail block element on the K axis. The value range is [1, 4096]. |
Restrictions
- m, k, and n do not need to be multiples of 16. However, due to hardware restrictions, the shapes of the operands dst, Src0Local, and Src1Local must meet the alignment requirements: the m and n dimensions must be rounded up to multiples of 16, while the k dimension must be rounded up to either 16 or 32 depending on the data type of the operands.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.