pypto_pro.language.max#
产品支持情况#
Ascend 950PR/Ascend 950DT:支持
Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
功能说明#
在Kernel代码中可直接使用Python内置max(lhs, rhs),前端会自动将其解析为pypto_pro.language.max(lhs, rhs),取两个标量中的较大值。
函数原型#
# 以下两种写法等价
result = max(lhs, rhs)
result = pypto_pro.language.max(lhs, rhs)
参数 |
输入/输出 |
说明 |
|---|---|---|
|
输入 |
左操作数(Python |
|
输入 |
右操作数(Python |
调用示例#
import pypto_pro.language as pl
@pl.jit()
def example_kernel(...):
bottom_k = max(1, trunk_len - topk + 1)
end = pl.max(start, min_end)
offset = max(i - window, 0)
c = max(a, b)
注意事项#
仅用于标量:用于循环边界、索引计算等场景
Tile逐元素取最大值:使用
pl.maximum不支持多参数:仅接受恰好2个参数,
max(a, b, c)不支持同类别约束:两个操作数须同为整型或同为浮点型,混合int/float会报错
详见pl.max接口文档。