GetUBSizeInBytes

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Obtains the UB size, in bytes. Developers can calculate the number of cycles based on the UB size.

Prototype

__aicore__ inline constexpr uint32_t GetUBSizeInBytes()

Parameters

None

Returns

UB size, in bytes.

Restrictions

None

Example

This example shows how to calculate the value of tileNum based on the UB size obtained by calling GetUBSizeInBytes.

// Define the total length of data to be processed (number of elements).
uint32_t totalLength = 16384;

// GetUBSizeInBytes() / sizeof(half) -> Calculate the number of half elements that the UB can accommodate.
// Divide by 2 -> Reserve 50% of the UB space.
uint32_t tileLength = AscendC::GetUBSizeInBytes() / sizeof(half) / 2;
// Prevent the tile size from exceeding the actual data volume.
if (totalLength < tileLength) {
    tileLength = totalLength;
}
// Number of tiles to be iterated: 16384/63488 = 1
uint32_t tileNum = totalLength / tileLength;