nndeploy C++ API  0.2.0
nndeploy C++ API
Public Member Functions | List of all members
nndeploy::dag::Edge Class Reference

Edge class in DAG graph for connecting nodes and transferring data. More...

#include <edge.h>

Inheritance diagram for nndeploy::dag::Edge:
[legend]
Collaboration diagram for nndeploy::dag::Edge:
[legend]

Public Member Functions

template<typename T >
bool checkTypeInfo ()
 Check if type information matches (template version) More...
 
bool checkTypeInfo (std::shared_ptr< EdgeTypeInfo > type_info)
 Check if type information matches. More...
 
base::Status construct ()
 Construct the Edge instance. More...
 
template<typename T , typename... Args, typename std::enable_if< std::is_base_of< base::Param, T >::value, int >::type = 0>
base::Paramcreate (Args &&...args)
 Create Param object of specified type. More...
 
template<typename T , typename... Args>
T * create (Args &&...args)
 Create arbitrary type data object (template version) More...
 
device::Buffercreate (device::Device *device, const device::BufferDesc &desc)
 Create Buffer on specified device. More...
 
device::Tensorcreate (device::Device *device, const device::TensorDesc &desc, std::string tensor_name="")
 Create Tensor on specified device. More...
 
 Edge ()
 Default constructor. More...
 
 Edge (const std::string &name)
 Constructor with name. More...
 
bool empty ()
 Check if the Edge is empty. More...
 
template<typename T >
T * get (const Node *node)
 Get arbitrary type data for specified node (template version) More...
 
device::BuffergetBuffer (const Node *node)
 Get Buffer data for specified node. More...
 
std::vector< Node * > getConsumers ()
 Get all consumer nodes. More...
 
template<typename T >
T * getGraphOutput ()
 Get arbitrary type data for graph output (template version) More...
 
device::BuffergetGraphOutputBuffer ()
 Get Buffer data for graph output. More...
 
int64_t getGraphOutputIndex ()
 Get data index for graph output. More...
 
base::ParamgetGraphOutputParam ()
 Get Param data for graph output. More...
 
int getGraphOutputPosition ()
 Get position of graph output in queue. More...
 
void * getGraphOutputPtr ()
 Get raw pointer for graph output. More...
 
device::TensorgetGraphOutputTensor ()
 Get Tensor data for graph output. More...
 
int64_t getIndex (const Node *node)
 Get data index for specified node. More...
 
std::string getName ()
 Get the name of the Edge. More...
 
base::ParallelType getParallelType ()
 Get the current parallel type. More...
 
base::ParamgetParam (const Node *node)
 Get Param data for specified node. More...
 
int getPosition (const Node *node)
 Get position of specified node in queue. More...
 
std::vector< Node * > getProducers ()
 Get all producer nodes. More...
 
int getQueueDropCount ()
 Get the queue drop count. More...
 
int getQueueMaxSize ()
 Get the maximum queue capacity. More...
 
base::QueueOverflowPolicy getQueueOverflowPolicy ()
 Get the current queue overflow policy. More...
 
device::TensorgetTensor (const Node *node)
 Get Tensor data for specified node. More...
 
std::shared_ptr< EdgeTypeInfogetTypeInfo ()
 Get type information of Edge. More...
 
std::string getTypeName ()
 Get type name. More...
 
base::Status increaseConsumers (std::vector< Node * > &consumers)
 Add consumer nodes. More...
 
base::Status increaseProducers (std::vector< Node * > &producers)
 Add producer nodes. More...
 
bool markGraphOutput ()
 Mark as graph output Edge. More...
 
bool notifyWritten (base::Param *param)
 Notify that Param data has been written. More...
 
bool notifyWritten (device::Buffer *buffer)
 Notify that Buffer data has been written. More...
 
bool notifyWritten (device::Tensor *tensor)
 Notify that Tensor data has been written. More...
 
template<typename T >
bool notifyWritten (T *t)
 Notify that arbitrary type data has been written (template version) More...
 
bool requestTerminate ()
 Request termination of Edge processing. More...
 
void resetIndex ()
 Reset index counter. More...
 
base::Status set (base::Param &param)
 Set Param reference to Edge. More...
 
base::Status set (base::Param *param, bool is_external=true)
 Set Param data to Edge. More...
 
base::Status set (device::Buffer &buffer)
 Set Buffer reference to Edge. More...
 
base::Status set (device::Buffer *buffer, bool is_external=true)
 Set Buffer data to Edge. More...
 
base::Status set (device::Tensor &tensor)
 Set Tensor reference to Edge. More...
 
base::Status set (device::Tensor *tensor, bool is_external=true)
 Set Tensor data to Edge. More...
 
template<typename T >
base::Status set (T &t)
 Set arbitrary type data reference to Edge (template version) More...
 
template<typename T >
base::Status set (T *t, bool is_external=true)
 Set arbitrary type data to Edge (template version) More...
 
template<typename T >
base::Status set (T *t, std::function< void(T *)> deleter)
 
template<typename PY_WRAPPER , typename T >
base::Status set4py (PY_WRAPPER *wrapper, T *t, bool is_external=true)
 Data setting interface dedicated for Python binding. More...
 
base::Status setParallelType (const base::ParallelType &paralle_type)
 Set the parallel type. More...
 
base::Status setQueueMaxSize (int queue_max_size)
 Set the maximum queue capacity. More...
 
base::Status setQueueOverflowPolicy (base::QueueOverflowPolicy policy, int drop_count=1)
 Set the queue overflow policy. More...
 
template<typename T >
base::Status setTypeInfo ()
 Set type information of Edge (template version) More...
 
base::Status setTypeInfo (std::shared_ptr< EdgeTypeInfo > type_info)
 Set type information of Edge. More...
 
void setTypeName (const std::string &type_name)
 Set type name. More...
 
base::EdgeUpdateFlag update (const Node *node)
 Update Edge status for specified node. More...
 
virtual ~Edge ()
 Virtual destructor. More...
 
- Public Member Functions inherited from nndeploy::base::NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
NonCopyableoperator= (NonCopyable &&)=delete
 

Detailed Description

Edge class in DAG graph for connecting nodes and transferring data.

The Edge class is one of the core components of the DAG graph in the nndeploy framework, responsible for transferring data between nodes. It provides functionality similar to std::any, capable of storing arbitrary types of data while supporting advanced features such as memory management, queue buffering, and parallel processing.

It is recommended to use template functions set/create/notifyWritten/get/getGraphOutput to set and retrieve data,

Definition at line 35 of file edge.h.

Constructor & Destructor Documentation

◆ Edge() [1/2]

nndeploy::dag::Edge::Edge ( )

Default constructor.

Creates an unnamed Edge instance with default configuration parameters

◆ Edge() [2/2]

nndeploy::dag::Edge::Edge ( const std::string &  name)

Constructor with name.

Parameters
nameName of the Edge, used for debugging and logging

◆ ~Edge()

virtual nndeploy::dag::Edge::~Edge ( )
virtual

Virtual destructor.

Automatically cleans up internal resources, including abstract edge instances and related data

Member Function Documentation

◆ checkTypeInfo() [1/2]

template<typename T >
bool nndeploy::dag::Edge::checkTypeInfo ( )
inline

Check if type information matches (template version)

Template Parameters
TData type to check
Returns
bool true indicates type matches, false indicates mismatch

Definition at line 637 of file edge.h.

Here is the call graph for this function:

◆ checkTypeInfo() [2/2]

bool nndeploy::dag::Edge::checkTypeInfo ( std::shared_ptr< EdgeTypeInfo type_info)

Check if type information matches.

Parameters
type_infoType information to check
Returns
bool true indicates type matches, false indicates mismatch

◆ construct()

base::Status nndeploy::dag::Edge::construct ( )

Construct the Edge instance.

Creates concrete AbstractEdge implementation based on set parallel type and other parameters

Returns
base::Status Construction status, returns kSuccess on success

◆ create() [1/4]

template<typename T , typename... Args, typename std::enable_if< std::is_base_of< base::Param, T >::value, int >::type = 0>
base::Param* nndeploy::dag::Edge::create ( Args &&...  args)
inline

Create Param object of specified type.

Template Parameters
TConcrete type of Param, must inherit from base::Param
ArgsConstructor parameter types
Parameters
argsConstructor parameters
Returns
base::Param* Created Param pointer, returns nullptr on failure

Definition at line 338 of file edge.h.

◆ create() [2/4]

template<typename T , typename... Args>
T* nndeploy::dag::Edge::create ( Args &&...  args)
inline

Create arbitrary type data object (template version)

Template Parameters
TData type
ArgsConstructor parameter types
Parameters
argsConstructor parameters
Returns
T* Created object pointer, returns nullptr on failure

Definition at line 415 of file edge.h.

◆ create() [3/4]

device::Buffer* nndeploy::dag::Edge::create ( device::Device device,
const device::BufferDesc desc 
)

Create Buffer on specified device.

Parameters
deviceTarget device
descBuffer description information
Returns
device::Buffer* Created Buffer pointer, returns nullptr on failure

◆ create() [4/4]

device::Tensor* nndeploy::dag::Edge::create ( device::Device device,
const device::TensorDesc desc,
std::string  tensor_name = "" 
)

Create Tensor on specified device.

Parameters
deviceTarget device
descTensor description information
tensor_nameTensor name, optional
Returns
device::Tensor* Created Tensor pointer, returns nullptr on failure

◆ empty()

bool nndeploy::dag::Edge::empty ( )

Check if the Edge is empty.

Returns
bool true indicates no data in the Edge, false indicates data exists

◆ get()

template<typename T >
T* nndeploy::dag::Edge::get ( const Node node)
inline

Get arbitrary type data for specified node (template version)

In pipeline parallel mode, waits for type information to be available before returning data

Template Parameters
TData type
Parameters
nodeNode requesting data
Returns
T* Data pointer, returns nullptr if type mismatch or no data

Definition at line 443 of file edge.h.

◆ getBuffer()

device::Buffer* nndeploy::dag::Edge::getBuffer ( const Node node)

Get Buffer data for specified node.

Parameters
nodeNode requesting data
Returns
device::Buffer* Buffer pointer, returns nullptr if no data

◆ getConsumers()

std::vector<Node *> nndeploy::dag::Edge::getConsumers ( )

Get all consumer nodes.

Returns
std::vector<Node *> List of consumer nodes

◆ getGraphOutput()

template<typename T >
T* nndeploy::dag::Edge::getGraphOutput ( )
inline

Get arbitrary type data for graph output (template version)

In pipeline parallel mode, waits for type information to be available before returning data

Template Parameters
TData type
Returns
T* Data pointer, returns nullptr if type mismatch or no data

Definition at line 465 of file edge.h.

◆ getGraphOutputBuffer()

device::Buffer* nndeploy::dag::Edge::getGraphOutputBuffer ( )

Get Buffer data for graph output.

Returns
device::Buffer* Buffer pointer, returns nullptr if no data

◆ getGraphOutputIndex()

int64_t nndeploy::dag::Edge::getGraphOutputIndex ( )

Get data index for graph output.

Returns
int64_t Data index value

◆ getGraphOutputParam()

base::Param* nndeploy::dag::Edge::getGraphOutputParam ( )

Get Param data for graph output.

Returns
base::Param* Param pointer, returns nullptr if no data

◆ getGraphOutputPosition()

int nndeploy::dag::Edge::getGraphOutputPosition ( )

Get position of graph output in queue.

Returns
int Queue position

◆ getGraphOutputPtr()

void* nndeploy::dag::Edge::getGraphOutputPtr ( )

Get raw pointer for graph output.

Returns
void* Raw data pointer, type conversion is user's responsibility

◆ getGraphOutputTensor()

device::Tensor* nndeploy::dag::Edge::getGraphOutputTensor ( )

Get Tensor data for graph output.

Returns
device::Tensor* Tensor pointer, returns nullptr if no data

◆ getIndex()

int64_t nndeploy::dag::Edge::getIndex ( const Node node)

Get data index for specified node.

Parameters
nodeTarget node
Returns
int64_t Data index value

◆ getName()

std::string nndeploy::dag::Edge::getName ( )

Get the name of the Edge.

Returns
std::string Name string of the Edge

◆ getParallelType()

base::ParallelType nndeploy::dag::Edge::getParallelType ( )

Get the current parallel type.

Returns
base::ParallelType Current parallel processing type

◆ getParam()

base::Param* nndeploy::dag::Edge::getParam ( const Node node)

Get Param data for specified node.

Parameters
nodeNode requesting data
Returns
base::Param* Param pointer, returns nullptr if no data

◆ getPosition()

int nndeploy::dag::Edge::getPosition ( const Node node)

Get position of specified node in queue.

Parameters
nodeTarget node
Returns
int Queue position

◆ getProducers()

std::vector<Node *> nndeploy::dag::Edge::getProducers ( )

Get all producer nodes.

Returns
std::vector<Node *> List of producer nodes

◆ getQueueDropCount()

int nndeploy::dag::Edge::getQueueDropCount ( )

Get the queue drop count.

Returns
int Number of data items dropped each time on overflow

◆ getQueueMaxSize()

int nndeploy::dag::Edge::getQueueMaxSize ( )

Get the maximum queue capacity.

Returns
int Current maximum capacity of the queue, default value is 16

◆ getQueueOverflowPolicy()

base::QueueOverflowPolicy nndeploy::dag::Edge::getQueueOverflowPolicy ( )

Get the current queue overflow policy.

Returns
base::QueueOverflowPolicy Current overflow handling policy

◆ getTensor()

device::Tensor* nndeploy::dag::Edge::getTensor ( const Node node)

Get Tensor data for specified node.

Parameters
nodeNode requesting data
Returns
device::Tensor* Tensor pointer, returns nullptr if no data

◆ getTypeInfo()

std::shared_ptr<EdgeTypeInfo> nndeploy::dag::Edge::getTypeInfo ( )

Get type information of Edge.

Returns
std::shared_ptr<EdgeTypeInfo> Type information object

◆ getTypeName()

std::string nndeploy::dag::Edge::getTypeName ( )

Get type name.

Returns
std::string Type name string

◆ increaseConsumers()

base::Status nndeploy::dag::Edge::increaseConsumers ( std::vector< Node * > &  consumers)

Add consumer nodes.

Parameters
consumersList of consumer nodes
Returns
base::Status Operation status

◆ increaseProducers()

base::Status nndeploy::dag::Edge::increaseProducers ( std::vector< Node * > &  producers)

Add producer nodes.

Parameters
producersList of producer nodes
Returns
base::Status Operation status

◆ markGraphOutput()

bool nndeploy::dag::Edge::markGraphOutput ( )

Mark as graph output Edge.

Returns
bool Whether marking was successful
Note
Must be called after graph initialization is complete

◆ notifyWritten() [1/4]

bool nndeploy::dag::Edge::notifyWritten ( base::Param param)

Notify that Param data has been written.

Parameters
paramWritten Param pointer
Returns
bool Whether notification was successful

◆ notifyWritten() [2/4]

bool nndeploy::dag::Edge::notifyWritten ( device::Buffer buffer)

Notify that Buffer data has been written.

Parameters
bufferWritten Buffer pointer
Returns
bool Whether notification was successful

◆ notifyWritten() [3/4]

bool nndeploy::dag::Edge::notifyWritten ( device::Tensor tensor)

Notify that Tensor data has been written.

Parameters
tensorWritten Tensor pointer
Returns
bool Whether notification was successful

◆ notifyWritten() [4/4]

template<typename T >
bool nndeploy::dag::Edge::notifyWritten ( T *  t)
inline

Notify that arbitrary type data has been written (template version)

Template Parameters
TData type
Parameters
tWritten data pointer
Returns
bool Whether notification was successful

Definition at line 428 of file edge.h.

◆ requestTerminate()

bool nndeploy::dag::Edge::requestTerminate ( )

Request termination of Edge processing.

Returns
bool Whether request was successful

◆ resetIndex()

void nndeploy::dag::Edge::resetIndex ( )

Reset index counter.

◆ set() [1/9]

base::Status nndeploy::dag::Edge::set ( base::Param param)

Set Param reference to Edge.

Parameters
paramParam reference
Returns
base::Status Operation status

◆ set() [2/9]

base::Status nndeploy::dag::Edge::set ( base::Param param,
bool  is_external = true 
)

Set Param data to Edge.

Parameters
paramParam pointer
is_externalWhether it's external data
Returns
base::Status Operation status

◆ set() [3/9]

base::Status nndeploy::dag::Edge::set ( device::Buffer buffer)

Set Buffer reference to Edge.

Parameters
bufferBuffer reference, automatically set as external data
Returns
base::Status Operation status

◆ set() [4/9]

base::Status nndeploy::dag::Edge::set ( device::Buffer buffer,
bool  is_external = true 
)

Set Buffer data to Edge.

Parameters
bufferBuffer pointer
is_externalWhether it's external data, true means not responsible for memory deallocation
Returns
base::Status Operation status

◆ set() [5/9]

base::Status nndeploy::dag::Edge::set ( device::Tensor tensor)

Set Tensor reference to Edge.

Parameters
tensorTensor reference
Returns
base::Status Operation status

◆ set() [6/9]

base::Status nndeploy::dag::Edge::set ( device::Tensor tensor,
bool  is_external = true 
)

Set Tensor data to Edge.

Parameters
tensorTensor pointer
is_externalWhether it's external data
Returns
base::Status Operation status

◆ set() [7/9]

template<typename T >
base::Status nndeploy::dag::Edge::set ( T &  t)
inline

Set arbitrary type data reference to Edge (template version)

Template Parameters
TData type
Parameters
tData reference
Returns
base::Status Operation status

Definition at line 395 of file edge.h.

◆ set() [8/9]

template<typename T >
base::Status nndeploy::dag::Edge::set ( T *  t,
bool  is_external = true 
)
inline

Set arbitrary type data to Edge (template version)

Template Parameters
TData type
Parameters
tData pointer
is_externalWhether it's external data
Returns
base::Status Operation status

Definition at line 382 of file edge.h.

◆ set() [9/9]

template<typename T >
base::Status nndeploy::dag::Edge::set ( T *  t,
std::function< void(T *)>  deleter 
)
inline

Definition at line 401 of file edge.h.

◆ set4py()

template<typename PY_WRAPPER , typename T >
base::Status nndeploy::dag::Edge::set4py ( PY_WRAPPER *  wrapper,
T *  t,
bool  is_external = true 
)
inline

Data setting interface dedicated for Python binding.

Template Parameters
PY_WRAPPERPython wrapper type
TActual data type
Parameters
wrapperPython wrapper pointer
tData pointer
is_externalWhether it's external data
Returns
base::Status Operation status

Definition at line 488 of file edge.h.

◆ setParallelType()

base::Status nndeploy::dag::Edge::setParallelType ( const base::ParallelType paralle_type)

Set the parallel type.

Sets the parallel processing type of the Edge, affecting the creation and management of internal data structures

Parameters
paralle_typeParallel type (serial, pipeline parallel, etc.)
Returns
base::Status Operation status
Note
Must be called before construct(), internally creates corresponding concrete edge implementation

◆ setQueueMaxSize()

base::Status nndeploy::dag::Edge::setQueueMaxSize ( int  queue_max_size)

Set the maximum queue capacity.

Controls the maximum capacity of the edge buffer, used for data buffering in pipeline parallel processing. When the queue is full, the overflow policy determines how to handle new data.

Parameters
queue_max_sizeMaximum capacity of the queue, must be greater than 0, default is 16
Returns
base::Status Returns kSuccess on success, kInvalidParam for invalid parameters
Note
Must be set before calling construct(), otherwise returns kUninitialized

◆ setQueueOverflowPolicy()

base::Status nndeploy::dag::Edge::setQueueOverflowPolicy ( base::QueueOverflowPolicy  policy,
int  drop_count = 1 
)

Set the queue overflow policy.

Processing strategy when the queue is full, supports different strategies like backpressure, dropping, etc.

Parameters
policyOverflow handling policy
drop_countNumber of data items to drop each time when policy is drop, default is 1
Returns
base::Status Operation status

◆ setTypeInfo() [1/2]

template<typename T >
base::Status nndeploy::dag::Edge::setTypeInfo ( )
inline

Set type information of Edge (template version)

Template Parameters
TData type
Returns
base::Status Operation status

Definition at line 588 of file edge.h.

◆ setTypeInfo() [2/2]

base::Status nndeploy::dag::Edge::setTypeInfo ( std::shared_ptr< EdgeTypeInfo type_info)

Set type information of Edge.

Parameters
type_infoType information object
Returns
base::Status Operation status

◆ setTypeName()

void nndeploy::dag::Edge::setTypeName ( const std::string &  type_name)

Set type name.

Parameters
type_nameType name string

◆ update()

base::EdgeUpdateFlag nndeploy::dag::Edge::update ( const Node node)

Update Edge status for specified node.

Parameters
nodeTarget node
Returns
base::EdgeUpdateFlag Update flag

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