跳到主要内容

~TensorBase

GetTensorDataTypeDesc

函数功能

获取张量的数据类型。

函数原型

std::string GetTensorDataTypeDesc (TensorDataType type);

参数说明

参数名输入/输出说明
type输入枚举值,范围在[-1, 12],参考TensorDataType

返回参数说明

数据结构说明
std::string返回的张量的数据。

父主题: TensorBase

TensorBase

函数功能

TensorBase的构造函数,用来创建TensorBase对象,根据传入的不同参数可选用不同的构造函数。

备注

须知

如出现因内存耗尽,导致构造函数执行失败抛出的异常时,请勿继续调用后续的成员函数。

函数原型

TensorBase();
TensorBase(const MemoryData &memoryData, const bool &isBorrowed, const std::vector<uint32_t> &shape, const TensorDataType &type);
TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type, const MemoryData::MemoryType &bufferType, const int32_t &deviceId);
TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type, const int32_t &deviceId);
TensorBase(const std::vector<uint32_t> &shape, const TensorDataType &type);
TensorBase(const std::vector<uint32_t> &shape);
TensorBase(const TensorBase& tensor) = default;

参数说明

:::note 说明

  • 函数原型2、3、4、5只是预先设置了shape,但不会申请内存空间,需要调用TensorBaseMalloc才能申请对应内存空间。
  • 函数原型1使用场景:用户已在外部申请内存空间,构造Tensor对象的时候直接引用已申请的内存,需确保内存空间大小与Tensor对象的shape一致,同时可以选择外部申请的空间是Tensor对象内部自行释放还是用户外部释放。 :::
参数名输入/输出说明
memoryData输入用于构造TensorBase对象的参数,内存管理结构体,具体请参见MemoryData
isBorrowed输入表示传入的MemoryData数据是否要Tensor主动释放。
- 若为“true”,表示不需要主动释放,用户自行释放。
- 若为“false”,用户不需要手动释放,Tensor析构时自动释放。
shape输入用于构造TensorBase对象的参数,张量的形状。
type输入用于构造TensorBase对象的参数,TensorDataType类型数据,具体请参见TensorDataType枚举说明。
bufferType输入用于构造TensorBase对象的参数,张量数据的内存类型。
deviceId输入用于构造TensorBase对象的参数,int类型数据,设备编号。
tensor输入TensorBase对象,用于构造TensorBase对象的参数。

父主题: TensorBase

~TensorBase

函数功能

TensorBase类的默认析构函数。

函数原型

virtual ~TensorBase() = default;

父主题: TensorBase

TensorBaseMalloc

函数功能

用于获取TensorBase对象的内存。

Tensor对象在析构时会自动释放内存,因此无需通过函数释放内存。

函数原型

static APP_ERROR TensorBaseMalloc(TensorBase &tensor);

参数说明

参数名输入/输出说明
tensor输入用来获取对应内存的Tensor数据。

返回参数说明

数据结构说明
APP_ERROR程序执行返回的错误码,请参考APP_ERROR说明

父主题: TensorBase

TensorBaseCopy

函数功能

内存复制函数,根据MemoryData中指定的内存位置在Host侧和Device侧之间进行复制。

函数原型

static APP_ERROR TensorBaseCopy(TensorBase &dst, const TensorBase &src);

参数说明

参数名输入/输出说明
dst输出复制后的目标内存。
src输入待复制的源内存。

返回参数说明

数据结构说明
APP_ERROR程序执行返回的错误码,请参考APP_ERROR说明

父主题: TensorBase

GetTensorType

函数功能

用于获取Tensor的内存类型。

函数原型

MemoryData::MemoryType GetTensorType() const;

返回参数说明

数据结构说明
MemoryType申请的内存类型: ● MEMORY_HOST:对应Host侧。 ● MEMORY_DEVICE:对应Device侧。 ● MEMORY_DVPP:对应DVPP侧。 ● MEMORY_HOST_MALLOC:对应malloc申请内存。 ● MEMORY_HOST_NEW:对应new申请内存。

父主题: TensorBase

在线提单