当前位置: 首页 > news >正文

CANN/Ascend C浮点转BF16函数

asc_float2bfloat16

【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit

产品支持情况

产品是否支持
Atlas A3 训练系列产品/Atlas A3 推理系列产品
Atlas A2 训练系列产品/Atlas A2 推理系列产品

功能说明

将float类型数据转换为bfloat16_t类型,并支持多种舍入模式:

  • RINT舍入模式:四舍六入五成双舍入
  • ROUND舍入模式:四舍五入舍入
  • FLOOR舍入模式:向负无穷舍入
  • CEIL舍入模式:向正无穷舍入
  • TRUNC舍入模式:向零舍入

函数原型

  • 前n个数据连续计算

    // RINT舍入模式 __aicore__ inline void asc_float2bfloat16_rn(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) // ROUND舍入模式 __aicore__ inline void asc_float2bfloat16_rna(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) // FLOOR舍入模式 __aicore__ inline void asc_float2bfloat16_rd(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) // CEIL舍入模式 __aicore__ inline void asc_float2bfloat16_ru(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) // TRUNC舍入模式 __aicore__ inline void asc_float2bfloat16_rz(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count)
  • 高维切分计算

    // RINT舍入模式 __aicore__ inline void asc_float2bfloat16_rn(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint8_t repeat, uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride) // ROUND舍入模式 __aicore__ inline void asc_float2bfloat16_rna(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint8_t repeat, uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride) // FLOOR舍入模式 __aicore__ inline void asc_float2bfloat16_rd(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint8_t repeat, uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride) // CEIL舍入模式 __aicore__ inline void asc_float2bfloat16_ru(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint8_t repeat, uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride) // TRUNC舍入模式 __aicore__ inline void asc_float2bfloat16_rz(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint8_t repeat, uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride)
  • 同步计算

    // RINT舍入模式 __aicore__ inline void asc_float2bfloat16_rn_sync(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) //ROUND舍入模式 __aicore__ inline void asc_float2bfloat16_rna_sync(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) // FLOOR舍入模式 __aicore__ inline void asc_float2bfloat16_rd_sync(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) // CEIL舍入模式 __aicore__ inline void asc_float2bfloat16_ru_sync(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count) // TRUNC舍入模式 __aicore__ inline void asc_float2bfloat16_rz_sync(__ubuf__ bfloat16_t* dst, __ubuf__ float* src, uint32_t count)

参数说明

参数名输入/输出描述
dst输出目的操作数(矢量)的起始地址。
src输入源操作数(矢量)的起始地址。
count输入参与计算的元素个数。
repeat输入迭代次数。
dst_block_stride输入目的操作数单次迭代内不同DataBlock间地址步长。
src_block_stride输入源操作数单次迭代内不同DataBlock间地址步长。
dst_repeat_stride输入目的操作数相邻迭代间相同DataBlock的地址步长。
src_repeat_stride输入源操作数相邻迭代间相同DataBlock的地址步长。

返回值说明

流水类型

PIPE_V

约束说明

  • 操作数地址重叠约束请参考通用地址重叠约束。
  • dst、src的起始地址需要32字节对齐。

调用示例

constexpr uint32_t total_length = 256; __ubuf__ float src[total_length]; __ubuf__ bfloat16_t dst[total_length]; asc_float2bfloat16_rn(dst, src, total_length);

【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

http://www.jsqmd.com/news/1042790/

相关文章:

  • 1-1 Coursera吴恩达《神经网络与深度学习》第一周学习精要:从房价预测看AI核心
  • 从零开始:高效抖音无水印下载工具的完整实战指南
  • 西安高端奢侈品回收门店实测:7家正规商户10项合规测评,闲置奢品高效变现攻略 - 薛定谔的梨花猫
  • 天农凤中皇常见问题解答(2026专家版) - 速递信息
  • 2026万国手表回收避雷手册,助力上海表主避开回收行业各类常见猫腻 - 奢品小当家
  • 广州花都老板娘想找人教自己管账,找哪家财税公司靠谱?| 4招判断教学型财税公司 - 欢欢在创业
  • 村长团队GTA5用Blender+Sollumz 开发制作可驾驶+可飞行+轮子自动伸缩的载具改装教程
  • ComfyUI-MultiGPU终极指南:一键释放GPU显存,多GPU智能分配技术详解
  • FPGA_Webserver ARP协议实现:千兆速度下的地址解析协议硬件加速
  • S12Z微控制器内存映射与中断控制:嵌入式系统稳定性的核心机制
  • 重庆名表回收实测测评:7家主城门店横向对比,本地卖表怎么选不踩坑 - 沉迷学习28
  • 2026推荐:生石灰/耐火材料氧化钙(CaO)含量、活性度检测分析 - 公共场所卫生检测
  • 2026 广州奢侈品黄金回收门店分布核心洞察:耀辉全域布局与行业标杆实力 - 奢侈品回收
  • MMC2001 EIM配置详解:时序、总线与嵌入式系统稳定运行
  • 2026 宁波名表回收品牌榜,5 家横向测评 - 讯息早知道
  • 老板娘财税培训,标准化课程和按自己企业定制,哪种更值?| 4个维度客观对比 - 欢欢在创业
  • 重庆同城邮寄黄金回收,奢二网全程保价到货即刻核验 - 讯息早知道
  • BepInEx IL2CPP启动失败:3步终极解决方案与深度技术解析
  • 5分钟掌握JavaScript DXF生成:浏览器中创建CAD图纸的终极方案
  • ComfyUI TTP Toolset:专业级图像分块处理与超分辨率技术完整指南
  • Universal Android Debloater终极指南:无需Root彻底清理安卓预装软件
  • 厦门猎头公司前十名及联系电话 - 榜单推荐
  • 2026年6月上海知名的别墅设计/写字楼装修公司推荐上海洛根装饰设计工作室,办公别墅双赛道设计深耕多年 - 品牌鉴赏师
  • 盘点东莞靠谱黄金回收门店,紧跟实时金价,杜绝损耗隐形扣费 - 奢侈品交易观察员
  • 为什么开发Solidity必须用solc-select?5大理由告诉你
  • 第二周每周总结和冲刺
  • 内点法(IPM)的迭代与计算:从路径跟踪到Newton方程求解的复杂度拆解
  • 张家界黄金回收靠谱渠道推荐:六家精选店铺覆盖全市,高价变现不 - 清奢黄金上门回收
  • 2026西安奢侈品回收实测:正规渠道变现不踩坑 - 讯息早知道
  • 大连首饰回收门店怎么挑?权威排名干货分享 - 讯息早知道