nndeploy C++ API  0.2.0
nndeploy C++ API
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
nndeploy::net::Net Class Reference

#include <net.h>

Inheritance diagram for nndeploy::net::Net:
[legend]
Collaboration diagram for nndeploy::net::Net:
[legend]

Public Member Functions

base::Status addNet (Net *net, bool is_external)
 
TensorWrapperaddTensor (device::Tensor *tensor, bool is_external=true, bool is_weight=false)
 
base::Status copyToInputTensor (device::Tensor *tensor)
 将输入tensor复制到输入tensor More...
 
op::OpcreateOp (base::DeviceType device_type, const std::string &name, ir::OpType op_type, std::initializer_list< std::string > inputs, std::initializer_list< std::string > outputs)
 
op::OpcreateOp (base::DeviceType device_type, const std::string &name, ir::OpType op_type, std::vector< std::string > &inputs, std::vector< std::string > &outputs)
 
TensorWrappercreateTensor (const std::string &name, bool is_weight=false)
 
virtual base::Status deinit ()
 
base::Status dump (std::ostream &oss)
 
base::Status enableOpt (bool flag)
 设置开启图优化的开关 flag: true 启用图优化 false:关闭图优化 More...
 
virtual uint64_t getFlops ()
 得到op的flops More...
 
virtual int64_t getMemorySize ()
 获取推理所需的内存大小 More...
 
std::shared_ptr< base::ParamgetOpParam (const std::string &op_name)
 
device::TensorgetOutputTensorAfterRun (const std::string &name, base::DeviceType device_type, bool is_copy, base::DataFormat data_format)
 获取推理后的输出tensor More...
 
device::TensorgetTensor (const std::string &name)
 
device::TensorgetWeight (const std::string &weight)
 
virtual base::Status inferDataFormat ()
 数据格式推理 More...
 
virtual base::Status inferDataType ()
 类型推理 More...
 
virtual base::Status inferShape ()
 形状推理 More...
 
virtual base::Status init ()
 初始化 More...
 
bool isDynamicShape ()
 
bool isWeight (const std::string &name)
 
 Net ()
 
virtual base::Status postRun ()
 
virtual base::Status preRun ()
 
virtual base::Status reshape (base::ShapeMap &shape_map)
 重新推理形状,通常在初始化之后、preRun前调用 More...
 
virtual base::Status run ()
 
base::Status setDisablePass (std::set< OptPassType >)
 在图优化时禁用这些pass,如果为空则启用全部pass More...
 
base::Status setDynamicShape (bool is_dynamic_shape, base::ShapeMap &min_shape, base::ShapeMap &opt_shape, base::ShapeMap &max_shape)
 
base::Status setEnablePass (std::set< OptPassType >)
 在图优化时仅启用这些pass,如果为空则启用全部pass More...
 
base::Status setInterpret (ir::Interpret *interpret)
 
virtual base::Status setMemory (device::Buffer *buffer)
 设置推理所需的内存(推理内存由外部分配) More...
 
base::Status setModelDesc (ir::ModelDesc *model_desc)
 
base::Status setOpParam (const std::string &op_name, std::shared_ptr< base::Param > param)
 
base::Status setTensorPoolMemory (bool is_external)
 
base::Status setTensorPoolType (TensorPoolType tensor_pool_type)
 
base::Status setWorkers (int worker_num, std::vector< base::DeviceType > device_types=std::vector< base::DeviceType >())
 设置推理并行数量 More...
 
virtual ~Net ()
 
- Public Member Functions inherited from nndeploy::op::Op
virtual base::Status allocateWorkspace ()
 
virtual base::Status checkOrAllocOutput ()
 检查输出tensor More...
 
std::vector< device::Tensor * > getAllInput ()
 
std::vector< std::string > getAllInputName ()
 
std::vector< device::Tensor * > getAllOutput ()
 
std::vector< std::string > getAllOutputName ()
 
bool getConstructed ()
 
bool getDebugFlag ()
 
base::DeviceType getDeviceType ()
 
bool getInitialized ()
 
device::TensorgetInput (int index=0)
 
std::string getInputName (int index=0)
 
device::TensorgetInputTensor (const std::string &name)
 
std::string getName ()
 
ir::OpType getOpType ()
 
device::TensorgetOutput (int index=0)
 
std::string getOutputName (int index=0)
 
device::TensorgetOutputTensor (const std::string &name)
 
base::ParallelType getParallelType ()
 
virtual std::shared_ptr< base::ParamgetParam ()
 
base::PrecisionType getPrecisionType ()
 
device::StreamgetStream ()
 
bool getTimeProfileFlag ()
 
virtual uint64_t getWorkspaceSize ()
 得到op的workspace大小 note: op在运行时的workspace大小,在输入确定后调用 eg:例如Conv,当存在padding时,需要分配额外的内存,存放padding后的内存 More...
 
bool isRunning ()
 
 Op ()
 
base::Status replaceInputTensor (const std::string &name, device::Tensor *tensor)
 
base::Status replaceOutputTensor (const std::string &name, device::Tensor *tensor)
 
base::Status rmInput (device::Tensor *tensor)
 
base::Status setAllInput (std::vector< device::Tensor * > inputs)
 
base::Status setAllInputName (std::initializer_list< std::string >)
 
base::Status setAllInputName (std::vector< std::string > &)
 
base::Status setAllOutput (std::vector< device::Tensor * > outputs)
 
base::Status setAllOutputName (std::initializer_list< std::string >)
 
base::Status setAllOutputName (std::vector< std::string > &)
 
void setDebugFlag (bool flag)
 
base::Status setDeviceType (base::DeviceType device_type)
 
void setInitializedFlag (bool flag)
 
void setInnerFlag (bool flag)
 
virtual base::Status setInput (device::Tensor *input)
 
base::Status setInput (device::Tensor *input, int index)
 
base::Status setName (std::string name)
 
base::Status setOpType (ir::OpType op_type)
 
virtual base::Status setOutput (device::Tensor *output)
 
base::Status setOutput (device::Tensor *output, int index)
 
base::Status setParallelType (const base::ParallelType &paralle_type)
 
virtual base::Status setParam (std::shared_ptr< base::Param > param)
 
virtual base::Status setPrecisionType (base::PrecisionType precision_type)
 设置精度类型 精度不同,计算方式不同,内存分配不同 More...
 
void setRunningFlag (bool flag)
 
void setStream (device::Stream *stream)
 
void setTimeProfileFlag (bool flag)
 
virtual void setWorkspace (void *workspace)
 
virtual ~Op ()
 

Protected Member Functions

virtual base::Status construct ()
 
base::Status optimizer ()
 
virtual base::Status runtime ()
 

Protected Attributes

std::vector< base::DeviceTypedevice_types_
 
std::set< OptPassTypedisable_pass_
 
std::set< OptPassTypeenable_pass_
 
bool is_dynamic_shape_ = false
 
base::ShapeMap max_shape_ = base::ShapeMap()
 
base::ShapeMap min_shape_ = base::ShapeMap()
 
ir::ModelDescmodel_desc_
 
bool net_opt_flag_ = true
 
std::vector< OpWrapper * > op_repository_
 
base::ShapeMap opt_shape_ = base::ShapeMap()
 
Runtimeruntime_ = nullptr
 
bool tensor_pool_memory_is_external_ = false
 
TensorPoolType tensor_pool_type_
 
std::vector< TensorWrapper * > tensor_repository_
 
int worker_num_ = 1
 
- Protected Attributes inherited from nndeploy::op::Op
bool constructed_ = false
 
base::DeviceType device_type_
 op的设备类型 More...
 
uint64_t flops_ = 0
 
bool initialized_ = false
 
std::vector< device::Tensor * > inputs_
 op的输入tensor note: 当权重为tensor时,权重tensor也会在这里 eg: More...
 
bool is_changed_ = false
 
bool is_debug_ = false
 
bool is_external_stream_ = false
 op的stream note: 当stream为外部传入时,is_external_stream_为true More...
 
bool is_inner_ = false
 
bool is_inplace_ = false
 
bool is_running_ = false
 
bool is_time_profile_ = false
 
ir::OpDesc op_desc_
 op的描述 包含op的类型、名称、输入名称、输出名称、参数 More...
 
std::vector< device::Tensor * > outputs_
 op的输出tensor More...
 
base::ParallelType parallel_type_ = base::kParallelTypeNone
 
base::PrecisionType precision_type_ = base::kPrecisionTypeFp32
 op的精度类型 note: 精度类型与输入输出tensor的data_type的不同 More...
 
device::Streamstream_ = nullptr
 
void * workspace_ = nullptr
 
bool workspace_is_external_ = false
 op的workspace大小 note: op在运行时的workspace大小, 在preRun中确定 eg:例如Conv,当存在padding时,需要分配额外的内存,存放padding后的内存 More...
 
uint64_t workspace_size_ = 0
 

Detailed Description

Definition at line 15 of file net.h.

Constructor & Destructor Documentation

◆ Net()

nndeploy::net::Net::Net ( )

◆ ~Net()

virtual nndeploy::net::Net::~Net ( )
virtual

Member Function Documentation

◆ addNet()

base::Status nndeploy::net::Net::addNet ( Net net,
bool  is_external 
)

◆ addTensor()

TensorWrapper* nndeploy::net::Net::addTensor ( device::Tensor tensor,
bool  is_external = true,
bool  is_weight = false 
)

◆ construct()

virtual base::Status nndeploy::net::Net::construct ( )
protectedvirtual

◆ copyToInputTensor()

base::Status nndeploy::net::Net::copyToInputTensor ( device::Tensor tensor)

将输入tensor复制到输入tensor

Parameters
tensor
Returns
base::Status

◆ createOp() [1/2]

op::Op* nndeploy::net::Net::createOp ( base::DeviceType  device_type,
const std::string &  name,
ir::OpType  op_type,
std::initializer_list< std::string >  inputs,
std::initializer_list< std::string >  outputs 
)

◆ createOp() [2/2]

op::Op* nndeploy::net::Net::createOp ( base::DeviceType  device_type,
const std::string &  name,
ir::OpType  op_type,
std::vector< std::string > &  inputs,
std::vector< std::string > &  outputs 
)

◆ createTensor()

TensorWrapper* nndeploy::net::Net::createTensor ( const std::string &  name,
bool  is_weight = false 
)

◆ deinit()

virtual base::Status nndeploy::net::Net::deinit ( )
virtual

Reimplemented from nndeploy::op::Op.

◆ dump()

base::Status nndeploy::net::Net::dump ( std::ostream &  oss)

◆ enableOpt()

base::Status nndeploy::net::Net::enableOpt ( bool  flag)

设置开启图优化的开关 flag: true 启用图优化 false:关闭图优化

◆ getFlops()

virtual uint64_t nndeploy::net::Net::getFlops ( )
virtual

得到op的flops

Returns
uint64_t

Reimplemented from nndeploy::op::Op.

◆ getMemorySize()

virtual int64_t nndeploy::net::Net::getMemorySize ( )
virtual

获取推理所需的内存大小

Returns
int64_t

◆ getOpParam()

std::shared_ptr<base::Param> nndeploy::net::Net::getOpParam ( const std::string &  op_name)

◆ getOutputTensorAfterRun()

device::Tensor* nndeploy::net::Net::getOutputTensorAfterRun ( const std::string &  name,
base::DeviceType  device_type,
bool  is_copy,
base::DataFormat  data_format 
)

获取推理后的输出tensor

Parameters
name
device_type
is_copy
data_format
Returns
device::Tensor*

◆ getTensor()

device::Tensor* nndeploy::net::Net::getTensor ( const std::string &  name)

◆ getWeight()

device::Tensor* nndeploy::net::Net::getWeight ( const std::string &  weight)

◆ inferDataFormat()

virtual base::Status nndeploy::net::Net::inferDataFormat ( )
virtual

数据格式推理

Returns
base::Status
Note
当输入的shape数据格式时,在计算图Net::init中调用该函数

Reimplemented from nndeploy::op::Op.

◆ inferDataType()

virtual base::Status nndeploy::net::Net::inferDataType ( )
virtual

类型推理

Returns
base::Status
Note
当输入的data_type确定时,在计算图Net::init中会调用该函数

Reimplemented from nndeploy::op::Op.

◆ inferShape()

virtual base::Status nndeploy::net::Net::inferShape ( )
virtual

形状推理

Returns
base::Status
Note
当输入的shape确定时,在计算图Net::init中调用该函数

Reimplemented from nndeploy::op::Op.

◆ init()

virtual base::Status nndeploy::net::Net::init ( )
virtual

初始化

Returns
base::Status
Note
功能
  1. 参数
  2. 权重

Reimplemented from nndeploy::op::Op.

◆ isDynamicShape()

bool nndeploy::net::Net::isDynamicShape ( )

◆ isWeight()

bool nndeploy::net::Net::isWeight ( const std::string &  name)

◆ optimizer()

base::Status nndeploy::net::Net::optimizer ( )
protected

◆ postRun()

virtual base::Status nndeploy::net::Net::postRun ( )
virtual

Reimplemented from nndeploy::op::Op.

◆ preRun()

virtual base::Status nndeploy::net::Net::preRun ( )
virtual

Reimplemented from nndeploy::op::Op.

◆ reshape()

virtual base::Status nndeploy::net::Net::reshape ( base::ShapeMap shape_map)
virtual

重新推理形状,通常在初始化之后、preRun前调用

Parameters
shape_map
Returns
base::Status

Reimplemented from nndeploy::op::Op.

◆ run()

virtual base::Status nndeploy::net::Net::run ( )
virtual

Implements nndeploy::op::Op.

◆ runtime()

virtual base::Status nndeploy::net::Net::runtime ( )
protectedvirtual

◆ setDisablePass()

base::Status nndeploy::net::Net::setDisablePass ( std::set< OptPassType )

在图优化时禁用这些pass,如果为空则启用全部pass

◆ setDynamicShape()

base::Status nndeploy::net::Net::setDynamicShape ( bool  is_dynamic_shape,
base::ShapeMap min_shape,
base::ShapeMap opt_shape,
base::ShapeMap max_shape 
)

◆ setEnablePass()

base::Status nndeploy::net::Net::setEnablePass ( std::set< OptPassType )

在图优化时仅启用这些pass,如果为空则启用全部pass

◆ setInterpret()

base::Status nndeploy::net::Net::setInterpret ( ir::Interpret interpret)

◆ setMemory()

virtual base::Status nndeploy::net::Net::setMemory ( device::Buffer buffer)
virtual

设置推理所需的内存(推理内存由外部分配)

Parameters
buffer
Returns
base::Status

◆ setModelDesc()

base::Status nndeploy::net::Net::setModelDesc ( ir::ModelDesc model_desc)

◆ setOpParam()

base::Status nndeploy::net::Net::setOpParam ( const std::string &  op_name,
std::shared_ptr< base::Param param 
)

◆ setTensorPoolMemory()

base::Status nndeploy::net::Net::setTensorPoolMemory ( bool  is_external)

◆ setTensorPoolType()

base::Status nndeploy::net::Net::setTensorPoolType ( TensorPoolType  tensor_pool_type)

◆ setWorkers()

base::Status nndeploy::net::Net::setWorkers ( int  worker_num,
std::vector< base::DeviceType device_types = std::vector< base::DeviceType >() 
)

设置推理并行数量

Parameters
num
Returns
base::Status

Member Data Documentation

◆ device_types_

std::vector<base::DeviceType> nndeploy::net::Net::device_types_
protected

Definition at line 167 of file net.h.

◆ disable_pass_

std::set<OptPassType> nndeploy::net::Net::disable_pass_
protected

Definition at line 162 of file net.h.

◆ enable_pass_

std::set<OptPassType> nndeploy::net::Net::enable_pass_
protected

Definition at line 159 of file net.h.

◆ is_dynamic_shape_

bool nndeploy::net::Net::is_dynamic_shape_ = false
protected

Definition at line 149 of file net.h.

◆ max_shape_

base::ShapeMap nndeploy::net::Net::max_shape_ = base::ShapeMap()
protected

Definition at line 152 of file net.h.

◆ min_shape_

base::ShapeMap nndeploy::net::Net::min_shape_ = base::ShapeMap()
protected

Definition at line 150 of file net.h.

◆ model_desc_

ir::ModelDesc* nndeploy::net::Net::model_desc_
protected

Definition at line 144 of file net.h.

◆ net_opt_flag_

bool nndeploy::net::Net::net_opt_flag_ = true
protected

Definition at line 158 of file net.h.

◆ op_repository_

std::vector<OpWrapper *> nndeploy::net::Net::op_repository_
protected

Definition at line 147 of file net.h.

◆ opt_shape_

base::ShapeMap nndeploy::net::Net::opt_shape_ = base::ShapeMap()
protected

Definition at line 151 of file net.h.

◆ runtime_

Runtime* nndeploy::net::Net::runtime_ = nullptr
protected

Definition at line 156 of file net.h.

◆ tensor_pool_memory_is_external_

bool nndeploy::net::Net::tensor_pool_memory_is_external_ = false
protected

Definition at line 155 of file net.h.

◆ tensor_pool_type_

TensorPoolType nndeploy::net::Net::tensor_pool_type_
protected
Initial value:

Definition at line 153 of file net.h.

◆ tensor_repository_

std::vector<TensorWrapper *> nndeploy::net::Net::tensor_repository_
protected

Definition at line 146 of file net.h.

◆ worker_num_

int nndeploy::net::Net::worker_num_ = 1
protected

Definition at line 165 of file net.h.


The documentation for this class was generated from the following file: