ConvertTo

Function Usage

Converts the value of a tensor to a specified type. Conversions between float32, float16, int8, int32, uint8, int16, uint16, uint32, int64, uint64, double64, and Boolean types are supported. Asynchronous calling is supported.

It is supported by the Atlas inference product and Atlas 200I/500 A2 inference product.

For the Atlas 200I/500 A2 inference product, preloading is supported (see Example of the Preloading File of the Initialization Operator).

The following conditions must be met:

  • The input and output tensors must be on the device or DVPP side, and the parameters (stream and data memory) must be on the same device.
  • For synchronization, the device where the data memory is located must be the same as the initialized device.
  • For the Atlas inference product, src supports the inplace operation. In this case, the input and output tensors support HW, HWC, or NHWC, and the conversion between the u8 and fp16/fp32 types is supported. The ROI cannot be set for the output tensor, and the shape width and height of the output tensor must be the same as those of the src ROI.

Prototype

1
APP_ERROR ConvertTo(const Tensor &src, Tensor &dst, const MxBase::TensorDType &dataType, AscendStream& stream = AscendStream::DefaultStream());

Parameters

Parameter

Input/Output

Description

src

Input

Tensor class, input tensor.

  • For the inplace operation, the src ROI is the same as the dst shape.
  • For non-inplace operations, the shape of src is the same as that of dst.

dst

Output

Tensor class, output tensor. An empty tensor can be passed. If dst is not an empty tensor, call Tensor.Malloc() to allocate memory in advance.

dataType

Input

TensorDType class. It specifies the conversion type, which must be the same as the TensorDType property of dst.

stream

Input

AscendStream type. The default value is AscendStream::DefaultStream(). When the parameter value is the default value, the API calling is a synchronous operation. In other cases, the API calling is an asynchronous operation.

Response Parameters

Data Structure

Description

APP_ERROR

For details about the returned error codes, see APP_ERROR Description.