昇腾社区首页
中文
注册

aclnnSWhere

支持的产品型号

  • Atlas 推理系列产品。
  • Atlas 训练系列产品。
  • Atlas A2训练系列产品/Atlas 800I A2推理产品。

接口原型

每个算子分为undefined,必须先调用“aclnnSWhereGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnSWhere”接口执行计算。

  • aclnnStatus aclnnSWhereGetWorkspaceSize(const aclTensor *condition, const aclTensor *self, const aclTensor *other, aclTensor *out, uint64_t *workspaceSize, aclOpExecutor **executor);
  • aclnnStatus aclnnSWhere(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, aclrtStream stream);

功能描述

  • 算子功能:根据条件选取self或other中元素并返回(支持广播)。
  • 计算公式如下:
outi=where(selfi,otheri,conditioni)={selfi,if conditioniotheri,otherwiseout_i=where(self_i,other_i,condition_i)=\begin{cases} self_i, & \text{if condition}_i \\ other_i, & \text{otherwise} \end{cases}

aclnnSWhereGetWorkspaceSize

  • 参数说明:
    • condition(const aclTensor *, 计算输入):公式中的输入condition,Device侧的aclTensor,数据类型支持UINT8、BOOL,支持非连续的Tensor,shape需要与self和other满足undefined。支持undefinedundefined支持ND。
    • self(const aclTensor *, 计算输入):公式中的输入self,Device侧的aclTensor,数据类型支持FLOAT、BFLOAT16(仅Atlas A2训练系列产品/Atlas 800I A2推理产品支持)、FLOAT16、 INT8、 INT32、UINT8、INT16、INT64、DOUBLE、BOOL、COMPLEX64,shape需要与other和condition满足undefined。支持undefinedundefined支持ND。
    • other(const aclTensor *, 计算输入):公式中的输入other,Device侧的aclTensor,数据类型支持FLOAT、BFLOAT16(仅Atlas A2训练系列产品/Atlas 800I A2推理产品支持)、FLOAT16、 INT8、 INT32、UINT8、INT16、INT64、DOUBLE、BOOL、COMPLEX64,shape需要与self和condition满足undefined。支持undefinedundefined支持ND。
    • out(aclTensor *, 计算输出):公式中的输出out,支持非连续的Tensor,Device侧的aclTensor,数据类型支持FLOAT、BFLOAT16(仅Atlas A2训练系列产品/Atlas 800I A2推理产品支持)、FLOAT16、 INT8、 INT32、UINT8、INT16、INT64、DOUBLE、BOOL、COMPLEX64,shape需要是self与other 和condition broadcast之后的shape。支持非连续的Tensor,数据格式支持ND。
    • workspaceSize(uint64_t *, 出参):返回需要在Device侧申请的workspace大小。
    • executor(aclOpExecutor**, 出参):返回op执行器,包含了算子计算流程。
  • 返回值: aclnnStatus:返回状态码,具体参见undefined
[object Object]

aclnnSWhere

  • 参数说明:

    • workspace(void *, 入参):在Device侧申请的workspace内存地址。
    • workspaceSize(uint64_t, 入参):在Device侧申请的workspace大小,由第一段接口aclnnSWhereGetWorkspaceSize获取。
    • executor(aclOpExecutor*, 入参):op执行器,包含了算子计算流程。
    • stream(aclrtStream, 入参):指定执行任务的 AscendCL Stream流。
  • 返回值: aclnnStatus:返回状态码,具体参见undefined

约束与限制

调用示例

示例代码如下,仅供参考,具体编译和执行过程请参考undefined

[object Object]