2 #ifndef _NNDEPLOY_DAG_EDGE_H_
3 #define _NNDEPLOY_DAG_EDGE_H_
14 #include "nndeploy/dag/edge/abstract_edge.h"
49 Edge(
const std::string &name);
206 #ifdef ENABLE_NNDEPLOY_OPENCV
214 base::Status set(cv::Mat *cv_mat,
bool is_external =
true);
233 cv::Mat *create(
int rows,
int cols,
int type,
const cv::Vec3b &value);
241 bool notifyWritten(cv::Mat *cv_mat);
249 cv::Mat *getCvMat(
const Node *node);
256 cv::Mat *getGraphOutputCvMat();
285 std::string tensor_name =
"");
335 template <
typename T,
typename... Args,
336 typename std::enable_if<std::is_base_of<base::Param, T>::value,
339 this->setTypeInfo<T>();
340 return abstact_edge_->create<T>(std::forward<Args>(args)...);
381 template <
typename T>
383 this->setTypeInfo<T>();
384 return abstact_edge_->set<T>(t, is_external);
394 template <
typename T>
396 this->setTypeInfo<T>();
397 return this->set(&t,
true);
400 template <
typename T>
402 this->setTypeInfo<T>();
403 return abstact_edge_->set<T>(t, deleter);
414 template <
typename T,
typename... Args>
416 this->setTypeInfo<T>();
417 return abstact_edge_->create<T>(std::forward<Args>(args)...);
427 template <
typename T>
429 return abstact_edge_->notifyWritten<T>(t);
442 template <
typename T>
445 std::unique_lock<std::mutex> lock(type_info_mutex_);
446 type_info_cv_.wait(lock, [
this]() {
return type_info_ !=
nullptr; });
448 if (type_info_ !=
nullptr && !type_info_->isType<T>()) {
452 return abstact_edge_->get<T>(node);
464 template <
typename T>
467 std::unique_lock<std::mutex> lock(type_info_mutex_);
468 type_info_cv_.wait(lock, [
this]() {
return type_info_ !=
nullptr; });
470 if (type_info_ !=
nullptr && !type_info_->isType<T>()) {
474 return abstact_edge_->getGraphOutput<T>();
487 template <
typename PY_WRAPPER,
typename T>
489 this->setTypeInfo<T>();
490 return abstact_edge_->set4py<PY_WRAPPER, T>(wrapper, t, is_external);
587 template <
typename T>
589 if (type_info_ ==
nullptr) {
590 type_info_ = std::make_shared<EdgeTypeInfo>();
591 type_info_->setType<T>();
593 type_info_->setType<T>();
596 type_info_cv_.notify_all();
636 template <
typename T>
640 return *type_info_ == other_type_info;
653 AbstractEdge *abstact_edge_ =
655 std::mutex type_info_mutex_;
656 std::condition_variable
658 std::shared_ptr<EdgeTypeInfo> type_info_;
659 int queue_max_size_ = 16;
663 int queue_drop_count_ =
Edge class in DAG graph for connecting nodes and transferring data.
base::Status set(device::Buffer *buffer, bool is_external=true)
Set Buffer data to Edge.
int64_t getGraphOutputIndex()
Get data index for graph output.
base::Param * create(Args &&...args)
Create Param object of specified type.
T * create(Args &&...args)
Create arbitrary type data object (template version)
void setTypeName(const std::string &type_name)
Set type name.
virtual ~Edge()
Virtual destructor.
bool notifyWritten(base::Param *param)
Notify that Param data has been written.
base::Status construct()
Construct the Edge instance.
device::Buffer * create(device::Device *device, const device::BufferDesc &desc)
Create Buffer on specified device.
base::QueueOverflowPolicy getQueueOverflowPolicy()
Get the current queue overflow policy.
base::Status set(device::Tensor &tensor)
Set Tensor reference to Edge.
bool notifyWritten(device::Tensor *tensor)
Notify that Tensor data has been written.
bool checkTypeInfo()
Check if type information matches (template version)
bool markGraphOutput()
Mark as graph output Edge.
device::Buffer * getBuffer(const Node *node)
Get Buffer data for specified node.
std::string getTypeName()
Get type name.
device::Tensor * getGraphOutputTensor()
Get Tensor data for graph output.
base::Status setQueueMaxSize(int queue_max_size)
Set the maximum queue capacity.
bool notifyWritten(T *t)
Notify that arbitrary type data has been written (template version)
base::Status set(base::Param ¶m)
Set Param reference to Edge.
void * getGraphOutputPtr()
Get raw pointer for graph output.
bool requestTerminate()
Request termination of Edge processing.
void resetIndex()
Reset index counter.
T * get(const Node *node)
Get arbitrary type data for specified node (template version)
T * getGraphOutput()
Get arbitrary type data for graph output (template version)
device::Tensor * getTensor(const Node *node)
Get Tensor data for specified node.
base::Status set(base::Param *param, bool is_external=true)
Set Param data to Edge.
base::Status increaseConsumers(std::vector< Node * > &consumers)
Add consumer nodes.
base::Param * getParam(const Node *node)
Get Param data for specified node.
base::ParallelType getParallelType()
Get the current parallel type.
std::string getName()
Get the name of the Edge.
std::vector< Node * > getConsumers()
Get all consumer nodes.
base::Status set(device::Tensor *tensor, bool is_external=true)
Set Tensor data to Edge.
Edge(const std::string &name)
Constructor with name.
std::vector< Node * > getProducers()
Get all producer nodes.
base::Status setTypeInfo(std::shared_ptr< EdgeTypeInfo > type_info)
Set type information of Edge.
int64_t getIndex(const Node *node)
Get data index for specified node.
base::Status setParallelType(const base::ParallelType ¶lle_type)
Set the parallel type.
bool notifyWritten(device::Buffer *buffer)
Notify that Buffer data has been written.
int getGraphOutputPosition()
Get position of graph output in queue.
bool checkTypeInfo(std::shared_ptr< EdgeTypeInfo > type_info)
Check if type information matches.
base::Status set4py(PY_WRAPPER *wrapper, T *t, bool is_external=true)
Data setting interface dedicated for Python binding.
base::Status set(T *t, bool is_external=true)
Set arbitrary type data to Edge (template version)
base::Status setTypeInfo()
Set type information of Edge (template version)
base::Status increaseProducers(std::vector< Node * > &producers)
Add producer nodes.
device::Buffer * getGraphOutputBuffer()
Get Buffer data for graph output.
int getQueueDropCount()
Get the queue drop count.
std::shared_ptr< EdgeTypeInfo > getTypeInfo()
Get type information of Edge.
device::Tensor * create(device::Device *device, const device::TensorDesc &desc, std::string tensor_name="")
Create Tensor on specified device.
base::Status set(T &t)
Set arbitrary type data reference to Edge (template version)
int getPosition(const Node *node)
Get position of specified node in queue.
Edge()
Default constructor.
base::Status set(device::Buffer &buffer)
Set Buffer reference to Edge.
base::Status setQueueOverflowPolicy(base::QueueOverflowPolicy policy, int drop_count=1)
Set the queue overflow policy.
base::EdgeUpdateFlag update(const Node *node)
Update Edge status for specified node.
base::Param * getGraphOutputParam()
Get Param data for graph output.
base::Status set(T *t, std::function< void(T *)> deleter)
bool empty()
Check if the Edge is empty.
int getQueueMaxSize()
Get the maximum queue capacity.
#define NNDEPLOY_CC_API
api
@ kQueueOverflowPolicyNodeBackpressure