Skip to content

GetUBSizeInBytes

产品支持情况

  • Ascend 950PR/Ascend 950DT:支持
  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
  • Atlas 200I/500 A2 推理产品:不支持
  • Atlas 推理系列产品AI Core:不支持
  • Atlas 推理系列产品Vector Core:不支持
  • Atlas 训练系列产品:不支持

功能说明

头文件路径为:"basic_api/kernel_operator_sys_var_intf.h"

获取UB空间的大小,单位为Byte。开发者根据UB的大小来计算循环次数等参数值。

函数原型

C++
__aicore__ inline constexpr uint32_t GetUBSizeInBytes()

参数说明

返回值说明

UB空间的大小。

Ascend 950PR/Ascend 950DT架构下,返回常量248KB,单位为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;

免责声明:本站内容由 asc-devkit 仓 master 分支自动编译生成,属于持续开发版本,可能存在缺陷,仅供预览与参考。如需稳定及商用资料,请查阅官方 昇腾社区