cast_to

Description

Casts a data type, specifically, from data type of data into target dtype. The supported cast types are listed as follows.

Table 1 Supported cast types

Source Data Type

Target Data Type

Rounding Mode

Description

float32

float16

N/A

Supported by all SoC types

float32

int8

Round down

Supported by all SoC types

float32

uint8

Round down

Supported by all SoC types

float16

float32

N/A

Supported by all SoC types

float16

int8

Round down

Supported by all SoC types

float16

uint8

Round down

Supported by all SoC types

float16

int32

Round down

Supported by all SoC types

int8

float16

N/A

Supported by all SoC types

int8

uint8

Round down

Supported by all SoC types

int32

float16

N/A

Supported by all SoC types

int32

int8

Round down

Supported by all SoC types

int32

uint8

Round down

Supported by all SoC types

uint8

int8

Round down

Supported by:

Atlas inference product

uint8

float16

N/A

Supported by:

Atlas inference product

int16

int8

Round down

Supported by:

Atlas inference product

int16

uint8

Round down

Supported by:

Atlas inference product

int16

float16

N/A

Supported by:

Atlas inference product

float32

int32

Round down

Supported by:

Atlas inference product

int32

float32

N/A

Supported by:

Atlas inference product

int32

int64

Round down

Supported by:

Atlas inference product

int64

int32

Round down

Supported by:

Atlas inference product

int64

float16

N/A

Supported by:

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

float16

complex32

N/A

When a real number is converted to a complex number, the imaginary part is 0 by default.

Supported by:

Atlas A2 training product/Atlas A2 inference product

Atlas A3 training product/Atlas A3 inference product

float32

complex64

N/A

When a real number is converted to a complex number, the imaginary part is 0 by default.

Supported by:

Atlas A2 training product/Atlas A2 inference product

Atlas A3 training product/Atlas A3 inference product

Prototype

cast_to(data, dtype, f1628IntegerFlag=True)

Parameters

  • data: a tvm.tensor for the input tensor.
  • dtype: a string for the target data type.
  • f1628IntegerFlag: defaults to True. If the decimal part of data is 0, set f1628IntegerFlag to True. Otherwise, set f1628IntegerFlag to False.

Returns

res_tensor: a tvm.tensor for the result tensor

Restrictions

None

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)
res = dsl.cast_to(data,"float32")