Updated on 2022-03-13 GMT+08:00

AITensorFactory::CreateTensor

Creates a model tensor. This API is defined in ai_tensor.h.

Syntax

std::shared_ptr<IAITensor> CreateTensor(const AITensorDescription &tensor_desc, void *buffer, int32_t size);

std::shared_ptr<IAITensor> CreateTensor(const AITensorDescription &tensor_desc);

std::shared_ptr<IAITensor> CreateTensor(const std::string &type);

Parameter Description

Parameter

Description

Value Range

tensor_desc

Tensor description

For details about the syntax of the AITensorDescription data type, see AITensorDescription.

-

buffer

Data address

NOTE:
  • You are advised to allocate the memory for the input data and output data through the HIAI_DMalloc interface. This enables a zero-copy mechanism for algorithm inference to optimize the processing time.
  • The memory address is applied for and released by the customer.

-

size

Data length

NOTE:

The unit is byte. The value of size must be the same as the actual data size.

-

type

Type of registering a tensor

Note:

This API should be used only when no memory is pre-allocated. For details, see the description of type in AITensorDescription.

-

Return Value

If a model tensor is created successfully, the tensor pointer is returned. If a model tensor fails to be created, a null pointer is returned.