GetUBSizeInBytes
产品支持情况
产品 |
是否支持 |
|---|---|
Atlas 350 加速卡 |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
功能说明
获取UB空间的大小,单位为byte。开发者根据UB的大小来计算循环次数等参数值。
函数原型
__aicore__ inline constexpr uint32_t GetUBSizeInBytes()
参数说明
无
返回值说明
UB空间的大小,单位为byte。
约束说明
无
调用示例
本调用示例通过GetUBSizeInBytes获取的UB空间大小,来计算tileNum的值。
// 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;
父主题: 工具函数