TFILLPAD

Tile Operation Diagram

TFILLPAD tile operation

Introduction

Copy a source tile into a destination tile and fill the remaining (padded) elements with a compile-time pad value selected by TileDataDst::PadVal (e.g., PadValue::Min/PadValue::Max).

This is commonly used to materialize deterministic values outside the runtime valid region so that subsequent ops can operate on a full static tile shape.

Math Interpretation

Let VR = src.GetValidRow() and VC = src.GetValidCol(). For each destination element (i, j):

\[ \mathrm{dst}_{i,j} = \begin{cases} \mathrm{src}_{i,j} & \text{if } i < VR \text{ and } j < VC \\ \mathrm{pad} & \text{otherwise} \end{cases} \]

pad is determined by TileDataDst::PadVal and the element type (e.g., +inf/-inf for floating types when available, otherwise std::numeric_limits<T>::max()/min()).

Assembly Syntax

Synchronous form (conceptual):

%dst = tfillpad %src : !pto.tile<...> -> !pto.tile<...>

AS Level 1 (SSA)

%dst = pto.tfillpad %src : !pto.tile<...> -> !pto.tile<...>

AS Level 2 (DPS)

pto.tfillpad ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)

C++ Intrinsic

Implemented in the backend headers pulled in by include/pto/common/pto_instr_impl.hpp:

template <typename TileData, PadValue PadVal = PadValue::Zero, typename... WaitEvents>
PTO_INST RecordEvent TFILLPAD(TileData &dst, TileData &src, WaitEvents &... events);

template <
    TFillPadMode mode = TFillPadMode::Normal,
    typename DstTileData,
    typename SrcTileData,
    typename... WaitEvents>
PTO_INST RecordEvent TFILLPAD(DstTileData &dst, SrcTileData &src, WaitEvents &... events);

For vector tiles, mode selects the operation variant:

  • TFillPadMode::Normal: destination and source static shapes must match.
  • TFillPadMode::InPlace: destination and source must alias the same storage.
  • TFillPadMode::Expand: destination may have a larger static shape than source.

TFILLPAD_INPLACE and TFILLPAD_EXPAND remain available as compatibility aliases.

Constraints

  • TileDataDst::PadVal != PadValue::Null (Vec-type overload).
  • sizeof(TileDataDst::DType) == sizeof(TileDataSrc::DType) and element size must be 1, 2, or 4 bytes.
  • TFILLPAD: TileDataDst::Rows/Cols must match TileDataSrc::Rows/Cols.
  • TFILLPAD_EXPAND: TileDataDst::Rows >= TileDataSrc::Rows and TileDataDst::Cols >= TileDataSrc::Cols.
  • TFILLPAD(TileData &dst, TileData &src) (Mat-type overload): when TileData::TileType is Mat, the layout must satisfy !TileData::isRowMajor && TileData::SLayout::RowMajor, and PadVal must be PadValue::Zero or PadValue::Null. This Mat overload and the first Vec overload (PadVal != PadValue::Null) are separate SFINAE overloads, so the two are not contradictory.

Examples

#include <pto/pto-inst.hpp>

using namespace pto;

void example1() {
  using SrcT = Tile<TileType::Vec, float, 16, 16>;
  using DstT = Tile<TileType::Vec, float, 16, 16, BLayout::RowMajor, 16, 16, SLayout::NoneBox, TileConfig::fractalABSize, PadValue::Min>;

  SrcT src;
  DstT dst;
  TFILLPAD(dst, src);
}

void example2() {
  using TileMatData = Tile<TileType::Mat, float, 16, 256, BLayout::ColMajor, 1, 224, SLayout::RowMajor, 512>;

  TileMatData matTile;
  TFILLPAD(matTile, matTile);
}

ASM Form Examples

Auto Mode

# Auto mode: compiler/runtime-managed placement and scheduling.
%dst = pto.tfillpad %src : !pto.tile<...> -> !pto.tile<...>

Manual Mode

# Manual mode: resources must be bound explicitly before issuing the instruction.
# Optional for tile operands:
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%dst = pto.tfillpad %src : !pto.tile<...> -> !pto.tile<...>

PTO Assembly Form

%dst = pto.tfillpad %src : !pto.tile<...> -> !pto.tile<...>
# AS Level 2 (DPS)
pto.tfillpad ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)