CANN/asc-devkit:normf函数文档 normf【免费下载链接】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 训练系列产品不支持功能说明获取输入数据a中前n个元素的平方和a[0]^2 a[1]^2 ... a[n-1]^2的平方根。函数原型inline float normf(int n, float* a)参数说明表1参数说明参数名输入/输出描述n输入源操作数。输入数据a中连续计算的元素个数。a输入源操作数。Unified Buffer、Global Memory或栈空间的地址。返回值说明a[0]^2 a[1]^2 ... a[n-1]^2的平方根。若a[0]^2 a[1]^2 ... a[n-1]^2的平方根超出float最大范围返回值为inf。若a[0]、a[1] 、... 、a[n-1]任意一个或多个为±inf返回值为inf。若a[0]、a[1] 、... 、a[n-1]任意一个或多个为nan同时不是±inf返回值为nan。若n小于1返回a[0]的绝对值。约束说明输入数据a的长度必须大于等于参数n。若n过大接口性能无法保证。针对Ascend 950PR/Ascend 950DT本接口不支持Subnormal场景本接口内部实现使用到了除法运算符由于除法运算符不支持Subnormal场景当输入a的所有元素均为Subnormal数据时会导致接口最终结果为nan。需要包含的头文件使用该接口需要包含simt_api/math_functions.h头文件。#include simt_api/math_functions.h调用示例SIMT编程场景__global__ __launch_bounds__(256) void compute_normf(float *result, const int *n, float *vector_data, uint32_t count) { const uint32_t idx blockIdx.x * blockDim.x threadIdx.x; if (idx count) { return; } result[idx] normf(n[idx], vector_data idx * 4); }SIMD与SIMT混合编程场景__simt_vf__ __launch_bounds__(256) inline void compute_normf_vf(__gm__ float *result, __gm__ const int *n, __gm__ float *vector_data, uint32_t count) { const uint32_t idx blockIdx.x * blockDim.x threadIdx.x; if (idx count) { return; } result[idx] normf(n[idx], vector_data idx * 4); } __global__ __vector__ void run_normf(__gm__ float *result, __gm__ const int *n, __gm__ float *vector_data, uint32_t count) { asc_vf_callcompute_normf_vf(dim3(256), result, n, vector_data, count); }输入输出示例如下n1, 2, 3, 1 vector_data[[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7]] result: 1 3.605551 7.071068 4【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考