asc-devkit Power 高阶 API 实战指南:按元素幂运算的实现原理、临时空间规划与调用示例
人工智能深度学习算子库CANNAscend【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址https://gitcode.com/cann/asc-devkit点击查看免费下载本文基于 CANN asc-devkit 仓库昇腾 AI 处理器专用算子开发语言 Ascend C 的开源实现中的 Power 接口文档整理而成系统讲解按元素幂运算Power(x, y) x^y的 3 类接口形态、临时空间的两申请方式、PowerAlgo算法配置以及配套的 host 侧空间规划接口GetPowerMaxMinTmpSize与GetPowerTmpBufferFactorSize。读完本文你将掌握 Power 接口在不同产品系列上的支持矩阵、全部函数原型与参数语义、临时空间大小的计算与推算方法并能直接复用仓库中的完整样例与测试用例进行算子开发验证。一、接口总览与产品支持情况Power 接口位于 SIMD 高级 APIadv_api的数学计算math_compute分类下相关文档为 Power_interface.md其下包含三份相互衔接的接口文档Power.md核函数Kernel侧的主接口实现按元素幂运算GetPowerMaxMinTmpSize.mdhost 侧获取预留/申请临时空间的最大、最小范围GetPowerTmpBufferFactorSize.mdhost 侧获取maxLiveNodeCount与extraBuf用于在固定空间下反推单次最大计算元素数量。1.1 产品支持矩阵Power 接口在不同产品系列上的支持情况来自 Power.md产品系列支持情况Ascend 950PR950DT 系列产品支持Atlas A3 系列产品支持Atlas A2 系列产品支持Atlas 200I/500 A2 推理产品不支持Atlas 推理系列产品 AI Core支持Atlas 推理系列产品 Vector Core不支持Atlas 训练系列产品不支持对应的 NPU 架构宏在 power.h 中体现为__NPU_ARCH__ 2201Atlas A2/A3 系列、2002、3510、9201、5102、5162、3003、3113Ascend 950 系列等其中 2201/2002 走power_common_impl.h实现3510 等架构走power_3510_impl.h实现。二、功能说明与数学原理Power 接口实现按元素做幂运算提供 3 类接口形态处理逻辑如下Power(dstTensor, src0Tensor, src1Tensor)两个源操作数均为 Tensor逐元素计算dst src0 ^ src1Power(dstTensor, src0Tensor, src1Scalar)指数为标量张量内全部元素使用同一个指数计算dst src0 ^ scalarPower(dstTensor, src0Scalar, src1Tensor)底数为标量张量内全部元素使用同一个底数计算dst scalar ^ src1。从源码实现看该接口的函数签名注释明确标注数学公式为Power(x, y) x ^ y见 power.h 文件头注释。在 power_float_impl.h 中可以看到浮点路径的真实计算链条InitDst依次执行Abs取底数绝对值→Ln取对数→Mul乘以指数→Exp取指数即浮点算法等价于exp(y * ln(|x|))随后通过DetermineSign、GenMaskForSign、GenMaskForOne、GenMaskForNan生成多级掩码并用Select/Vsel指令修正符号、处理底数为 ±1、NaN/Inf 等边界情形。整型路径则不同power_int_impl.h中的BulkProcessPowerI、FineProcessPowerI采用基于指数二进制展开的快速幂迭代每次迭代平方、按掩码乘入底数、右移指数位与文档中整型使用快速幂算法的描述一致。三、函数原型12 个重载的完整说明Power 接口在 power.h 中实现全部重载共用模板签名template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(...)3 类接口形态 × 2 种临时空间获取方式 × 是否带calCount共 12 个重载如下3.1 Power(dstTensor, src0Tensor, src1Tensor)——两个源操作数均为 Tensor通过sharedTmpBuffer入参传入临时空间源操作数全部/部分参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const LocalTensorT src1Tensor, const LocalTensoruint8_t sharedTmpBuffer, uint32_t calCount)源操作数全部参与计算不传calCount时源码内部自动以src0Tensor.GetSize()作为计算元素个数见 power.htemplate typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const LocalTensorT src1Tensor, const LocalTensoruint8_t sharedTmpBuffer)接口框架申请临时空间全部/部分参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const LocalTensorT src1Tensor, uint32_t calCount)全部参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const LocalTensorT src1Tensor)3.2 Power(dstTensor, src0Tensor, src1Scalar)——指数为标量通过sharedTmpBuffer入参传入临时空间全部/部分参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const T src1Scalar, const LocalTensoruint8_t sharedTmpBuffer, uint32_t calCount)全部参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const T src1Scalar, const LocalTensoruint8_t sharedTmpBuffer)接口框架申请临时空间全部/部分参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const T src1Scalar, uint32_t calCount)全部参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const LocalTensorT src0Tensor, const T src1Scalar)3.3 Power(dstTensor, src0Scalar, src1Tensor)——底数为标量通过sharedTmpBuffer入参传入临时空间全部/部分参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const T src0Scalar, const LocalTensorT src1Tensor, const LocalTensoruint8_t sharedTmpBuffer, uint32_t calCount)全部参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const T src0Scalar, const LocalTensorT src1Tensor, const LocalTensoruint8_t sharedTmpBuffer)接口框架申请临时空间全部/部分参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const T src0Scalar, const LocalTensorT src1Tensor, uint32_t calCount)全部参与计算template typename T, bool isReuseSource false, const PowerConfig config defaultPowerConfig __aicore__ inline void Power(const LocalTensorT dstTensor, const T src0Scalar, const LocalTensorT src1Tensor)说明src0Tensor.GetSize()/src1Tensor.GetSize()获取的是 Tensor 元素个数可作为calCount使用Scalar 一侧不参与全部/部分之分只作为固定标量被广播。四、临时空间两种申请方式与 BufferSize 获取由于该接口的内部实现涉及复杂的数学计算浮点路径需要存放多级掩码与多块中间 Tensor整型路径需要记录指数迭代状态需要额外的临时空间存储计算过程中的中间变量。临时空间支持接口框架申请和开发者通过sharedTmpBuffer入参传入两种方式接口框架申请开发者无需申请临时空间但需要预留临时空间的大小源码中通过PopStackBufferuint8_t, TPosition::LCM(stackTensor)从框架栈中弹出空间见 power_common_impl.h 中无sharedTmpBuffer的重载实现通过sharedTmpBuffer入参传入使用该 Tensor 作为临时空间接口框架不再申请。该方式开发者可以自行管理sharedTmpBuffer内存空间并在接口调用完成后复用该部分内存内存不会反复申请释放灵活性和内存利用率都更高。源码中TPosition支持VECIN/VECCALC/VECOUT。两种方式下临时空间大小 BufferSize 的获取方式一致通过 host 侧 GetPowerMaxMinTmpSize 接口获取需要预留/申请空间的范围大小。需要特别留意的是接口框架申请临时空间的方式不保证用后清零sharedTmpBuffer内容在调用完成后可能是任意数据开发者不应依赖其残留值源码头文件注释同样明确了这一点。五、模板参数与接口参数说明5.1 模板参数参数名描述T操作数的数据类型。不同型号支持的数据类型见约束说明小节。isReuseSource是否允许修改源操作数。该参数预留传入默认值false即可。config该参数仅支持 Ascend 950PR950DT 系列产品对应__NPU_ARCH__ 3510等架构。Power 计算的相关配置PowerConfig类型可选配定义如下。enum class PowerAlgo { INTRINSIC 0, DOUBLE_FLOAT_TECH, }; struct PowerConfig { PowerAlgo algo PowerAlgo::INTRINSIC; };其中algo为不同数据类型支持的不同 Power 算法取值含义INTRINSIC默认值数据类型为整型时使用快速幂算法实现 Power 计算支持uint8_t、int8_t、uint16_t、int16_t、uint32_t、int32_t数据类型为浮点数时按照公式Power(x, y) exp(y * ln(x))进行 Power 计算支持half、floatDOUBLE_FLOAT_TECH高精度浮点数算法将源操作数的精度提升后按照公式Power(x, y) exp(y * ln(x))进行 Power 计算减少计算过程中的精度损失支持bfloat16_t、half、float。PowerAlgo/PowerConfig/defaultPowerConfig的常量定义可在 power_common_utils.h 中确认。5.2 接口参数参数名输入/输出描述dstTensor输出目的操作数。类型为 LocalTensor支持的 TPosition 为 VECIN/VECCALC/VECOUT。src0Tensor输入源操作数。类型为 LocalTensor支持的 TPosition 为 VECIN/VECCALC/VECOUT。源操作数的数据类型需与目的操作数保持一致。src1Tensor输入源操作数。类型为 LocalTensor支持的 TPosition 为 VECIN/VECCALC/VECOUT。源操作数的数据类型需与目的操作数保持一致。src0Scalar/src1Scalar输入源操作数类型为 Scalar。源操作数的数据类型需与目的操作数保持一致。sharedTmpBuffer输入临时内存空间。类型为 LocalTensor支持的 TPosition 为 VECIN/VECCALC/VECOUT。针对 3 个 Power 接口不同输入数据类型下临时空间大小 BufferSize 的获取方式见 GetPowerMaxMinTmpSize。calCount输入参与计算的元素个数。返回值说明无。六、约束说明使用 Power 接口必须遵守以下约束不支持源操作数与目的操作数地址重叠对于 Atlas 推理系列产品 AI Core幂运算的指数必须小于 231-1操作数地址对齐要求请参见通用地址对齐约束。6.1 支持的数据类型按产品系列产品系列支持的数据类型Ascend 950PR950DT 系列产品uint8_t、int8_t、uint16_t、int16_t、uint32_t、int32_t、half、bfloat16_t、floatAtlas A3 系列产品half、float、int32_tAtlas A2 系列产品half、float、int32_tAtlas 推理系列产品 AI Corehalf、float、int32_t6.2 Ascend 950PR950DT 的 Subnormal 处理针对 Ascend 950PR950DT 系列产品接口内部计算对 Subnormal次正规数的处理方式受编译选项--cce-ftz控制默认值为true配置为false时计算过程中保留 Subnormal并按照其实际数值参与后续计算配置为true时启用 FTZFlush-To-Zero模式计算过程中产生或参与运算的 Subnormal 将按 0 处理可能导致计算结果与保留 Subnormal 时存在精度差异。七、调用示例与运行结果验证文档提供的调用示例完整样例见 power 样例// dstLocal: 存放计算结果的Tensor // srcLocalExp: Power计算使用的指数Tensor // srcLocalBase: Power计算使用的底数Tensor // 使用srcLocalBase做底数对srcLocalExp中的全部元素做幂运算 AscendC::PowerT, false(dstLocal, srcLocalBase, srcLocalExp); // scalarValueBase: Power计算使用的底数 T scalarValueBase srcLocalBase.GetValue(0); // 使用同一个底数scalarValueBase对srcLocalExp中的全部元素做幂运算 AscendC::PowerT, false(dstLocal, scalarValueBase, srcLocalExp); // scalarValueExp: Power计算使用的指数 T scalarValueExp srcLocalExp.GetValue(0); // 使用同一个指数scalarValueExp对srcLocalBase中的全部元素做幂运算 AscendC::PowerT, false(dstLocal, srcLocalBase, scalarValueExp); // 高精度算法仅Ascend 950PR950DT系列产品支持 // static constexpr AscendC::PowerConfig config { AscendC::PowerAlgo::DOUBLE_FLOAT_TECH }; // AscendC::PowersrcType, false, config(dstLocal, scalarValue, srcLocal2);7.1 张量对张量示例数据AscendC::PowerT, false(dstLocal, srcLocalBase, srcLocalExp)输入数据(srcLocalBase): [2 3 4 5 6 7 8 9] 输入数据(srcLocalExp): [4 3 2 1 4 3 2 1] 输出数据(dstLocal): [16 27 16 5 1296 343 64 9]7.2 张量对标量示例数据AscendC::PowerT, false(dstLocal, scalarValueBase, srcLocalExp)输入数据(scalarValueBase): 2 输入数据(srcLocalExp): [4 3 2 1 4 3 2 1] 输出数据(dstLocal): [16 8 4 2 16 8 4 2]7.3 标量对张量示例数据AscendC::PowerT, false(dstLocal, srcLocalBase, scalarValueExp)输入数据(srcLocalBase): [2 3 4 5 6 7 8 9] 输入数据(scalarValueExp): 4 输出数据(dstLocal): [16 81 256 625 1296 2401 4096 6561]7.4 仓库样例工程仓库提供了可直接编译运行的完整样例 examples/01_simd_cpp_api/04_advanced_api/10_math/power核心实现位于 power.asc样例实现KernelPower算子类支持mode 0/1/2三种场景张量对张量、张量对标量、标量对张量对 3510 架构通过static constexpr AscendC::PowerConfig显式选择INTRINSIC或DOUBLE_FLOAT_TECH算法对 2201 架构使用默认配置host 侧通过AscendC::GetPowerMaxMinTmpSize(shape1, shape2, false, sizeof(float), false, maxValue, minValue)获取临时空间大小并以minValue作为tmpBufSize传入核函数真值数据由 scripts/gen_data.py 用numpy.power生成结果与 golden 数据对比EPS 1e-4输出test pass!即通过。编译运行方式在样例目录下SCENARIO0 mkdir -p build cd build cmake -DCMAKE_ASC_ARCHITECTURESdav-2201 -DSCENARIO$SCENARIO ..; make -j python3 ../scripts/gen_data.py --scenario $SCENARIO ./demo其中CMAKE_ASC_ARCHITECTURES可选dav-2201Atlas A2/A3 系列默认或dav-3510Ascend 950PR950DT 系列CMAKE_ASC_RUN_MODE可选npu默认/cpuCPU 调试/simNPU 仿真。样例支持的 CANN 版本Ascend 950PR950DT 系列 ≥ CANN 9.1.0Atlas A3/A2 系列 ≥ CANN 9.0.0。八、配套 host 侧接口GetPowerMaxMinTmpSize核函数Kernel侧 Power 接口的计算需要开发者预留/申请临时空间GetPowerMaxMinTmpSize 用于在host 侧获取预留/申请的最大和最小临时空间大小开发者基于此范围选择合适的空间大小作为 Tiling 参数传递到核函数侧使用。核心规则为保证功能正确预留/申请的临时空间大小不能小于最小临时空间大小在最小临时空间~最大临时空间范围内随着临时空间增大核函数侧接口计算性能会有一定程度的优化提升。为达到更好的性能开发者可以根据实际的内存使用情况在范围内进行空间预留/申请。接口内部根据srcShape1、srcShape2输入判断接口属于Power(dstTensor, srcTensor1, srcTensor2)、Power(dstTensor, srcTensor1, scalarValue)或Power(dstTensor, scalarValue, srcTensor2)中的哪一种进而返回对应临时空间大小——实现上通过ShapeIsTensor判断 shape 是否为一维且长度为 1是则视为标量见 power_tiling_impl.cpp。8.1 函数原型void GetPowerMaxMinTmpSize(const AscendC::TensorShape srcShape1, const AscendC::TensorShape srcShape2, const bool typeIsInt, const uint32_t typeSize, const bool isReuseSource, uint32_t maxValue, uint32_t minValue)8.2 参数说明参数名输入/输出描述srcShape1输入输入 srcTensor1 的 shape 信息参数类型为 AscendC::TensorShape。srcShape2输入输入 srcTensor2 的 shape 信息参数类型为 AscendC::TensorShape。typeIsInt输入bool 类型true表示输入是 int32_t。typeSize输入输入的数据类型大小单位为字节。例如输入的数据类型为 half此处应传入 2。isReuseSource输入是否复用源操作数输入的空间与 Power 接口一致。maxValue输出Power 接口能完成计算所需的最大临时空间大小超出该值的空间不会被该接口使用。在最小临时空间~最大临时空间范围内随着临时空间增大核函数侧接口计算性能会有一定程度的优化提升。最大空间大小为 0 表示计算不需要临时空间。注意maxValue 仅作为参考值有可能大于 Unified BufferUB剩余空间的大小该场景下开发者需要根据 UB 剩余空间的大小来选取合适的临时空间大小。minValue输出Power 接口能完成计算所需的最小临时空间大小。为保证功能正确接口计算时预留/申请的临时空间不能小于该数值。最小空间大小为 0 表示计算不需要临时空间。返回值说明无。8.3 实现原理源码视角从 power_tiling_impl.cpp 可以看出空间估算的底层逻辑对不同架构使用不同的计算过程倍数常量表PowTiling如 V220 架构下POW_TENSOR_TENSOR_HALF_CALC_PROC 14、POW_TENSOR_TENSOR_INT_CALC_PROC 6、POW_TENSOR_TENSOR_FLOAT_CALC_PROC 4Tensor-Scalar 形态相应为 14/7/5V200 架构数值更大说明 half 路径因需要转 float 计算、占用空间约为输入的若干倍而整型快速幂路径倍数较小最小空间 POWER_MIN_TMP_SIZE(256)× 计算过程倍数half 需再除以 2 并加 256B 的 repeat 空间最大空间 max(inputSize*typeSize, 256)× 倍数float 加 256B3510 等架构下最大空间直接取4 * inputSize * 3仅浮点整型返回 0且maxValue minValue接口会通过PlatformAscendCManager::GetCurNpuArch()校验当前设备是否支持不支持的设备上直接返回。8.4 调用示例完整调用样例参考 more_examples.md。Power(dstTensor, srcTensor1, srcTensor2)样例// srcTensor1、srcTensor2输入shape信息均为512; 算子输入的数据类型为float; 不允许修改源操作数 std::vectorint64_t shape_vec {1024}; AscendC::TensorShape shape(shape_vec); uint32_t maxValue 0; uint32_t minValue 0; AscendC::GetPowerMaxMinTmpSize(shape, shape, false, 4, false, maxValue, minValue);Power(dstTensor, srcTensor1, scalarValue)样例// srcTensor1输入shape信息为128*128scalarValue的shape为1; 算子输入的数据类型为half; 不允许修改源操作数 std::vectorint64_t shape1_vec {128, 128}; std::vectorint64_t shape2_vec {1}; AscendC::TensorShape shape1(shape1_vec); AscendC::TensorShape shape2(shape2_vec); uint32_t maxValue 0; uint32_t minValue 0; AscendC::GetPowerMaxMinTmpSize(shape1, shape2, false, 2, false, maxValue, minValue);Power(dstTensor, scalarValue, srcTensor2)样例// scalarValue的shape为1srcTensor2输入shape信息为128*128; 算子输入的数据类型为float; 不允许修改源操作数 std::vectorint64_t shape1_vec {1}; std::vectorint64_t shape2_vec {128, 128}; AscendC::TensorShape shape1(shape1_vec); AscendC::TensorShape shape2(shape2_vec); uint32_t maxValue 0; uint32_t minValue 0; AscendC::GetPowerMaxMinTmpSize(shape1, shape2, false, 4, false, maxValue, minValue);九、配套 host 侧接口GetPowerTmpBufferFactorSizeGetPowerTmpBufferFactorSize 用于获取maxLiveNodeCount和extraBuf在固定空间大小的情况下通过二者可以推算算子单次最大计算元素数量。maxLiveNodeCount表示临时空间是单次计算数据量所占空间的多少倍extraBuf表示使用的额外临时空间大小。9.1 推算公式算子实现需要调用 Power 接口开发者为其预留currBuff大小的空间利用GetPowerTmpBufferFactorSize接口得到maxLiveNodeCount、extraBuf输出值可推导算子单次最大计算元素数量为currentShapeSize (currBuff - extraBuf) / maxLiveNodeCount / typeSize注意上文中的currBuff表示接口计算可用的空间需要去除用户输入输出等空间另外接口获取的maxLiveNodeCount值可能为 0计算时需要判断该值非 0避免除零错误。9.2 函数原型void GetPowerTmpBufferFactorSize(const bool baseIsTensor, const bool expIsTensor, const bool typeIsInt, const uint32_t typeSize, uint32_t maxLiveNodeCount, uint32_t extraBuffer)9.3 参数说明参数名输入/输出功能baseIsTensor输入底数是 Tensor 输入true否则输入false。expIsTensor输入指数是 Tensor 输入true否则输入false。typeIsInt输入数据类型是 int 时输入true否则输入false。typeSize输入输入的数据类型大小单位为字节。例如输入的数据类型为 half此处应传入 2。maxLiveNodeCount输出最大存活节点数表示临时空间是单次计算数据量所占空间的多少倍。extraBuffer输出使用的额外临时空间大小单位为字节。返回值说明无。9.4 约束说明当利用maxLiveNodeCount、extraBuf反推出的currentShapeSize * typeSize 256B时currentShapeSize按照256B / typeSize的值向上取整。9.5 调用示例完整调用样例参考 more_examples.md。uint32_t maxLiveNodeCount 0; uint32_t extraBuf 0; AscendC::GetPowerTmpBufferFactorSize(true, true, true, 4, maxLiveNodeCount, extraBuf);9.6 实现原理源码视角源码中GetPowerTmpBufferFactorSize见 power_tiling_impl.cpp的实现与最大临时空间公式maxTmpBuffer maxLiveNodeCount * inputSize * typeSize extraBuf完全对应头文件 power_tiling.h 注释同样给出该关系式baseIsTensor expIsTensor为 true 时按 Tensor-Tensor 形态取倍数如 V220 下 half/int/float 分别为 14/6/4否则按 Tensor-Scalar 形态取倍数14/7/5extraBuffer默认取REPEAT_BYTE_SIZE(256)仅整型输入时为 03510 等架构下整型输入时maxLiveNodeCount直接为 0表示整型在 3510 上计算无需临时空间float 为 3、half 为 6。该接口的价值在于当 UB 空间受限、无法按 maxValue 预留时开发者可以结合maxLiveNodeCount/extraBuf反推出当前空间能支撑的单次计算元素数从而合理设置 Tiling 切分粒度。十、测试与验证路径仓库为 Power 接口提供了完整的测试与校验支撑可作为验证接口行为的参考功能测试tests/api/adv_api/math/power/test_operator_power.cpp 覆盖 float/half/int32_t 三种数据类型 × NORMAL_MODE框架申请空间与 BASIC_BLK_MODEsharedTmpBuffer传入空间两种内存模式另有 test_operator_power_v200.cpp 与 test_operator_power_c310.cpp 覆盖不同架构参数校验tests/api/adv_api/api_check/math/power/kernel_power_check.cpp 以及校验头文件 impl/adv_api/detail/api_check/kernel_check/math/power/power_check.h 系列对应 Kernel 侧CHECK_FUNC_HIGHLEVEL_API(Power, ...)的编译期检查Tiling 实现impl/adv_api/tiling/math/power_tiling_impl.cpp 是GetPowerMaxMinTmpSize与GetPowerTmpBufferFactorSize的 host 侧落地实现可通过 power_tiling.h 公开头文件调用。十一、总结Power 高阶 API 是 Ascend C 算子开发中处理幂运算的核心接口Kernel 侧提供 12 个重载覆盖Tensor-Tensor / Tensor-Scalar / Scalar-Tensor三种形态与两种临时空间管理方式整型走快速幂、浮点走exp(y*ln(x))两条算法路径并针对 Ascend 950 系列提供DOUBLE_FLOAT_TECH高精度算法与 Subnormal 处理选项host 侧通过GetPowerMaxMinTmpSize与GetPowerTmpBufferFactorSize完成临时空间的范围估算与固定空间下的单次计算量反推从而支撑 Tiling 参数的精细化设计。开发者可直接参考 power 样例 与 测试用例将其快速接入自己的算子实现。赞分享人工智能深度学习算子库CANNAscend【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址https://gitcode.com/cann/asc-devkit点击查看免费下载相关推荐asc-devkit 高阶 API 详解BitwiseAnd 逐比特按位与算子及其临时空间规划指南asc devkit 高阶 API 详解BitwiseAnd 逐比特按位与算子及其临时空间规划指南 导读 本文以 CANN asc devkit 开源仓库中的人工智能深度学习算子库CANNAscendAscendC Xor 高阶接口实战指南按元素异或运算与临时空间管理AscendC Xor 高阶接口实战指南按元素异或运算与临时空间管理 Xor 是 AscendC 高阶算子库adv_api数学计算math_comput人工智能深度学习算子库CANNAscendasc-devkit Matmul 高阶 API 实战IBShareB 直调样例原理与实现asc devkit Matmul 高阶 API 实战IBShareB 直调样例原理与实现 导读 本篇技术指南以 asc devkit 仓库中的 matmul人工智能深度学习算子库CANNAscend上一篇3大核心黑科技让你的老Mac重获新生免费升级到最新macOS下一篇Mac Mouse Fix让普通鼠标在macOS上超越苹果触控板的终极指南创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考