Cast

Applicability

Product

Supported

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

x

Atlas inference products

Atlas training products

Function Usage

Converts an input tensor to the specified data type.

Prototype

const aclTensor *Cast(const aclTensor *self, op::DataType dstDtype, aclOpExecutor *executor)

Parameters

Parameter

Input/Output

Description

self

Input

Input tensor to be converted. The data type can be FLOAT16, FLOAT, DOUBLE, BFLOAT16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, BOOL, COMPLEX64, or COMPLEX 128. The data format can be ND.

NOTE:

BFLOAT16 applies to the following product models:

Atlas A2 training products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

dstDtype

Input

Destination type of the converted tensor. The data type can be FLOAT16, FLOAT, DOUBLE, BFLOAT16, INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, BOOL, COMPLEX64, or COMPLEX 128.

NOTE:

BFLOAT16 applies to the following product models:

Atlas A2 training products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

executor

Input

Operator executor, containing the operator computation process.

Returns

A tensor of dstDtype.

Constraints

None

Examples

1
2
3
4
5
6
7
8
9
// Standard format for creating an OpExecutor
auto uniqueExecutor = CREATE_EXECUTOR();

auto selfCasted = self;
// When self is of the Boolean type, use the Cast API to convert it to the uint8 type for integer computation.
if (self->GetDataType() == op::DataType::DT_BOOL) {
  selfCasted = l0op::Cast(self, op::DataType::DT_UINT8, uniqueExecutor.get());
  CHECK_RET(selfCasted != nullptr, ACLNN_ERR_PARAM_NULLPTR);
}