vcmpsel

功能说明

tensor lhs中的元素和rhs按operation处的操作进行比较,operation处的操作包括eq、ne、lt、gt、le、ge,依次表示==、!=、<、>、<=、>=。如果表达式成立,返回slhs对应的值,否则返回srhs对应的值。

以下通过表达式的方式来解释各操作的含义,其中a表示lhs中的元素,b表示rhs中的元素,c表示slhs中的元素,d表示srhs中的元素,res表示结果tensor的元素,表达式如下:
  • lt: res = c (a < b) or d (a >= b)
  • gt: res = c (a > b) or d (a <= b)
  • le: res = c (a <= b) or d (a > b)
  • ge: res = c (a >= b) or d (a < b)
  • eq: res = c (a == b) or d (a != b)
  • ne: res = c (a != b) or d (a == b)

如果srhs为None并且rhs类型为scalar,表达式不成立时,返回float数0.0。

函数原型

vcmpsel(lhs,rhs=None,operation='lt', slhs=None, srhs=None)

参数说明

返回值

res_tensor:结果tensor ,tvm.tensor类型

约束说明

无。

支持的型号

Atlas 200/300/500 推理产品

Atlas 训练系列产品

Atlas 推理系列产品

Atlas A2训练系列产品

调用示例

from tbe import tvm
from tbe import dsl
shape = (1024,1024)
input_dtype = "float16"
data1 = tvm.placeholder(shape, name="data1", dtype=input_dtype)
data2 = tvm.placeholder(shape, name="data2", dtype=input_dtype) 
data3 = tvm.placeholder(shape, name="data3", dtype=input_dtype)
data4 = tvm.placeholder(shape, name="data4", dtype=input_dtype)
res = dsl.vcmpsel(data1, data2, 'gt', data3, data4)