cann/asc-devkit SIMD标量转换API

cann/asc-devkit SIMD标量转换API Castfloat转half/int32_t【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit产品支持情况Ascend 950PR/Ascend 950DT支持Atlas A3 训练系列产品/Atlas A3 推理系列产品支持Atlas A2 训练系列产品/Atlas A2 推理系列产品支持Atlas 200I/500 A2 推理产品不支持Atlas 推理系列产品AI Core支持Atlas 推理系列产品Vector Core不支持Atlas 训练系列产品不支持Kirin X90支持Kirin 9030支持功能说明头文件路径为basic_api/kernel_operator_scalar_intf.h。对标量的数据类型进行转换。在使用该接口之前用户需要先了解内置数据类型和精度转换。函数原型template typename T, typename U, RoundMode roundMode __aicore__ inline U Cast(T valueIn)参数说明表1模板参数说明参数名描述TvalueIn的数据类型。U转换后的数据类型。roundMode精度转换处理模式类型是RoundMode。RoundMode为枚举类型用以控制精度转换处理模式参考精度舍入模式可取值为:• CAST_NONE当转换过程存在精度损失时按CAST_RINT模式处理当不存在精度损失时不进行舍入• CAST_RINT向最近的偶数舍入• CAST_FLOOR向负无穷大方向舍入• CAST_CEIL向正无穷大方向舍入• CAST_ROUND四舍五入• CAST_TRUNC截断模式• CAST_ODD向最近的奇数舍入。表2参数说明参数名称输入/输出描述valueIn输入被转换数据类型的标量。数据类型支持的数据类型如下valueIn支持float。返回值支持half、int32_t。返回值说明转换后的U类型标量数据。约束说明支持的数据类型组合及对应支持的RoundMode如下valueIn返回值RoundModefloathalfCAST_ODDfloatint32_tCAST_ROUNDfloatint32_tCAST_CEILfloatint32_tCAST_FLOORfloatint32_tCAST_RINT调用示例float valueIn 3.14159f; half halfOut AscendC::Castfloat, half, AscendC::RoundMode::CAST_ODD(valueIn); // 返回3.142578 valueIn 1.5f; int32_t intRoundOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_ROUND(valueIn); // 使用CAST_ROUND模式四舍五入返回2 int32_t intCeilOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_CEIL(valueIn); // 使用CAST_CEIL模式向上取整返回2 int32_t intFloorOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_FLOOR(valueIn); // 使用CAST_FLOOR模式向下取整返回1 int32_t intRintOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_RINT(valueIn); // 使用CAST_RINT模式1.5向临近偶数舍入返回2 valueIn 2.5f; intRoundOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_ROUND(valueIn); // 使用CAST_ROUND模式四舍五入返回3 intCeilOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_CEIL(valueIn); // 使用CAST_CEIL模式向上取整返回3 intFloorOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_FLOOR(valueIn); // 使用CAST_FLOOR模式向下取整返回2 intRintOut AscendC::Castfloat, int32_t, AscendC::RoundMode::CAST_RINT(valueIn); // 使用CAST_RINT模式2.5向临近偶数舍入返回2【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考