TMATMUL_BIAS
Instruction Diagram
Introduction
Performs matrix multiplication with bias addition.
Mathematical Semantics
Assume:
M = aMatrix.GetValidRow()K = aMatrix.GetValidCol()N = bMatrix.GetValidCol()
For 0 <= i < M and 0 <= j < N:
The bias broadcast behavior is implementation-defined.
Assembly Syntax
Synchronous form:
%acc = tmatmul.bias %a, %b, %bias : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>AS Level 1 (SSA)
%c = pto.tmatmul.bias %a, %b, %bias : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>AS Level 2 (DPS)
pto.tmatmul.bias ins(%a, %b, %bias : !pto.tile_buf<...>, !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%c : !pto.tile_buf<...>)C++ Built-in APIs
Declared in include/pto/common/pto_instr.hpp:
The public include header is
<pto/pto-inst.hpp>, and the internal declaration is located inpto/common/pto_instr.hpp.
template <typename TileRes, typename TileLeft, typename TileRight, typename TileBias, typename... WaitEvents>
PTO_INST RecordEvent TMATMUL_BIAS(TileRes &cMatrix, TileLeft &aMatrix, TileRight &bMatrix, TileBias &biasData, WaitEvents &... events);
template <AccPhase Phase, typename TileRes, typename TileLeft, typename TileRight, typename TileBias,
typename... WaitEvents>
PTO_INST RecordEvent TMATMUL_BIAS(TileRes &cMatrix, TileLeft &aMatrix, TileRight &bMatrix, TileBias &biasData, WaitEvents &... events);Constraints
- All constraints from
TMATMULapply to the(cMatrix, aMatrix, bMatrix)triple. - Bias constraints (Atlas A2/A3 training products/Atlas A2/A3 inference products):
TileBias::DTypemust matchTileRes::DType.TileBias::Loc == TileType::BiasandTileBias::Rows == 1.
- Bias constraints (Ascend 950PR/Ascend 950DT):
TileBias::DTypemust matchTileRes::DType.TileBias::Loc == TileType::Bias,TileBias::Rows == 1, andTileBias::isRowMajor.
Examples
Automatic
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using A = TileLeft<half, 16, 16>;
using B = TileRight<half, 16, 16>;
using Bias = Tile<TileType::Bias, float, 1, 16>;
using C = TileAcc<float, 16, 16>;
A a;
B b;
Bias bias;
C c;
TMATMUL_BIAS(c, a, b, bias);
}Manual
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using A = TileLeft<half, 16, 16>;
using B = TileRight<half, 16, 16>;
using Bias = Tile<TileType::Bias, float, 1, 16>;
using C = TileAcc<float, 16, 16>;
A a;
B b;
Bias bias;
C c;
TASSIGN(a, 0x1000);
TASSIGN(b, 0x2000);
TASSIGN(bias, 0x3000);
TASSIGN(c, 0x4000);
TMATMUL_BIAS(c, a, b, bias);
}ASM Examples
Automatic Mode
# Automatic mode: the compiler/runtime handles resource placement and scheduling.
%c = pto.tmatmul.bias %a, %b, %bias : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>Manual Mode
# Manual mode: explicitly bind resources first, then issue the instruction.
# Optional (when the instruction contains tile operands):
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%c = pto.tmatmul.bias %a, %b, %bias : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>PTO Assembly Form
%acc = tmatmul.bias %a, %b, %bias : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
# AS Level 2 (DPS)
pto.tmatmul.bias ins(%a, %b, %bias : !pto.tile_buf<...>, !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%c : !pto.tile_buf<...>)