vcmp
Description
Compares lhs with rhs element-wise based on operation. The operations specified by operation are selected from eq, ne, lt, gt, le, and ge, which indicate ==, !=, <, >, <=, and >=, respectively. If the expression is true, True is returned when the mode is bool, and 1 is returned when the mode is bit. If the expression is false, False is returned when the mode is bool, and 0 is returned when the mode is bit.
The following describes the operations by using expressions. x indicates an element in lhs, y indicates an element in rhs, z indicates an element of the result tensor, and n (a value ranging from 0 to 7) indicates the index of the bit dimension of the result tensor. The expressions are as follows:
- mode=='bool':
- lt: z = True (x < y) or False (x >= y)
- gt: z = True (x > y) or False (x <= y)
- le: z = True (x <= y) or False (x > y)
- ge: z = True (x >= y) or False (x < y)
- eq: z = True (x == y) or False (x != y)
- ne: z = True (x != y) or False (x == y)
- mode=='bit':
- lt: z[n] = 1 (x < y) or 0 (x >= y)
- gt: z[n] = 1 (x > y) or 0 (x <= y)
- le: z[n] = 1 (x <= y) or 0 (x > y)
- ge: z[n] = 1 (x >= y) or 0 (x < y)
- eq: z[n] = 1 (x == y) or 0 (x != y)
- ne: z[n] = 1 (x != y) or 0 (x == y)
Prototype
vcmp(lhs, rhs, operation='lt', mode='bool')
Parameters
- lhs: a tvm.tensor for the left operand.
- rhs: a tvm.tensor or scalar for the right operand.
- operation: operation type selected from eq, ne, lt, gt, ge, or le. Defaults to lt.
- mode: mode selected from bool or bit. Defaults to bool.
The left and right operands for comparison must have the same data type.
Atlas training products : supports float16, float32, and int64.Atlas inference products : supports float16, float32, int64, and uint64.Atlas 200I/500 A2 inference products : supports float16, float32, and int64.Atlas A2 training products /Atlas A2 inference products : supports float16, float32, and int64.Atlas A3 training products /Atlas A3 inference products : supports float16, float32, and int64.
Returns
res_tensor: a tvm.tensor for the result tensor If mode is set to bool, the data type is bool. If mode is set to bit, the data type is uint8.
Restrictions
- When mode is set to bool and the tbe.dsl.build API is called for build, bool_storage_as_1bit in the passed configuration parameter must be set to False. Otherwise, unexpected output shape will be obtained.
bool_storage_as_1bit is set to True by default, indicating that it is stored as 1-bit data.
The following gives a build configuration file template.
with tvm.target.cce(): schedule = tbe.dsl.auto_schedule(res) config = {"name": kernel_name, "tensor_list": [data_x, data_y, res], "bool_storage_as_1bit": False} tbe.dsl.build(schedule, config) - When mode is set to bit, the last dimension of the shape of the left operand must be divisible by 8.
- If the right operand is also a tensor, the two tensors must have the same shape.
- For Atlas Inference Series Product, when the data type is int64 or uint64, mode must be set to bool.
Applicable Models
Example
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) res = dsl.vcmp(data1, data2, 'lt', 'bit')