clip

Description

Rounds data towards the range of [min_value, max_value] by comparing data's elements with min_value and max_value element-wise. If an element value is within the range, the element is retained. If an element value is not within the range, the element is round to the nearest extreme value.

Restrictions

Atlas training product: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

Atlas inference product: supports float16 and float32.

Atlas 200I/500 A2 inference product: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

Atlas A2 training product/Atlas A2 inference product: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

Atlas A3 training product/Atlas A3 inference product: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be converted to float16.

In case of data type inconsistency, the data type of max_value and min_value will be cast into the same data type as data during computation.

Prototype

clip(data, max_value, min_value)

Parameters

  • data: a tvm.tensor for the input tensor.
  • max_value: a scalar for the maximum value of the target range.
  • min_value: a scalar for the minimum value of the target range.

Returns

res_tensor: a tvm.tensor for the result tensor

Applicability

Atlas training product

Atlas inference product

Atlas 200I/500 A2 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas A3 training product/Atlas A3 inference product

Example

from tbe import tvm
from tbe import dsl
shape = (1024,1024)
input_dtype = "float16"
data = tvm.placeholder(shape, name="data", dtype=input_dtype)
max_value = tvm.const(2, dtype =input_dtype)
min_value = tvm.const(3, dtype =input_dtype)
res = dsl.clip(data, max_value, min_value)