news 2026/5/9 15:11:40

CANN/pyasc LeakyReLU函数API

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN/pyasc LeakyReLU函数API

asc.language.basic.leaky_relu

【免费下载链接】pyasc本项目为Python用户提供算子编程接口,支持在昇腾AI处理器上加速计算,接口与Ascend C一一对应并遵守Python原生语法。项目地址: https://gitcode.com/cann/pyasc

asc.language.basic.leaky_relu(dst: LocalTensor, src: LocalTensor, scalar: int | float, count: int, is_set_mask: bool = True) → None

asc.language.basic.leaky_relu(dst: LocalTensor, src: LocalTensor, scalar: int | float, mask: int, repeat_times: int, repeat_params: UnaryRepeatParams, is_set_mask: bool = True) → None

asc.language.basic.leaky_relu(dst: LocalTensor, src: LocalTensor, scalar: int | float, mask: List[int], repeat_times: int, repeat_params: UnaryRepeatParams, is_set_mask: bool = True) → None

按元素执行Leaky ReLU(Leaky Rectified Linear Unit)操作。

对应的Ascend C函数原型

template <typename T, bool isSetMask = true> __aicore__ inline void LeakyRelu(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, const int32_t& calCount)
template <typename T, bool isSetMask = true> __aicore__ inline void LeakyRelu(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, uint64_t mask[], const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams)
template <typename T, bool isSetMask = true> __aicore__ inline void LeakyRelu(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const T& scalarValue, uint64_t mask, const uint8_t repeatTimes, const UnaryRepeatParams& repeatParams)

参数说明

  • is_set_mask:是否在接口内部设置mask模式和mask值。
  • dst:目的操作数。类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。
  • src:源操作数。类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。
  • scalar:源操作数,数据类型需要与目的操作数中的元素类型保持一致。
  • count:参与计算的元素个数。
  • mask:用于控制每次迭代内参与计算的元素。
  • repeat_times:重复迭代次数。
  • params:元素操作控制结构信息。

约束说明

  • 操作数地址对齐要求请参见 《Ascend C算子开发接口》 中的“通用说明和约束-通用地址对齐约束”。
  • 操作数地址重叠约束请参考 《Ascend C算子开发接口》 中的“通用说明和约束-通用地址重叠约束”。

调用示例

  • tensor高维切分计算样例-mask连续模式
    mask = 128 scalar = 2 # repeat_times = 4,一次迭代计算128个数,共计算512个数 # dst_blk_stride, src_blk_stride = 1,单次迭代内数据连续读取和写入 # dst_rep_stride, src_rep_stride = 8,相邻迭代间数据连续读取和写入 params = asc.UnaryRepeatParams(1, 1, 8, 8) asc.leaky_relu(dst, src, scalar, mask=mask, repeat_times=4, repeat_params=params)
  • tensor高维切分计算样例-mask逐bit模式
    mask = [uint64_max, uint64_max] scalar = 2 # repeat_times = 4,一次迭代计算128个数,共计算512个数 # dst_blk_stride, src_blk_stride = 1,单次迭代内数据连续读取和写入 # dst_rep_stride, src_rep_stride = 8,相邻迭代间数据连续读取和写入 params = asc.UnaryRepeatParams(1, 1, 8, 8) asc.leaky_relu(dst, src, scalar, mask=mask, repeat_times=4, repeat_params=params)
  • tensor前n个数据计算样例
    asc.leaky_relu(dst, src, scalar, count=512)

【免费下载链接】pyasc本项目为Python用户提供算子编程接口,支持在昇腾AI处理器上加速计算,接口与Ascend C一一对应并遵守Python原生语法。项目地址: https://gitcode.com/cann/pyasc

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

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/9 15:11:21

CANN/ops-math PadV3梯度复制算子

PadV3GradReplication 【免费下载链接】ops-math 本项目是CANN提供的数学类基础计算算子库&#xff0c;实现网络在NPU上加速计算。 项目地址: https://gitcode.com/cann/ops-math 产品支持情况 产品是否支持Ascend 950PR/Ascend 950DTAtlas A3 训练系列产品/Atlas A3 推…

作者头像 李华
网站建设 2026/5/9 15:09:55

浏览器自动化技能库:提升Playwright与Puppeteer开发效率的实战指南

1. 项目概述&#xff1a;一个浏览器自动化技能库的诞生最近在折腾浏览器自动化项目时&#xff0c;我遇到了一个几乎所有开发者都会碰到的痛点&#xff1a;重复造轮子。无论是处理复杂的登录验证、解析动态加载的网页数据&#xff0c;还是模拟特定的用户交互序列&#xff0c;很多…

作者头像 李华
网站建设 2026/5/9 15:09:20

vurb.ts:全栈TypeScript框架的端到端类型安全与插件化架构

1. 项目概述&#xff1a;一个现代、类型安全的Web应用构建框架如果你最近在寻找一个能兼顾开发体验、类型安全和运行时性能的Web应用框架&#xff0c;那么你很可能已经注意到了vinkius-labs/vurb.ts这个名字。它不是一个简单的工具库&#xff0c;而是一个旨在重新定义全栈TypeS…

作者头像 李华
网站建设 2026/5/9 15:03:32

CANN/AMCT训练后量化配置

训练后量化简易配置文件 【免费下载链接】amct AMCT是CANN提供的昇腾AI处理器亲和的模型压缩工具仓。 项目地址: https://gitcode.com/cann/amct calibration_config_pytorch.proto文件参数说明如表1所示&#xff0c;该文件所在目录为&#xff1a;AMCT安装目录/amct_pyt…

作者头像 李华
网站建设 2026/5/9 15:03:31

基于MCP协议连接AI与Telegram:构建智能通讯自动化工作流

1. 项目概述&#xff1a;一个连接AI与即时通讯的桥梁最近在折腾AI应用集成时&#xff0c;发现了一个挺有意思的项目&#xff1a;dryeab/mcp-telegram。简单来说&#xff0c;这是一个实现了Model Context Protocol (MCP)协议的Telegram服务器。它的核心价值在于&#xff0c;能让…

作者头像 李华