pypto_pro.language.simt.ceil#

产品支持情况#

  • Ascend 950PR/Ascend 950DT:支持

  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持

  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持

功能说明#

将源操作数向正无穷方向舍入到整数值,计算公式如下:

\[result = \lceil value \rceil\]

函数原型#

pypto_pro.language.simt.ceil(
    value: Scalar,
) -> Scalar

参数说明#

参数

输入/输出

说明

value

输入

源操作数,Scalar类型,支持DT_FP16、DT_BF16和DT_FP32。Tensor或Tile元素需通过下标访问后传入。

约束说明#

只能在由@pypto_pro.language.vector_function(mode=”simt”)定义的SIMT入口函数或辅助函数中调用。

返回值说明#

返回不小于源操作数的最小整数值,数据类型与输入一致。

调用示例#

import pypto_pro.language as pl

@pl.vector_function(mode="simt", max_threads=256)
def block_count(
    lengths: pl.Tensor[[1, 256], pl.DT_FP32],
    output: pl.Tensor[[1, 256], pl.DT_FP32],
    block_size: pl.DT_FP32,
):
    tid = pl.simt.linear_thread_idx()
    output[0, tid] = pl.simt.ceil(lengths[0, tid] / block_size)


@pl.jit()
def simt_ceil_kernel(
    lengths: pl.Tensor[[1, 256], pl.DT_FP32],
    output: pl.Tensor[[1, 256], pl.DT_FP32],
    block_size: pl.DT_FP32,
):
    with pl.section_vector():
        block_count[256](lengths, output, block_size)