Element-Wise Compute APIs
Element-wise compute APIs are used to compute input data element by element. The output usually has the same shape as the input.
vadd
Description
Adds two tensors element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vadd(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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.vadd(data1, data2)
vsub
Description
Subtracts two tensors element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vsub(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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.vsub(data1, data2)
vmul
Description
Multiplies two tensors element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vmul(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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.vmul(data1, data2)
vdiv
Description
Divides two tensors element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vdiv(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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.vdiv(data1, data2)
vmod
Description
Performs modulo operations on two tensors element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vmod(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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.vmod(data1, data2)
vmin
Description
Returns the min of two tensors element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vmin(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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.vmin(data1, data2)
vmax
Description
Returns the max of two tensors element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vmax(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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.vmax(data1, data2)
vor
Description
Performs the bitwise OR operation on two tensors.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
The supported data types are int16 and uint16.
Prototype
te.lang.cce.vor(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "int16" data1 = tvm.placeholder(shape, name="data1", dtype=input_dtype) data2 = tvm.placeholder(shape, name="data2", dtype=input_dtype) res = te.lang.cce.vor(data1, data2)
vand
Description
Performs the bitwise AND operation on two tensors.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
The supported data types are int16 and uint16.
Prototype
te.lang.cce.vand(lhs, rhs)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "int16" data1 = tvm.placeholder(shape, name="data1", dtype=input_dtype) data2 = tvm.placeholder(shape, name="data2", dtype=input_dtype) res = te.lang.cce.vand(data1, data2)
vadds
Description
Adds a scalar to a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
In case of data type inconsistency, the scalar will be converted into the same data type as the tensor during computation.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vadds(raw_tensor, scalar)
Parameters
- raw_tensor: a tvm.tensor for the input tensor
- scalar: a scalar for the coefficient to be added to raw_tensor element-wise
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) scalar = tvm.const(2, dtype =input_dtype) res = te.lang.cce.vadds(data, scalar)
vmins
Description
Compares a raw_tensor with a scalar element-wise and chooses the smaller one.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
In case of data type inconsistency, the scalar will be converted into the same data type as the raw_tensor during computation.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vmins(raw_tensor, scalar)
Parameters
- raw_tensor: a tvm.tensor for the input tensor
- scalar: a scalar for the coefficient to be compared with raw_tensor element-wise
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) scalar = tvm.const(2, dtype =input_dtype) res = te.lang.cce.vmins(data, scalar)
vmaxs
Description
Compares a raw_tensor with a scalar element-wise and chooses the larger one.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
In case of data type inconsistency, the scalar will be converted into the same data type as the raw_tensor during computation.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vmaxs(raw_tensor, scalar)
Parameters
- raw_tensor: a tvm.tensor for the input tensor
- scalar: a scalar for the coefficient to be compared with raw_tensor element-wise
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) scalar = tvm.const(2, dtype =input_dtype) res = te.lang.cce.vmaxs(data, scalar)
vmuls
Description
Multiplies a raw_tensor and a scalar element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
In case of data type inconsistency, the scalar will be converted into the same data type as the raw_tensor during computation.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vmuls(raw_tensor, scalar)
Parameters
- raw_tensor: a tvm.tensor for the input tensor
- scalar: a scalar for the coefficient by which raw_tensor is multiplied element-wise
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) scalar = tvm.const(2, dtype =input_dtype) res = te.lang.cce.vmuls(data, scalar)
vcmp
Description
Compares lhs with rhs element-wise based on operation. The operations specified by operation include 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 meaning of each operation by using an expression. Parameter x indicates an element in lhs, parameter y indicates an element in rhs, parameter z indicates an element of the result tensor, and parameter n (the value ranging from 0 to 7) indicates the bit index of an element 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)
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
- The left and right operands for comparison must have the same data type.
- When mode is set to bool and the te.lang.cce.cce_build_code API is called for compilation, 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 building configuration file is as follows:
with tvm.target.cce(): schedule = generic.auto_schedule(res) config = {"name": kernel_name, "tensor_list": [data_x, data_y, res], "bool_storage_as_1bit": False} te.lang.cce.cce_build_code(schedule, config)
- When mode is set to bit, the last dimension of the shape of the left operand must be divided by 8.
- If the right operand is also a tensor, the two tensors must have the same shape.
- Ascend 310 AI Processor: float16
Prototype
te.lang.cce.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.
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.
Example
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')
vlogic
Description
Performs the logical AND/OR operation on two tensors element-wise, or performs the logical NOT operation on one tensor.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The supported data type is bool. The elements of the two tensors must have the same data type.
Prototype
te.lang.cce.vlogic(lhs, rhs=None, operation='logic_and')
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
- operation: operation type selected from logic_and, logic_or, or logic_not. Defaults to logic_and. To perform the logic_not operation, you must set rhs to None.
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "bool" data1 = tvm.placeholder(shape, name="data1", dtype=input_dtype) data2 = tvm.placeholder(shape, name="data2", dtype=input_dtype) res = te.lang.cce.vlogic(data1, data2, 'logic_and')
vsel
Description
Compares the condition element with True or 1 based on the data type of condition. If the expression is true, the value of x is returned. Otherwise, the value of y is returned.
- If the data type of condition is bool, the condition element is compared with True. If the expression is true, the value of x is returned. Otherwise, the value of y is returned.
- If the data type of condition is uint8, the condition element is compared with the bit index or 1. If the expression is true, the value of x is returned. Otherwise, the value of y is returned.
The following uses an expression to explain the comparison. i indicates the element in the condition, the parameter x' indicates the x element or x, the parameter y' indicates the y element or y, the parameter z indicates the element of the result tensor, and the parameter n (value range: 0–7) indicates the bit index of the condition element. The expression is as follows:
- When the data type of condition is bool:
z = (i==True)? x': y'
- When the data type of condition is uint8:
z = (i[n]==1)? x': y'
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
- x and y must have the same data type.
- When condition is an uint8, the last dimension of the shape of x and y must be a multiple of 8.
- When condition is a bool and the te.lang.cce.cce_build_code API is called for compilation, 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 building configuration file is as follows:
with tvm.target.cce(): schedule = generic.auto_schedule(res) config = {"name": kernel_name, "tensor_list": [data_x, data_y, res], "bool_storage_as_1bit": False} te.lang.cce.cce_build_code(schedule, config)
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vsel(condition, x, y)
Parameters
- condition: a tvm.tensor for the condition tensor of type bool or uint8.
- x: a tvm.tensor or scalar for the possible return value
- y: a tvm.tensor or scalar for the possible return value
Returns
res_tensor: a tvm.tensor for the result tensor
vcmpsel
Description
Compares lhs with rhs element-wise based on operation. The operations specified by operation include eq, ne, lt, gt, le, and ge, which indicate ==, !=, <, >, <=, and >=, respectively. If the expression is true, the value of slhs is returned. Otherwise, the value of srhs is returned.
- 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)
- If rhs is None, the elements in lhs are compared with the floating-point number 2.0.
- If slhs is None and the expression is true, the value of lhs is returned.
- If srhs is None and rhs is a tensor, the value of rhs is returned when the expression is not true.
If srhs is None and rhs is a scalar, the floating-point number 0.0 is returned when the expression is not true.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The data types of all parameters must be the same.
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vcmpsel(lhs,rhs=None,operation='lt', slhs=None, srhs=None)
Parameters
- lhs: a tvm.tensor for the left operand
- rhs: a tvm.tensor or scalar for the right operand. Defaults to None.
- slhs: a tvm.tensor or scalar for the value returned when the comparison expression is true. Defaults to None.
- srhs: a tvm.tensor or scalar for the value returned when the comparison expression is not true. Defaults to None.
- operation: operation type selected from eq, ne, lt, gt, ge, or le. Defaults to lt.
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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 = te.lang.cce.vcmpsel(data1, data2, 'gt', data3, data4)
vlog
Description
Performs the logarithmic ln(x) operation a raw_tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vlog(raw_tensor, priority_flag=0)
Parameters
- raw_tensor: a tvm.tensor for the input tensor
- priority_flag: a scalar for the priority flag
- 1 indicates that the precision takes priority. In this case, the performance deteriorates because the computation process is complex.
- 0 indicates that the performance takes priority. In this case, the precision deteriorates.
Defaults to 0.
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vlog(data)
vexp
Description
Performs the natural exponential operation e^x on a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vexp(raw_tensor)
Parameters
raw_tensor: a tvm.tensor for the input tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vexp(data)
vabs
Description
Performs the absolute value operation |x| on a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vabs(raw_tensor)
Parameters
raw_tensor: a tvm.tensor for the input tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vabs(data)
vrec
Description
Performs the reciprocal operation 1/x on a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vrec(raw_tensor)
Parameters
raw_tensor: a tvm.tensor for the input tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vrec(data)
vrelu
Description
Performs the ReLU operation on a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vrelu(raw_tensor)
Parameters
raw_tensor: a tvm.tensor for the input tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vrelu(data)
vnot
Description
Performs bitwise NOT on a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The supported data types are int16 and uint16.
Prototype
te.lang.cce.vnot(raw_tensor)
Parameters
raw_tensor: a tvm.tensor for the input tensor
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "int16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vnot(data)
vsqrt
Description
Computes the square root for a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vsqrt(raw_tensor, priority_flag=0)
Parameters
- raw_tensor: a tvm.tensor for the input tensor
- priority_flag: a scalar for the priority flag
- 1 indicates that the precision takes priority. In this case, the performance deteriorates because the computation process is complex.
- 0 indicates that the performance takes priority. In this case, the precision deteriorates.
Defaults to 0.
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float 16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vsqrt(data)
vrsqrt
Description
Calculates the reciprocal of the square root for a tensor element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vrsqrt(raw_tensor, priority_flag=0)
Parameters
- raw_tensor: a tvm.tensor for the input tensor
- priority_flag: a scalar for the priority flag
- 1 indicates that the precision takes priority. In this case, the performance deteriorates because the computation process is complex.
- 0 indicates that the performance takes priority. In this case, the precision deteriorates.
Defaults to 0.
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float 16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vrsqrt(data)
vaxpy
Description
Multiplies lhs by a scalar and adds rhs to the result element-wise.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
- lhs and rhs must have the same data type and shape.
- If the data type of the scalar is different from that of the tensor, the data type of the tensor prefers.
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vaxpy(lhs, rhs, scalar)
Parameters
- lhs: a tvm.tensor for the left tensor
- rhs: a tvm.tensor for the right tensor
- scalar: a scalar for the coefficient by which lhs is multiplied
Returns
res_tensor: a tvm.tensor for the result tensor
Example
shape = (1024,1024) input_dtype = "float16" data1 = tvm.placeholder(shape, name="data1", dtype=input_dtype) data2 = tvm.placeholder(shape, name="data2", dtype=input_dtype) scalar = tvm.const(2, dtype =input_dtype) res = te.lang.cce.vaxpy(data1, data2, scalar)
vmla
Description
Multiplies tensor_0 by tensor_1 and adds tensor_2 to the result element-wise. The corresponding computation formula is tensor_0 * tensor_1 + tensor_2.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vmla(tensor_0, tensor_1, tensor_2)
Parameters
- tensor_0: a tvm.tensor for tensor 0
- tensor_1: a tvm.tensor for tensor 1
- tensor_2: a tvm.tensor for tensor 2
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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) res = te.lang.cce.vmla(data1, data2, data3)
vmadd
Description
Multiplies tensor_0 by tensor_2 and adds tensor_1 to the result element-wise. The corresponding computation formula is tensor_0 * tensor_2 + tensor_1
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type and same shape.
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vmadd(tensor_0, tensor_1, tensor_2)
Parameters
- tensor_0: a tvm.tensor for tensor 0
- tensor_1: a tvm.tensor for tensor 1
- tensor_2: a tvm.tensor for tensor 2
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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) res = te.lang.cce.vmadd(data1, data2, data3)
vmaddrelu
Description
Multiplies tensor_0 by tensor_2 and adds tensor_1 to the result element-wise. Then, performs ReLU. The corresponding computation formula is relu(tensor_0 * tensor_2 + tensor_1).
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type.
Ascend 310 AI Processor: float16, float32
Prototype
te.lang.cce.vmaddrelu(tensor_0, tensor_1, tensor_2)
Parameters
- tensor_0: a tvm.tensor for tensor 0
- tensor_1: a tvm.tensor for tensor 1
- tensor_2: a tvm.tensor for tensor 2
Returns
res_tensor: a tvm.tensor for the result tensor
Example
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) res = te.lang.cce.vmaddrelu(data1, data2, data3)
vlrelu
Description
Computes Leaky ReLU on the input tensor element-wise. If an element is greater than or equal to 0, the element is retained; otherwise, the element is multiplied by the alpha constant.
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type.
Ascend 310 AI Processor: float16, float32, int32
Prototype
te.lang.cce.vlrelu(raw_tensor, alpha=0)
Parameters
- raw_tensor: a tvm.tensor for the input
- alpha: a scalar for the input
Returns
res_tensor: a tvm.tensor for the result
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) res = te.lang.cce.vlrelu(data, alpha=0.01)
vaddrelu
Description
Computes ReLU on the element-wise sum of tensor_1 and tensor_0: relu(tensor_0 + tensor_1)
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type.
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vaddrelu(lhs, rhs)
Parameters
- lhs: a tvm.tensor for input 0
- rhs: a tvm.tensor for input 1
Returns
res_tensor: a tvm.tensor for the result
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) data1 = tvm.placeholder(shape, name="data1", dtype=input_dtype) res = te.lang.cce.vaddrelu(data, data1)
vsubrelu
Description
Computes ReLU on the element-wise difference between tensor_1 and tensor_0: relu(tensor_0 - tensor_1)
The API is defined in python/site-packages/te/lang/cce/te_compute/elewise_compute.py in the ATC installation path.
Restrictions
The tensors must have the same data type.
Ascend 310 AI Processor: float16
Prototype
te.lang.cce.vsubrelu(lhs, rhs)
Parameters
- lhs: a tvm.tensor for input 0
- rhs: a tvm.tensor for input 1
Returns
res_tensor: a tvm.tensor for the result
Example
shape = (1024,1024) input_dtype = "float16" data = tvm.placeholder(shape, name="data", dtype=input_dtype) data1 = tvm.placeholder(shape, name="data1", dtype=input_dtype) res = te.lang.cce.vsubrelu(data, data1)