lhs tensor中的元素与rhs按operation指定的操作进行比较,operation指定的操作包括eq、ne、lt、gt、le、ge,依次表示==、!=、<、>、<=、>=。如果表达式成立,mode为bool时返回True,mode为bit时返回1;如果表达式不成立,mode为bool时返回False,mode为bit时返回0。
以下通过表达式的方式来解释各操作的含义,其中,x表示lhs中的元素,y表示rhs中的元素,z表示结果tensor的元素,n(取值0~7)表示结果tensor的元素的bit位index,表达式如下:
您可以在“te/lang/cce/te_compute/elewise_compute.py”查看接口定义。
因为bool_storage_as_1bit的默认值为True,表示按照1 bit进行存储。
编译配置config如下所示:
import te.lang.cce as tbe with tvm.target.cce(): schedule = tbe.auto_schedule(res) config = {"name": kernel_name, "tensor_list": [data_x, data_y, res], "bool_storage_as_1bit": False} tbe.build(schedule, config)
te.lang.cce.vcmp(lhs, rhs, operation='lt', mode='bool')
res_tensor:结果tensor,tvm.tensor类型。mode为bool时数据类型为bool,mode为bit时数据类型为uint8。
Atlas 200/300/500 推理产品
Atlas 训练系列产品
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 = te.lang.cce.vcmp(data1, data2, 'lt', 'bit')