GetUBSizeInBytes
产 品 支 持 情 况
| 产 品 | 是 否 支 持 |
|---|---|
Ascend 950PR/Ascend 950DT | √ |
Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品 | x |
Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品 | x |
Atlas 200I/500 A2 推 理 产 品 | x |
Atlas 推 理 系 列 产 品 AI Core | x |
Atlas 推 理 系 列 产 品 Vector Core | x |
Atlas 训 练 系 列 产 品 | x |
功 能 说 明
头 文 件 路 径 为:"basic_api/kernel_operator_sys_var_intf.h"。
获 取UB空 间 的 大 小,单 位 为Byte。开 发 者 根 据UB的 大 小 来 计 算 循 环 次 数 等 参 数 值。
函 数 原 型
C++
__aicore__ inline constexpr uint32_t GetUBSizeInBytes()
参 数 说 明
无
返 回 值 说 明
UB空 间 的 大 小,单 位 为Byte。
约 束 说 明
无
调 用 示 例
本 调 用 示 例 通 过GetUBSizeInBytes获 取 的UB空 间 大 小,来 计 算tileNum的 值。完 整 的 算 子 样 例 请 参 考:get_ub_size样 例。
C++
// totalLength为 待 处 理 的 总 数 据 长 度 (元 素 个 数)
this->totalLength = totalLength;
// GetUBSizeInBytes() / sizeof(half) -> 计 算UB能 容 纳 多 少 个half类 型 元 素
// 除2 -> 预 留50%的UB空 间
if (totalLength > AscendC::GetUBSizeInBytes() / sizeof(half) / 2) {
this->tileLength = AscendC::GetUBSizeInBytes() / sizeof(half) / 2;
} else { // 防 止 分 片 大 小 超 过 实 际 数 据 总 量
this->tileLength = this->totalLength;
}
// 需 要 迭 代 的 分 片 数 量
this->tileNum = this->totalLength / this->tileLength;