MNN  1.0
Public 类型 | Public 成员函数 | 静态 Public 成员函数 | 友元 | 所有成员列表
MNN::Tensor类 参考

#include <Tensor.hpp>

Public 类型

enum  DimensionType { TENSORFLOW, CAFFE, CAFFE_C4 }
 
enum  HandleDataType { HANDLE_NONE = 0, HANDLE_STRING = 1 }
 
enum  DataReorderType { NO_REORDER = 0, REORDER_4 = 1, REORDER_8 }
 

Public 成员函数

 Tensor (int dimSize=4, DimensionType type=CAFFE)
 create a tensor with dimension size and type without acquire memory for data. 更多...
 
 Tensor (const Tensor *tensor, DimensionType type=CAFFE, bool allocMemory=true)
 create a tensor with same shape as given tensor. 更多...
 
 ~Tensor ()
 
bool copyFromHostTensor (const Tensor *hostTensor)
 for DEVICE tensor, copy data from given host tensor. 更多...
 
bool copyToHostTensor (Tensor *hostTensor) const
 for DEVICE tensor, copy data to given host tensor. 更多...
 
const halide_buffer_tbuffer () const
 
halide_buffer_tbuffer ()
 
DimensionType getDimensionType () const
 get dimension type. 更多...
 
HandleDataType getHandleDataType () const
 handle data type. used when data type code is halide_type_handle. 更多...
 
void setType (int type)
 set data type. 更多...
 
halide_type_t getType () const
 get data type. 更多...
 
template<typename T >
T * host () const
 visit host memory, data type is represented by T. 更多...
 
uint64_t deviceId () const
 visit device memory. 更多...
 
int dimensions () const
 
std::vector< int > shape () const
 get all dimensions' extent. 更多...
 
int size () const
 calculate number of bytes needed to store data taking reordering flag into account. 更多...
 
int elementSize () const
 calculate number of elements needed to store data taking reordering flag into account. 更多...
 
int width () const
 
int height () const
 
int channel () const
 
int batch () const
 
int tfWidth () const
 
int tfHeight () const
 
int tfChannel () const
 
int tfBatch () const
 
int stride (int index) const
 
int length (int index) const
 
void setStride (int index, int stride)
 
void setLength (int index, int length)
 
void print () const
 print tensor data. for DEBUG use only. 更多...
 

静态 Public 成员函数

static TensorcreateDevice (const std::vector< int > &shape, halide_type_t type, DimensionType dimType=TENSORFLOW)
 create tensor with shape, data type and dimension type. 更多...
 
template<typename T >
static TensorcreateDevice (const std::vector< int > &shape, DimensionType dimType=TENSORFLOW)
 create tensor with shape and dimension type. data type is represented by T. 更多...
 
static Tensorcreate (const std::vector< int > &shape, halide_type_t type, void *data=NULL, DimensionType dimType=TENSORFLOW)
 create tensor with shape, data type, data and dimension type. 更多...
 
template<typename T >
static Tensorcreate (const std::vector< int > &shape, void *data=NULL, DimensionType dimType=TENSORFLOW)
 create tensor with shape, data and dimension type. data type is represented by T. 更多...
 
static TensorcreateHostTensorFromDevice (const Tensor *deviceTensor, bool copyData=true)
 create HOST tensor from DEVICE tensor, with or without data copying. 更多...
 

友元

class TensorUtils
 

详细描述

data container. data for host tensor is saved in host field. its memory is allocated malloc directly. data for device tensor is saved in deviceId field. its memory is allocated by session's backend. usually, device tensors are created by engine (like net, session). meanwhile, host tensors could be created by engine or user.

成员枚举类型说明

◆ DataReorderType

dimension reorder flag

枚举值
NO_REORDER 

default reorder type, do not reorder

REORDER_4 

reorder dimension 4 by 4. usually used with NC4HW4 or NHWC4 while data type is float.

REORDER_8 

reorder dimension 8 by 8. usually used with NC4HW4 or NHWC4 while data type is uint8 or int8.

◆ DimensionType

dimension type used to create tensor

枚举值
TENSORFLOW 

for tensorflow net type. uses NHWC as data format.

CAFFE 

for caffe net type. uses NCHW as data format.

CAFFE_C4 

for caffe net type. uses NC4HW4 as data format.

◆ HandleDataType

handle type

枚举值
HANDLE_NONE 

default handle type

HANDLE_STRING 

string handle type

构造及析构函数说明

◆ Tensor() [1/2]

MNN::Tensor::Tensor ( int  dimSize = 4,
DimensionType  type = CAFFE 
)

create a tensor with dimension size and type without acquire memory for data.

参数
dimSizedimension size.
typedimension type.

◆ Tensor() [2/2]

MNN::Tensor::Tensor ( const Tensor tensor,
DimensionType  type = CAFFE,
bool  allocMemory = true 
)

create a tensor with same shape as given tensor.

参数
tensorshape provider.
typedimension type.
allocMemoryacquire memory for data or not.
警告
tensor data won't be copied.

◆ ~Tensor()

MNN::Tensor::~Tensor ( )

deinitializer

成员函数说明

◆ batch()

int MNN::Tensor::batch ( ) const
inline

◆ buffer() [1/2]

const halide_buffer_t& MNN::Tensor::buffer ( ) const
inline

◆ buffer() [2/2]

halide_buffer_t& MNN::Tensor::buffer ( )
inline

◆ channel()

int MNN::Tensor::channel ( ) const
inline

◆ copyFromHostTensor()

bool MNN::Tensor::copyFromHostTensor ( const Tensor hostTensor)

for DEVICE tensor, copy data from given host tensor.

参数
hostTensorhost tensor, the data provider.
返回
true for DEVICE tensor, and false for HOST tensor.

◆ copyToHostTensor()

bool MNN::Tensor::copyToHostTensor ( Tensor hostTensor) const

for DEVICE tensor, copy data to given host tensor.

参数
hostTensorhost tensor, the data consumer.
返回
true for DEVICE tensor, and false for HOST tensor.

◆ create() [1/2]

static Tensor* MNN::Tensor::create ( const std::vector< int > &  shape,
halide_type_t  type,
void *  data = NULL,
DimensionType  dimType = TENSORFLOW 
)
static

create tensor with shape, data type, data and dimension type.

参数
shapetensor shape.
typedata type.
datadata to save.
dimTypedimension type.
返回
created tensor.

◆ create() [2/2]

template<typename T >
static Tensor* MNN::Tensor::create ( const std::vector< int > &  shape,
void *  data = NULL,
DimensionType  dimType = TENSORFLOW 
)
inlinestatic

create tensor with shape, data and dimension type. data type is represented by T.

参数
shapetensor shape.
datadata to save.
dimTypedimension type.
返回
created tensor.

◆ createDevice() [1/2]

static Tensor* MNN::Tensor::createDevice ( const std::vector< int > &  shape,
halide_type_t  type,
DimensionType  dimType = TENSORFLOW 
)
static

create tensor with shape, data type and dimension type.

参数
shapetensor shape.
typedata type.
dimTypedimension type.
返回
created tensor.
警告
memory for data won't be acquired. call backend's onAcquireBuffer to get memory ready.

◆ createDevice() [2/2]

template<typename T >
static Tensor* MNN::Tensor::createDevice ( const std::vector< int > &  shape,
DimensionType  dimType = TENSORFLOW 
)
inlinestatic

create tensor with shape and dimension type. data type is represented by T.

参数
shapetensor shape.
dimTypedimension type.
返回
created tensor.
警告
memory for data won't be acquired. call backend's onAcquireBuffer to get memory ready.

◆ createHostTensorFromDevice()

static Tensor* MNN::Tensor::createHostTensorFromDevice ( const Tensor deviceTensor,
bool  copyData = true 
)
static

create HOST tensor from DEVICE tensor, with or without data copying.

参数
deviceTensorgiven device tensor.
copyDatacopy data or not.
返回
created host tensor.

◆ deviceId()

uint64_t MNN::Tensor::deviceId ( ) const
inline

visit device memory.

返回
device data ID. what the ID means varies between backends.

◆ dimensions()

int MNN::Tensor::dimensions ( ) const
inline

◆ elementSize()

int MNN::Tensor::elementSize ( ) const
inline

calculate number of elements needed to store data taking reordering flag into account.

返回
elements needed to store data

◆ getDimensionType()

DimensionType MNN::Tensor::getDimensionType ( ) const

get dimension type.

返回
dimension type.

◆ getHandleDataType()

HandleDataType MNN::Tensor::getHandleDataType ( ) const

handle data type. used when data type code is halide_type_handle.

返回
handle data type.

◆ getType()

halide_type_t MNN::Tensor::getType ( ) const
inline

get data type.

返回
data type.

◆ height()

int MNN::Tensor::height ( ) const
inline

◆ host()

template<typename T >
T* MNN::Tensor::host ( ) const
inline

visit host memory, data type is represented by T.

返回
data point in T type.

◆ length()

int MNN::Tensor::length ( int  index) const
inline

◆ print()

void MNN::Tensor::print ( ) const

print tensor data. for DEBUG use only.

◆ setLength()

void MNN::Tensor::setLength ( int  index,
int  length 
)
inline

◆ setStride()

void MNN::Tensor::setStride ( int  index,
int  stride 
)
inline

◆ setType()

void MNN::Tensor::setType ( int  type)

set data type.

参数
typedata type defined in 'Type_generated.h'.

◆ shape()

std::vector<int> MNN::Tensor::shape ( ) const

get all dimensions' extent.

返回
dimensions' extent.

◆ size()

int MNN::Tensor::size ( ) const

calculate number of bytes needed to store data taking reordering flag into account.

返回
bytes needed to store data

◆ stride()

int MNN::Tensor::stride ( int  index) const
inline

◆ tfBatch()

int MNN::Tensor::tfBatch ( ) const
inline

◆ tfChannel()

int MNN::Tensor::tfChannel ( ) const
inline

◆ tfHeight()

int MNN::Tensor::tfHeight ( ) const
inline

◆ tfWidth()

int MNN::Tensor::tfWidth ( ) const
inline

◆ width()

int MNN::Tensor::width ( ) const
inline

友元及相关函数文档

◆ TensorUtils

friend class TensorUtils
friend

该类的文档由以下文件生成: