Ln
【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit
产品支持情况
功能说明
按元素取自然对数,计算公式如下:
函数原型
tensor前n个数据计算
template <typename T, const LnConfig& config = DEFAULT_LN_CONFIG> __aicore__ inline void Ln(const LocalTensor<T>& dst, const LocalTensor<T>& src, const int32_t& count)tensor高维切分计算
mask逐bit模式
template <typename T, bool isSetMask = true, const LnConfig& config = DEFAULT_LN_CONFIG> __aicore__ inline void Ln(const LocalTensor<T>& dst, const LocalTensor<T>& src, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)mask连续模式
template <typename T, bool isSetMask = true, const LnConfig& config = DEFAULT_LN_CONFIG> __aicore__ inline void Ln(const LocalTensor<T>& dst, const LocalTensor<T>& src, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
参数说明
表 1模板参数说明
表 2参数说明
返回值说明
无
约束说明
- 操作数地址对齐要求请参见通用地址对齐约束。
- 操作数地址重叠约束请参考通用地址重叠约束。
调用示例
本样例的srcLocal和dstLocal均为half类型。
更多样例可参考LINK。
tensor高维切分计算样例-mask连续模式
uint64_t mask = 256 / sizeof(half); // repeatTime = 4, 128 elements one repeat, 512 elements total // dstBlkStride, srcBlkStride = 1, no gap between blocks in one repeat // dstRepStride, srcRepStride = 8, no gap between repeats AscendC::Ln(dstLocal, srcLocal, mask, 4, { 1, 1, 8, 8 });tensor高维切分计算样例-mask逐bit模式
uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTime = 4, 128 elements one repeat, 512 elements total // dstBlkStride, srcBlkStride = 1, no gap between blocks in one repeat // dstRepStride, srcRepStride = 8, no gap between repeats AscendC::Ln(dstLocal, srcLocal, mask, 4, { 1, 1, 8, 8 });tensor前n个数据计算样例
AscendC::Ln(dstLocal, srcLocal, 512); static constexpr LnConfig config = { LnAlgo::PRECISION_1ULP_FTZ_FALSE }; AscendC::Ln<T, config>(dstLocal, srcLocal, 512);
结果示例如下:
输入数据srcLocal:[1 2 3 4 ...] 输出数据dstLocal:[0 0.6931 1.0986 1.3863 ...]【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考