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 products

uint8

float16

N/A

Supported by:

Atlas inference products

int16

int8

Round down

Supported by:

Atlas inference products

int16

uint8

Round down

Supported by:

Atlas inference products

int16

float16

N/A

Supported by:

Atlas inference products

float32

int32

Round down

Supported by:

Atlas inference products

int32

float32

N/A

Supported by:

Atlas inference products

int32

int64

Round down

Supported by:

Atlas inference products

int64

int32

Round down

Supported by:

Atlas inference products

int64

float16

N/A

Supported by:

Atlas training products

Atlas inference products

Atlas 200I/500 A2 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

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 products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

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 products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

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

Applicable Models

Atlas training products

Atlas inference products

Atlas 200I/500 A2 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

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")