Unlock this feature

This feature isn’t part of your plan yet

Contact sales to get upgraded to the full DevStudio experience.

Unlock this feature

This feature isn't part of your plan yet.

Random Access of Data

Introduction

Quadric APIs provide two methods for data transfer(bi-directional) between L2 and LRM

  • Flow APIs

  • RAU (Random Access Unit) APIs

RAU APIs provide the ability to fetch data in any pattern by computing relevant addresses and fetching data only from those addresses. This feature is particularly useful in cases where we need to access data in a strided pattern. Unlike Flow APIs, which allow us to read/write a block of data from a particular starting address, RAU APIs enable us to fetch data only from relevant addresses, avoiding unnecessary data transfer and computation.

The following are some examples of applications where RAU APIs are useful:

  1. Down-sampling using bilinear-interpolation: In this application, RAU APIs can be used to efficiently access data in a strided pattern to perform bilinear interpolation.

  2. RGB interleaved to RGB planar conversion: In this application, RAU APIs can be used to efficiently access data in a strided pattern to perform RGB interleaved to RGB planar conversion.

RAU APIs

There are several variants of RAU apis.

Load APIs

oneTile APIs

The oneTile function reads data from L2 into LRM and reads only one tile at a time. This function has two variations, one for address-based access and the other for index-based access.

1. Address-based

The address-based function reads data from a tensor located at the given linearized address

oneTilefunction
File: /src/core/rau.hppLines 174–197

Fetches data from a tensor located at the given linearized index.

template <typename TensorType,
          std::int32_t outOfRangeConstant = 0,
          typename T = typename TensorType::UnderlyingType,
          std::enable_if_t<(ElementsPerPack<typename TensorType::elemType>::value >= 2), int> = 0>
INLINE qVar_t<T> oneTile(const qVar_t<std::uint32_t>& addresses,
                         TensorType& tensor,
                         const qVar_t<bool>& qValidAddr = true)
NameTypeDefaultDescription
TensorTypetypenameType of the tensor to fetch data from (auto deduced).
outOfRangeConstantstd::int32_t0Value for elements which are outside the region of interest. Default to `0`.
Ttypenametypename TensorType::UnderlyingTypeElement type. Default is `TensorType::elemType`.
NameTypeDescription
addressesconst qVar_t<std::uint32_t>&Linearized addresses.
tensorTensorType&Tensor of the type `TensorType`.
qValidAddrconst qVar_t<bool>&The condition if the corresponding core is valid. Default is `true`.

INLINE qVar_t<T> — North port contaning the data.

2. Index-based

The index-based function reads data from a tensor located at the given index values.

oneTilefunction
File: /src/core/rau.hppLines 174–197

Fetches data from a tensor located at the given linearized index.

template <typename TensorType,
          std::int32_t outOfRangeConstant = 0,
          typename T = typename TensorType::UnderlyingType,
          std::enable_if_t<(ElementsPerPack<typename TensorType::elemType>::value >= 2), int> = 0>
INLINE qVar_t<T> oneTile(const qVar_t<std::uint32_t>& addresses,
                         TensorType& tensor,
                         const qVar_t<bool>& qValidAddr = true)
NameTypeDefaultDescription
TensorTypetypenameType of the tensor to fetch data from (auto deduced).
outOfRangeConstantstd::int32_t0Value for elements which are outside the region of interest. Default to `0`.
Ttypenametypename TensorType::UnderlyingTypeElement type. Default is `TensorType::elemType`.
NameTypeDescription
addressesconst qVar_t<std::uint32_t>&Linearized addresses.
tensorTensorType&Tensor of the type `TensorType`.
qValidAddrconst qVar_t<bool>&The condition if the corresponding core is valid. Default is `true`.

INLINE qVar_t<T> — North port contaning the data.

multi-TIle API

The multi-tile function, on the other hand, reads data from L2 into LRM and reads numTiles tiles at a time. This function is useful when users need to fetch multiple tiles of data in a single call. This function has two variations, one for qVar_t data type and the other for NDArray data type.

For qVar_t data type.

tilesfunction
File: /src/core/rau.hppLines 277–289

Read/write several tiles via RAU.

template <typename TensorType, typename T = typename TensorType::elemType>
INLINE void tiles(const qVar_t<std::uint32_t>* qAddresses,
                  qVar_t<T>* qData,
                  TensorType& tensor,
                  std::int32_t numTiles)
NameTypeDefaultDescription
TensorTypetypenameType of tensor.
Ttypenametypename TensorType::elemTypeTensor element type. Default is `TensorType::elemType`.
NameTypeDescription
qAddressesconst qVar_t<std::uint32_t>*Addresses.
qDataqVar_t<T>*Data.
tensorTensorType&Tensor.
numTilesstd::int32_tNumber of tiles.

INLINE void

For NDArray data type.

tilesfunction
File: /src/core/rau.hppLines 308–323

Load multiple tiles of data via RAU into an LRM array.

Accepts any container with operator[], Tbase and linearElementCount: container::NDArray (owned) or container::NDArrayView (caller-placed). To land the tiles part-way into a larger buffer, pass a view that starts there.

template <typename TensorType,
          typename AddrArray,
          typename DataArray,
          typename = decltype((void)AddrArray::linearElementCount, (void)DataArray::linearElementCount)>
INLINE void tiles(const AddrArray& qAddresses,
                  DataArray& qData,
                  TensorType& tensor,
                  std::int32_t numTiles = static_cast<std::int32_t>(AddrArray::linearElementCount))
NameTypeDefaultDescription
TensorTypetypenameType of tensor.
AddrArraytypenameContainer of `qVar_t<std::uint32_t>` addresses.
DataArraytypenameContainer of `qVar_t<T>` destination elements.
NameTypeDescription
qAddressesconst AddrArray&Addresses.
qDataDataArray&Data.
tensorTensorType&Tensor.
numTilesstd::int32_tNumber of tiles. Default is the address count; a larger count is capped at the smaller container, since the transfer walks `[0, numTiles)` of both.

INLINE void

Store APIs

oneTile APIs

The oneTile function is used to store data from LRM into L2, and it can store only one tile at a time. There are two variations of this function: one for address-based access and the other for index-based access.

1. Address-based

The address-based function stores data to a tensor located at the given linearized address in the LRM memory space.

oneTilefunction
File: /src/core/rau.hppLines 408–420

store 1 tile of data to a core-specific address

template <typename dataType, typename TensorType>
INLINE void oneTile(const qVar_t<std::uint32_t>& addresses,
                    const qVar_t<dataType>& data,
                    TensorType& tensor)
NameTypeDefaultDescription
dataTypetypenamedata type, deduced
TensorTypetypenametensor type, deduced
NameTypeDescription
addressesconst qVar_t<std::uint32_t>&the target addresses
dataconst qVar_t<dataType>&the data
tensorTensorType&the target tensor

INLINE void

2. Index-based

The index-based function stores data to a tensor located at the given index values.

oneTilefunction
File: /src/core/rau.hppLines 516–529

store 1 tile of data to a core-specific offset

template <typename dataType, typename TensorType>
INLINE void oneTile(const qVar_t<std::uint32_t>& bchIndx,
                    const qVar_t<std::uint32_t>& chIndx,
                    const qVar_t<std::uint32_t>& rowIndx,
                    const qVar_t<std::uint32_t>& colIndx,
                    const qVar_t<dataType>& qData,
                    TensorType& tensor)
NameTypeDefaultDescription
dataTypetypenamedata type, deduced
TensorTypetypenametensor type, deduced
NameTypeDescription
bchIndxconst qVar_t<std::uint32_t>&batch index
chIndxconst qVar_t<std::uint32_t>&channel index
rowIndxconst qVar_t<std::uint32_t>&row index
colIndxconst qVar_t<std::uint32_t>&column index
qDataconst qVar_t<dataType>&the data
tensorTensorType&the target tensor

INLINE void

multi-TIle API

The multi-tile function stores data from LRM into L2 and can store multiple tiles of data in a single call. This function is useful when there is a need to store multiple tiles of data in the LRM at once. This function has two variations, one for qVar_t data type and the other for NDArray data type.

For qVar_t data type.

tilesfunction
File: /src/core/rau.hppLines 457–466

Store multiple tiles of data via RAU (delegates to startTiles + qbar; see it for params).

template <typename TensorType,
          typename T = typename TensorType::elemType,
          std::int32_t elemSize = static_cast<std::int32_t>(sizeof(typename TensorType::elemType))>
INLINE void tiles(const qVar_t<std::uint32_t>* qAddresses,
                  qVar_t<T>* qData,
                  TensorType& tensor,
                  std::int32_t numTiles)
NameTypeDefaultDescription
TensorTypetypename
Ttypenametypename TensorType::elemType
elemSizestd::int32_tstatic_cast<std::int32_t>(sizeof(typename TensorType::elemType))
NameTypeDescription
qAddressesconst qVar_t<std::uint32_t>*
qDataqVar_t<T>*
tensorTensorType&
numTilesstd::int32_t

INLINE void

For NDArray data type.

tilesfunction
File: /src/core/rau.hppLines 485–500

Store multiple tiles of data via RAU from an LRM array.

Accepts any container with operator[], Tbase and linearElementCount: container::NDArray (owned) or container::NDArrayView (caller-placed). To store from part-way into a larger buffer, pass a view that starts there.

template <typename TensorType,
          typename AddrArray,
          typename DataArray,
          typename = decltype((void)AddrArray::linearElementCount, (void)DataArray::linearElementCount)>
INLINE void tiles(const AddrArray& qAddresses,
                  DataArray& qData,
                  TensorType& tensor,
                  std::int32_t numTiles = static_cast<std::int32_t>(AddrArray::linearElementCount))
NameTypeDefaultDescription
TensorTypetypenameType of the tensor to store into.
AddrArraytypenameContainer of `qVar_t<std::uint32_t>` addresses.
DataArraytypenameContainer of `qVar_t<T>` source elements.
NameTypeDescription
qAddressesconst AddrArray&Addresses.
qDataDataArray&Data.
tensorTensorType&Tensor.
numTilesstd::int32_tNumber of tiles. Default is the address count; a larger count is capped at the smaller container, since the transfer walks `[0, numTiles)` of both.

INLINE void

Other Utility functions to use with RAU load/store APIs

RAU Configuration

The config function is a pre-configuration function that sets up the PLS and RAU (Register Access Unit) addresses before calling the RAU load/store functions. This function is designed to simplify the setup process for RAU APIs by providing a single call to configure the PLS and set the RAU address.

To use this function, you need to pass an LRM tensor as input. This API can be used for both load and store operations. If you need to load or store data from/to another LRM tensor, you will need to call the config function again with the new LRM tensor as inp.

The config function must be called before using the RAU load/store functions. It configures the PLS and RAU addresses and sets up the necessary registers for proper operation.

configfunction
File: /src/core/rau.hppLines 45–50
template <typename TensorType>
INLINE void config(TensorType& inp)
NameTypeDefaultDescription
TensorTypetypename
NameTypeDescription
inpTensorType&

INLINE void

Examples

Randomly stores data in qInp at locations specified by qAddrs.

File: /tests/static_data_tests/rau_load_store_1tile_i16.cpp
  // Fetch data to qInp[i] using Rau LOAD
  rau::config<OcmInOutTensor>(ocmInPtr);
  for(std::int32_t i = 0; i < OcmInOutTensor::NUM_TILES; i++) {
    qInp[i] = rau::load::oneTile(qAddrs[i], ocmInPtr);
  }

  // Config rau for writing (Rau STORE) to output
  rau::config<OcmInOutTensor>(ocmOutPtr);
  for(std::int32_t i = 0; i < OcmInOutTensor::NUM_TILES; i++) {
    qVar_t<bool> cond = (((qAddrs[i] / sizeof(typename OcmInOutTensor::elemType)) % core_array::coreDim) != 0);
    if(cond) {
      rau::store::oneTile(qAddrs[i], qInp[i], ocmOutPtr);
    }
  }

Calculate linearized addresses

The computeAddr function takes in four parameters, bch, ch, row, and col, which represent the indexes of a tensor. The function then computes a serialized address based on these indexes and returns it as a qVar_t<std::uint32_t> type.

This function is typically used in conjunction with the RAU load/store APIs to load/store data from/to the L2 memory. In the example provided, the computeAddr function is used to compute the serialized address for both the read and write operations. The resulting address is then passed as a parameter to the RAU load/store APIs to perform the respective read/write operation.

computeAddrfunction
File: /src/core/rau.hppLines 53–60

returns a serialized address based in the tensor indexes

template <typename TensorType>
INLINE computeAddr(qVar_t<std::uint32_t> bch,
                   qVar_t<std::uint32_t> ch,
                   qVar_t<std::uint32_t> row,
                   qVar_t<std::uint32_t> col)
NameTypeDefaultDescription
TensorTypetypename
NameTypeDescription
bchqVar_t<std::uint32_t>
chqVar_t<std::uint32_t>
rowqVar_t<std::uint32_t>
colqVar_t<std::uint32_t>

INLINE

It is not recommended to use RAU load APIs inside an if/else block. Doing so may lead to unexpected results and computed results may not match the expected results. Instead, qValidAddr parameter can be used to select the cores that should be participating in the load operation.

However, RAU store APIs can be used inside an if/else block.

Sign in to your account

Don't have an account? 
By signing in, you are agreeing to our Terms of Use and Privacy Policy.
Quadric // One architecture. Every algorithm.

Develop.

Simulate.

Profile.

Collaborate.