nndeploy C++ API  0.2.0
nndeploy C++ API
node.h
Go to the documentation of this file.
1 
2 #ifndef _NNDEPLOY_DAG_NODE_H_
3 #define _NNDEPLOY_DAG_NODE_H_
4 
5 #include "nndeploy/base/any.h"
6 #include "nndeploy/base/common.h"
8 #include "nndeploy/base/log.h"
9 #include "nndeploy/base/macro.h"
10 #include "nndeploy/base/object.h"
11 #include "nndeploy/base/status.h"
12 #include "nndeploy/base/string.h"
14 #include "nndeploy/dag/base.h"
15 #include "nndeploy/dag/edge.h"
16 #include "nndeploy/device/buffer.h"
17 #include "nndeploy/device/device.h"
19 #include "nndeploy/device/tensor.h"
20 #include "rapidjson/document.h"
21 #include "rapidjson/stringbuffer.h"
22 #include "rapidjson/writer.h"
23 
24 namespace nndeploy {
25 namespace dag {
26 
27 class Node;
28 class Graph;
29 class CompositeNode;
30 
36  public:
37  NodeDesc() = default;
38 
45  NodeDesc(const std::string &node_name,
46  std::initializer_list<std::string> inputs,
47  std::initializer_list<std::string> outputs)
48  : node_name_(node_name), inputs_(inputs), outputs_(outputs) {}
49 
56  NodeDesc(const std::string &node_name, std::vector<std::string> inputs,
57  std::vector<std::string> outputs)
58  : node_name_(node_name), inputs_(inputs), outputs_(outputs) {}
59 
67  NodeDesc(const std::string &node_key, const std::string &node_name,
68  std::initializer_list<std::string> inputs,
69  std::initializer_list<std::string> outputs)
70  : node_key_(node_key),
71  node_name_(node_name),
72  inputs_(inputs),
73  outputs_(outputs) {}
74 
82  NodeDesc(const std::string &node_key, const std::string &node_name,
83  std::vector<std::string> inputs, std::vector<std::string> outputs)
84  : node_key_(node_key),
85  node_name_(node_name),
86  inputs_(inputs),
87  outputs_(outputs) {}
88 
89  virtual ~NodeDesc() = default;
90 
95  std::string getKey() const { return node_key_; }
96 
101  std::string getName() const { return node_name_; }
102 
107  std::vector<std::string> getInputs() const { return inputs_; }
108 
113  std::vector<std::string> getOutputs() const { return outputs_; }
114 
115  // JSON serialization related methods
122  base::Status serialize(rapidjson::Value &json,
123  rapidjson::Document::AllocatorType &allocator);
124 
129  std::string serialize();
130 
136  base::Status saveFile(const std::string &path);
137 
143  base::Status deserialize(rapidjson::Value &json);
144 
150  base::Status deserialize(const std::string &json_str);
151 
157  base::Status loadFile(const std::string &path);
158 
159  private:
160  std::string node_key_;
161  std::string node_name_;
162  std::vector<std::string> inputs_;
163  std::vector<std::string> outputs_;
164 };
165 
172  public:
177  Node(const std::string &name);
178 
185  Node(const std::string &name, std::vector<Edge *> inputs,
186  std::vector<Edge *> outputs);
187 
188  virtual ~Node();
189 
190  // Basic property setting and getting methods
195  void setKey(const std::string &key);
196 
201  std::string getKey();
202 
207  void setName(const std::string &name);
208 
213  std::string getName();
214 
219  void setDeveloper(const std::string &developer);
220 
225  std::string getDeveloper();
226 
231  void setSource(const std::string &source);
232 
237  std::string getSource();
238 
243  void setDesc(const std::string &desc);
244 
249  std::string getDesc();
250 
251  // Dynamic input/output settings
256  void setDynamicInput(bool is_dynamic_input);
257 
262  void setDynamicOutput(bool is_dynamic_output);
263 
269 
275 
276  // Input/output name management
281  std::vector<std::string> getInputNames();
282 
287  std::vector<std::string> getOutputNames();
288 
294  std::string getInputName(int index = 0);
295 
301  std::string getOutputName(int index = 0);
302 
308  int getInputIndex(const std::string &name);
309 
315  int getOutputIndex(const std::string &name);
316 
322 
328 
335  virtual base::Status setInputName(const std::string &name, int index = 0);
336 
343  virtual base::Status setOutputName(const std::string &name, int index = 0);
344 
350  virtual base::Status setInputNames(const std::vector<std::string> &names);
351 
357  virtual base::Status setOutputNames(const std::vector<std::string> &names);
358 
359  // Graph and composite node management
366 
372 
379 
385 
386  // Device type management
393 
399 
400  // Parameter management
407 
413  virtual base::Status setParamSharedPtr(std::shared_ptr<base::Param> param);
414 
419  virtual base::Param *getParam();
420 
425  virtual std::shared_ptr<base::Param> getParamSharedPtr();
426 
434  const std::string &key, std::shared_ptr<base::Param> external_param);
435 
441  virtual std::shared_ptr<base::Param> getExternalParam(const std::string &key);
442 
449  virtual base::Status setParam(const std::string &key, base::Any &any);
450 
457  virtual base::Status getParam(const std::string &key, base::Any &any);
458 
465  virtual base::Status setParam(const std::string &key,
466  const std::string &value);
467 
468  // Stateless resource management
475  virtual base::Status addResourceWithoutState(const std::string &key,
476  const base::Any &value);
477 
483  virtual base::Any &getResourceWithoutState(const std::string &key);
484 
491  template <typename T>
492  T getResourceWithoutState(const std::string &key) {
493  base::Any &any = this->getResourceWithoutState(key);
494  if (any.empty()) {
495  // NNDEPLOY_LOGI("any is empty in getResourceWithoutState, key: %s.\n", key.c_str());
496  return T();
497  }
498  return base::get<T>(any);
499  }
500 
501  // Stateful resource management
507  virtual Edge *createResourceWithState(const std::string &key);
508 
515  virtual base::Status addResourceWithState(const std::string &key, Edge *edge);
516 
522  virtual Edge* getResourceWithState(const std::string &key);
523 
532  template <typename T>
533  base::Status setResourceWithState(const std::string &key, T *value, bool is_external = true) {
534  Edge* edge = this->getResourceWithState(key);
535  if (edge == nullptr) {
536  NNDEPLOY_LOGE("edge is nullptr in setResourceWithState, key: %s.\n", key.c_str());
538  }
539  edge->set<T>(value, is_external);
540  return base::kStatusCodeOk;
541  }
542 
549  template <typename T>
550  T *getResourceWithState(const std::string &key) {
551  Edge* edge = this->getResourceWithState(key);
552  if (edge == nullptr) {
553  NNDEPLOY_LOGE("edge is nullptr in getResourceWithState, key: %s.\n", key.c_str());
554  return nullptr;
555  }
556  return edge->get<T>(this);
557  }
558 
559  // Version management
565  base::Status setVersion(const std::string &version);
566 
571  std::string getVersion();
572 
573  // Required parameter management
580  const std::vector<std::string> &required_params);
581 
587  base::Status addRequiredParam(const std::string &required_param);
588 
594  base::Status removeRequiredParam(const std::string &required_param);
595 
601 
606  std::vector<std::string> getRequiredParams();
607 
608  // UI parameter management
614  base::Status setUiParams(const std::vector<std::string> &ui_params);
615 
621  base::Status addUiParam(const std::string &ui_param);
622 
628  base::Status removeUiParam(const std::string &ui_param);
629 
635 
640  std::vector<std::string> getUiParams();
641 
642  // IO parameter management
648  base::Status setIoParams(const std::vector<std::string> &io_params);
649 
655  base::Status addIoParam(const std::string &io_param);
656 
662  base::Status removeIoParam(const std::string &io_param);
663 
669 
674  std::vector<std::string> getIoParams();
675 
676  // Dropdown parameter management
683  const std::map<std::string, std::vector<std::string>> &dropdown_params);
684 
692  const std::string &dropdown_param,
693  const std::vector<std::string> &dropdown_values);
694 
700  base::Status removeDropdownParam(const std::string &dropdown_param);
701 
707 
712  std::map<std::string, std::vector<std::string>> getDropdownParams();
713 
714  // Input/output edge setting
721  virtual base::Status setInput(Edge *input, int index = -1);
722 
729  virtual base::Status setOutput(Edge *output, int index = -1);
730 
737  virtual base::Status setIterInput(Edge *input, int index = -1);
738 
744  virtual base::Status setInputs(std::vector<Edge *> inputs);
745 
751  virtual base::Status setOutputs(std::vector<Edge *> outputs);
752 
759  virtual base::Status setInputSharedPtr(std::shared_ptr<Edge> input,
760  int index = -1);
761 
768  virtual base::Status setOutputSharedPtr(std::shared_ptr<Edge> output,
769  int index = -1);
770 
777  std::vector<std::shared_ptr<Edge>> inputs);
778 
785  std::vector<std::shared_ptr<Edge>> outputs);
786 
787  // Input/output edge getting
793  Edge *getInput(int index = 0);
794 
800  Edge *getOutput(int index = 0);
801 
808  template <typename T>
809  T *getInputData(int index = 0) {
810  Edge *edge = getInput(index);
811  if (edge == nullptr) {
812  return nullptr;
813  }
814  return edge->get<T>(this);
815  }
816 
825  template <typename T>
826  base::Status setOutputData(T *obj, int index = 0, bool is_external = true) {
827  Edge *edge = getOutput(index);
828  if (edge == nullptr) {
830  }
831  return edge->set<T>(obj, is_external);
832  }
833 
838  std::vector<Edge *> getAllInput();
839 
844  std::vector<Edge *> getAllOutput();
845 
851  virtual Edge *createInternalOutputEdge(const std::string &name);
852 
858 
859  // Parallel type management
865  virtual base::Status setParallelType(const base::ParallelType &paralle_type);
866 
872 
873  // Flag management
878  void setInnerFlag(bool flag);
879 
884  void setInitializedFlag(bool flag);
885 
891 
896  void setTimeProfileFlag(bool flag);
897 
903 
908  void setDebugFlag(bool flag);
909 
914  bool getDebugFlag();
915 
916  // Running state management
921  void setRunningFlag(bool flag);
922 
927  bool isRunning();
928 
933  size_t getRunSize();
934 
940 
945  virtual std::shared_ptr<RunStatus> getRunStatus();
946 
951  virtual void setTraceFlag(bool flag);
952 
957  bool getTraceFlag();
958 
963  void setGraphFlag(bool flag);
964 
969  bool getGraphFlag();
970 
971  // Node type management
976  void setNodeType(NodeType node_type);
977 
983 
988  void setIoType(IOType io_type);
989 
995 
996  // Loop control
1001  virtual void setLoopCount(int loop_count);
1002 
1007  virtual int getLoopCount();
1008 
1009  // Stream management
1014  void setStream(device::Stream *stream);
1015 
1021 
1022  // Type information management
1029  template <typename T>
1030  base::Status setInputTypeInfo(std::string desc = "") {
1031  std::shared_ptr<EdgeTypeInfo> edge_type_info =
1032  std::make_shared<EdgeTypeInfo>();
1033  edge_type_info->setType<T>();
1034  edge_type_info->setEdgeName(desc);
1035  input_type_info_.push_back(edge_type_info);
1036  return base::Status::Ok();
1037  }
1038 
1045  base::Status setInputTypeInfo(std::shared_ptr<EdgeTypeInfo> input_type_info,
1046  std::string desc = "");
1047 
1052  std::vector<std::shared_ptr<EdgeTypeInfo>> getInputTypeInfo();
1053 
1060  template <typename T>
1061  base::Status setOutputTypeInfo(std::string desc = "") {
1062  std::shared_ptr<EdgeTypeInfo> edge_type_info =
1063  std::make_shared<EdgeTypeInfo>();
1064  edge_type_info->setType<T>();
1065  edge_type_info->setEdgeName(desc);
1066  output_type_info_.push_back(edge_type_info);
1067  return base::Status::Ok();
1068  }
1069 
1076  base::Status setOutputTypeInfo(std::shared_ptr<EdgeTypeInfo> output_type_info,
1077  std::string desc = "");
1078 
1083  std::vector<std::shared_ptr<EdgeTypeInfo>> getOutputTypeInfo();
1084 
1085  // Lifecycle management
1091 
1096  virtual base::Status init();
1097 
1103 
1104  // Memory management
1109  virtual int64_t getMemorySize();
1110 
1117 
1123 
1124  // Core execution methods
1129  virtual base::Status run() = 0;
1130 
1135  virtual bool synchronize();
1136 
1137  // Interrupt control
1142  virtual bool interrupt();
1143 
1148  virtual bool checkInterruptStatus();
1149 
1153  virtual void clearInterrupt();
1154 
1155  // Forward propagation interfaces
1165  virtual std::vector<Edge *> forward(std::vector<Edge *> inputs);
1166 
1172  virtual std::vector<Edge *> operator()(std::vector<Edge *> inputs);
1173 
1178  virtual std::vector<Edge *> forward();
1179 
1184  virtual std::vector<Edge *> operator()();
1185 
1191  virtual std::vector<Edge *> forward(Edge *input);
1192 
1198  virtual std::vector<Edge *> operator()(Edge *input);
1199 
1200  // Validation methods
1206  bool checkInputs(std::vector<Edge *> &inputs);
1207 
1213  bool checkOutputs(std::vector<std::string> &outputs_name);
1214 
1220  bool checkOutputs(std::vector<Edge *> &outputs);
1221 
1227  bool isInputsChanged(std::vector<Edge *> inputs);
1228 
1234 
1239  virtual std::vector<std::string> getRealOutputsName();
1240 
1241  // JSON serialization related methods
1248  virtual base::Status serialize(rapidjson::Value &json,
1249  rapidjson::Document::AllocatorType &allocator);
1250 
1255  virtual std::string serialize();
1256 
1262  virtual base::Status saveFile(const std::string &path);
1263 
1269  virtual base::Status deserialize(rapidjson::Value &json);
1270 
1276  virtual base::Status deserialize(const std::string &json_str);
1277 
1283  virtual base::Status loadFile(const std::string &path);
1284 
1285  protected:
1290  std::string key_;
1291  std::string name_;
1292  std::string developer_;
1293  std::string source_;
1294  std::string desc_;
1296 
1301  bool is_external_stream_ = false;
1302  device::Stream *stream_ = nullptr;
1303 
1304  std::shared_ptr<base::Param> param_;
1305  std::map<std::string, std::shared_ptr<base::Param>> external_param_;
1306 
1312  bool is_dynamic_input_ = false;
1313  bool is_dynamic_output_ = false;
1314 
1315  std::vector<std::shared_ptr<EdgeTypeInfo>> input_type_info_;
1316  std::vector<std::shared_ptr<EdgeTypeInfo>> output_type_info_;
1317  std::vector<Edge *> inputs_;
1318  std::vector<Edge *> outputs_;
1319  std::map<std::string, Edge *> internal_outputs_;
1320 
1321  Graph *graph_ = nullptr;
1322  CompositeNode *composite_node_ = nullptr;
1323 
1324  protected:
1325  bool constructed_ = false;
1326  bool is_inner_ = false;
1327  bool parallel_type_set_ = false;
1329  bool initialized_ = false;
1330  bool is_running_ = false;
1331  size_t run_size_ = 0;
1332  size_t completed_size_ = 0;
1333  bool is_time_profile_ = false;
1334  bool is_debug_ = false;
1335  bool is_trace_ = false;
1336  bool traced_ = false;
1337  bool is_graph_ = false;
1338  bool is_loop_ = false;
1339  bool is_condition_ = false;
1340  bool is_composite_node_ = false;
1341 
1344 
1345  int loop_count_ = -1;
1346  std::atomic<bool> stop_{false};
1347 
1348  std::string version_ = "1.0.0";
1349  std::vector<std::string> required_params_;
1350  std::vector<std::string> ui_params_;
1351  std::vector<std::string> io_params_;
1352  std::map<std::string, std::vector<std::string>> dropdown_params_;
1353 };
1354 
1360  public:
1368  virtual Node *createNode(const std::string &node_name,
1369  std::vector<Edge *> inputs,
1370  std::vector<Edge *> outputs) = 0;
1371 
1379  virtual std::shared_ptr<Node> createNodeSharedPtr(
1380  const std::string &node_name, std::vector<Edge *> inputs,
1381  std::vector<Edge *> outputs) = 0;
1382 
1383  virtual ~NodeCreator() = default;
1384 };
1385 
1391 template <typename T>
1393  public:
1401  virtual Node *createNode(const std::string &node_name,
1402  std::vector<Edge *> inputs,
1403  std::vector<Edge *> outputs) override {
1404  return new T(node_name, inputs, outputs);
1405  }
1406 
1414  virtual std::shared_ptr<Node> createNodeSharedPtr(
1415  const std::string &node_name, std::vector<Edge *> inputs,
1416  std::vector<Edge *> outputs) override {
1417  return std::make_shared<T>(node_name, inputs, outputs);
1418  }
1419 };
1420 
1426  public:
1432  static NodeFactory instance;
1433  return &instance;
1434  }
1435 
1441  void registerNode(const std::string &node_key,
1442  std::shared_ptr<NodeCreator> creator) {
1443  auto it = creators_.find(node_key);
1444  // NNDEPLOY_LOGI("register node: %s\n", node_key.c_str());
1445  if (it != creators_.end()) {
1446  // NNDEPLOY_LOGE("Node name %s already exists!\n", node_key.c_str());
1447  // return;
1448  NNDEPLOY_LOGW("Node name %s already exists, will be overwritten!\n",
1449  node_key.c_str());
1450  }
1451  creators_[node_key] = creator;
1452  // NNDEPLOY_LOGI("register node success: %s\n", node_key.c_str());
1453  }
1454 
1460  std::shared_ptr<NodeCreator> getCreator(const std::string &node_key) {
1461  // for (auto &it : creators_) {
1462  // NNDEPLOY_LOGI("node key: %s\n", it.first.c_str());
1463  // }
1464  auto it = creators_.find(node_key);
1465  if (it != creators_.end()) {
1466  return it->second;
1467  }
1468  return nullptr;
1469  }
1470 
1475  std::set<std::string> getNodeKeys() {
1476  std::set<std::string> keys;
1477  for (auto &it : creators_) {
1478  keys.insert(it.first);
1479  }
1480  return keys;
1481  }
1482 
1483  private:
1484  NodeFactory() = default;
1485  ~NodeFactory() = default;
1486  std::map<std::string, std::shared_ptr<NodeCreator>> creators_;
1487 };
1488 
1494 
1501 #define REGISTER_NODE(node_key, node_class) \
1502  namespace { \
1503  struct NodeRegister_##node_class { \
1504  NodeRegister_##node_class() { \
1505  nndeploy::dag::getGlobalNodeFactory()->registerNode( \
1506  node_key, \
1507  std::make_shared<nndeploy::dag::TypeNodeCreator<node_class>>()); \
1508  } \
1509  }; \
1510  static NodeRegister_##node_class g_node_register_##node_class; \
1511  }
1512 
1517 extern NNDEPLOY_CC_API std::set<std::string> getNodeKeys();
1518 
1519 // Node creation functions
1526 NNDEPLOY_CC_API Node *createNode(const std::string &node_key,
1527  const std::string &node_name);
1528 
1537 NNDEPLOY_CC_API Node *createNode(const std::string &node_key,
1538  const std::string &node_name,
1539  std::initializer_list<Edge *> inputs,
1540  std::initializer_list<Edge *> outputs);
1541 
1550 NNDEPLOY_CC_API Node *createNode(const std::string &node_key,
1551  const std::string &node_name,
1552  std::vector<Edge *> inputs,
1553  std::vector<Edge *> outputs);
1554 
1561 NNDEPLOY_CC_API std::shared_ptr<Node> createNodeSharedPtr(
1562  const std::string &node_key, const std::string &node_name);
1563 
1572 NNDEPLOY_CC_API std::shared_ptr<Node> createNodeSharedPtr(
1573  const std::string &node_key, const std::string &node_name,
1574  std::initializer_list<Edge *> inputs,
1575  std::initializer_list<Edge *> outputs);
1576 
1585 NNDEPLOY_CC_API std::shared_ptr<Node> createNodeSharedPtr(
1586  const std::string &node_key, const std::string &node_name,
1587  std::vector<Edge *> inputs, std::vector<Edge *> outputs);
1588 
1593 using NodeFunc = std::function<base::Status(std::vector<Edge *> inputs,
1594  std::vector<Edge *> outputs,
1595  base::Param *param)>;
1596 
1597 } // namespace dag
1598 } // namespace nndeploy
1599 
1600 #endif
static Status Ok()
Composite node Composite node is a special type of node in nndeploy that enhances the capabilities of...
Edge class in DAG graph for connecting nodes and transferring data.
Definition: edge.h:35
base::Status set(device::Buffer *buffer, bool is_external=true)
Set Buffer data to Edge.
T * get(const Node *node)
Get arbitrary type data for specified node (template version)
Definition: edge.h:443
Directed Acyclic Graph Node.
Definition: graph.h:31
Node creator base class.
Definition: node.h:1359
virtual std::shared_ptr< Node > createNodeSharedPtr(const std::string &node_name, std::vector< Edge * > inputs, std::vector< Edge * > outputs)=0
Create node (shared pointer)
virtual ~NodeCreator()=default
virtual Node * createNode(const std::string &node_name, std::vector< Edge * > inputs, std::vector< Edge * > outputs)=0
Create node.
Node description class.
Definition: node.h:35
base::Status saveFile(const std::string &path)
Save to file.
NodeDesc(const std::string &node_key, const std::string &node_name, std::initializer_list< std::string > inputs, std::initializer_list< std::string > outputs)
Constructor.
Definition: node.h:67
std::string getKey() const
Get node key.
Definition: node.h:95
std::vector< std::string > getInputs() const
Get input edge name list.
Definition: node.h:107
std::string serialize()
Serialize to JSON string.
base::Status deserialize(rapidjson::Value &json)
Deserialize from JSON.
std::string getName() const
Get node name.
Definition: node.h:101
base::Status deserialize(const std::string &json_str)
Deserialize from JSON string.
virtual ~NodeDesc()=default
base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
Serialize to JSON.
base::Status loadFile(const std::string &path)
Load from file.
std::vector< std::string > getOutputs() const
Get output edge name list.
Definition: node.h:113
NodeDesc(const std::string &node_name, std::vector< std::string > inputs, std::vector< std::string > outputs)
Constructor.
Definition: node.h:56
NodeDesc(const std::string &node_name, std::initializer_list< std::string > inputs, std::initializer_list< std::string > outputs)
Constructor.
Definition: node.h:45
NodeDesc(const std::string &node_key, const std::string &node_name, std::vector< std::string > inputs, std::vector< std::string > outputs)
Constructor.
Definition: node.h:82
Node factory class.
Definition: node.h:1425
std::shared_ptr< NodeCreator > getCreator(const std::string &node_key)
Get node creator.
Definition: node.h:1460
std::set< std::string > getNodeKeys()
Get all node keys.
Definition: node.h:1475
void registerNode(const std::string &node_key, std::shared_ptr< NodeCreator > creator)
Register node.
Definition: node.h:1441
static NodeFactory * getInstance()
Get singleton instance.
Definition: node.h:1431
Node base class.
Definition: node.h:171
virtual base::Status setOutput(Edge *output, int index=-1)
Set output edge.
bool checkOutputs(std::vector< std::string > &outputs_name)
Check output edge names.
Node(const std::string &name, std::vector< Edge * > inputs, std::vector< Edge * > outputs)
Constructor.
std::string getInputName(int index=0)
Get input edge name at specified index.
base::Status clearUiParams()
Clear UI parameters.
bool isInputsChanged(std::vector< Edge * > inputs)
Check if inputs changed.
base::Status addUiParam(const std::string &ui_param)
Add UI parameter.
virtual std::shared_ptr< RunStatus > getRunStatus()
Get run status.
void setDynamicInput(bool is_dynamic_input)
Set whether it's dynamic input.
base::Status setOutputTypeInfo(std::string desc="")
Set output type information (template method)
Definition: node.h:1061
base::Status setGraph(Graph *graph)
Set parent graph.
void setKey(const std::string &key)
Set node key.
virtual Edge * createInternalOutputEdge(const std::string &name)
Create internal output edge.
int getOutputCount()
Get output edge count.
virtual base::Status setParam(base::Param *param)
Set parameter.
std::map< std::string, std::vector< std::string > > dropdown_params_
Dropdown parameter mapping.
Definition: node.h:1352
virtual base::ParallelType getParallelType()
Get parallel type.
std::map< std::string, std::shared_ptr< base::Param > > external_param_
External parameter mapping.
Definition: node.h:1305
std::string getKey()
Get node key.
std::string name_
Node name.
Definition: node.h:1291
std::vector< std::shared_ptr< EdgeTypeInfo > > input_type_info_
Input type information.
Definition: node.h:1315
void setStream(device::Stream *stream)
Set compute stream.
bool getTimeProfileFlag()
Get time profile flag.
virtual base::Status setInputName(const std::string &name, int index=0)
Set input edge name.
std::string developer_
Developer information.
Definition: node.h:1292
void setDesc(const std::string &desc)
Set node description.
std::string getSource()
Get source information.
virtual base::Status setExternalParam(const std::string &key, std::shared_ptr< base::Param > external_param)
Set external parameter.
bool checkOutputs(std::vector< Edge * > &outputs)
Check output edges.
std::string desc_
Node description.
Definition: node.h:1294
std::string getOutputName(int index=0)
Get output edge name at specified index.
void setSource(const std::string &source)
Set source information.
std::string getDesc()
Get node description.
std::vector< std::string > getIoParams()
Get IO parameter list.
base::Status setResourceWithState(const std::string &key, T *value, bool is_external=true)
Set stateful resource (template method)
Definition: node.h:533
virtual std::vector< Edge * > operator()(Edge *input)
Single input invocation operator overload.
virtual base::Status saveFile(const std::string &path)
Save to file.
void setGraphFlag(bool flag)
Set graph flag.
T * getResourceWithState(const std::string &key)
Get stateful resource (template method)
Definition: node.h:550
virtual base::Status getParam(const std::string &key, base::Any &any)
Get parameter (Any type)
virtual base::Status setOutputName(const std::string &name, int index=0)
Set output edge name.
int getInputCount()
Get input edge count.
void setDynamicOutput(bool is_dynamic_output)
Set whether it's dynamic output.
bool isDynamicOutput()
Check if it's dynamic output.
virtual std::vector< Edge * > forward(std::vector< Edge * > inputs)
Node invocation interface.
std::string source_
Source information.
Definition: node.h:1293
std::vector< Edge * > getAllOutput()
Get all output edges.
virtual std::vector< Edge * > operator()(std::vector< Edge * > inputs)
Node invocation operator overload.
virtual int getLoopCount()
Get loop count.
std::vector< std::string > required_params_
Required parameter list.
Definition: node.h:1349
std::vector< std::shared_ptr< EdgeTypeInfo > > getInputTypeInfo()
Get input type information.
virtual std::string serialize()
Serialize to JSON string.
base::Status removeRequiredParam(const std::string &required_param)
Remove required parameter.
Graph * getGraph()
Get parent graph.
virtual void setLoopCount(int loop_count)
Set loop count.
virtual std::vector< std::string > getRealOutputsName()
Get real output names.
virtual std::vector< Edge * > operator()()
Parameter-free invocation operator overload.
virtual bool synchronize()
Synchronize execution.
virtual base::Status toStaticGraph()
Convert to static graph.
bool getConstructed()
Get whether it's constructed.
size_t getRunSize()
Get run count.
virtual base::Status addResourceWithState(const std::string &key, Edge *edge)
Add stateful resource.
virtual base::Status setParamSharedPtr(std::shared_ptr< base::Param > param)
Set parameter (shared pointer)
void setTimeProfileFlag(bool flag)
Set time profile flag.
virtual std::vector< Edge * > forward()
Parameter-free forward propagation.
bool getDebugFlag()
Get debug flag.
NodeType getNodeType()
Get node type.
size_t getCompletedSize()
Get completed count.
std::string getDeveloper()
Get developer information.
device::Stream * getStream()
Get compute stream.
virtual base::DeviceType getDeviceType()
Get device type.
base::Status clearRequiredParams()
Clear required parameters.
virtual bool interrupt()
Interrupt execution.
T * getInputData(int index=0)
Get input data (template method)
Definition: node.h:809
void setDeveloper(const std::string &developer)
Set developer information.
base::Status clearDropdownParams()
Clear dropdown parameters.
virtual base::Status setOutputNames(const std::vector< std::string > &names)
Set all output edge names.
void setName(const std::string &name)
Set node name.
virtual base::Status run()=0
Run node (pure virtual function)
virtual bool checkInterruptStatus()
Check interrupt status.
std::vector< std::string > getUiParams()
Get UI parameter list.
std::vector< std::string > getInputNames()
Get all input edge names.
virtual base::Param * getParam()
Get parameter.
std::vector< std::string > io_params_
IO parameter list.
Definition: node.h:1351
base::Status setUiParams(const std::vector< std::string > &ui_params)
Set UI parameter list.
base::Status setRequiredParams(const std::vector< std::string > &required_params)
Set required parameter list.
void setNodeType(NodeType node_type)
Set node type.
virtual int64_t getMemorySize()
Get memory size.
std::string getVersion()
Get version number.
virtual base::Status addResourceWithoutState(const std::string &key, const base::Any &value)
Add stateless resource.
std::vector< std::string > getRequiredParams()
Get required parameter list.
virtual base::Status setIterInput(Edge *input, int index=-1)
Set iteration input edge.
virtual base::Status setParam(const std::string &key, const std::string &value)
Set parameter (string type)
bool getInitialized()
Get whether it's initialized.
bool getTraceFlag()
Get trace flag.
base::Status removeDropdownParam(const std::string &dropdown_param)
Remove dropdown parameter.
virtual base::Status setMemory(device::Buffer *buffer)
Set memory buffer.
virtual base::Status deserialize(rapidjson::Value &json)
Deserialize from JSON.
virtual base::Status init()
Initialize node.
base::Status setOutputTypeInfo(std::shared_ptr< EdgeTypeInfo > output_type_info, std::string desc="")
Set output type information.
virtual base::Status setDeviceType(base::DeviceType device_type)
Set device type.
virtual Edge * createResourceWithState(const std::string &key)
Create stateful resource.
virtual base::EdgeUpdateFlag updateInput()
Update input.
virtual base::Any & getResourceWithoutState(const std::string &key)
Get stateless resource.
virtual std::vector< Edge * > forward(Edge *input)
Single input forward propagation.
std::vector< Edge * > outputs_
Output edge list.
Definition: node.h:1318
T getResourceWithoutState(const std::string &key)
Get stateless resource (template method)
Definition: node.h:492
Edge * getOutput(int index=0)
Get output edge.
Edge * getInput(int index=0)
Get input edge.
bool isDynamicInput()
Check if it's dynamic input.
Node(const std::string &name)
Constructor.
virtual base::Status deinit()
Deinitialize node.
virtual std::shared_ptr< base::Param > getParamSharedPtr()
Get parameter (shared pointer)
std::vector< Edge * > getAllInput()
Get all input edges.
base::Status clearIoParams()
Clear IO parameters.
IOType getIoType()
Get IO type.
void setDebugFlag(bool flag)
Set debug flag.
int getOutputIndex(const std::string &name)
Get output edge index by name.
base::Status setInputTypeInfo(std::string desc="")
Set input type information (template method)
Definition: node.h:1030
virtual base::Status setParallelType(const base::ParallelType &paralle_type)
Set parallel type.
std::vector< std::string > getOutputNames()
Get all output edge names.
virtual base::Status setInputs(std::vector< Edge * > inputs)
Set all input edges.
void setIoType(IOType io_type)
Set IO type.
void setRunningFlag(bool flag)
Set running flag.
int getInputIndex(const std::string &name)
Get input edge index by name.
virtual base::Status deserialize(const std::string &json_str)
Deserialize from JSON string.
virtual base::Status setParam(const std::string &key, base::Any &any)
Set parameter (Any type)
std::map< std::string, Edge * > internal_outputs_
Internal output edge mapping.
Definition: node.h:1319
virtual base::Status defaultParam()
Configure default parameters.
void setInitializedFlag(bool flag)
Set initialized flag.
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
Serialize to JSON.
std::string key_
Node key.
Definition: node.h:1290
virtual base::Status setInputSharedPtr(std::shared_ptr< Edge > input, int index=-1)
Set input edge (shared pointer)
virtual base::Status setOutputs(std::vector< Edge * > outputs)
Set all output edges.
std::vector< Edge * > inputs_
Input edge list.
Definition: node.h:1317
virtual base::Status setInputNames(const std::vector< std::string > &names)
Set all input edge names.
std::vector< std::string > ui_params_
UI parameter list.
Definition: node.h:1350
bool checkInputs(std::vector< Edge * > &inputs)
Check input edges.
base::Status setInputTypeInfo(std::shared_ptr< EdgeTypeInfo > input_type_info, std::string desc="")
Set input type information.
base::Status setOutputData(T *obj, int index=0, bool is_external=true)
Set output data (template method)
Definition: node.h:826
virtual base::Status setInputsSharedPtr(std::vector< std::shared_ptr< Edge >> inputs)
Set all input edges (shared pointer)
virtual void clearInterrupt()
Clear interrupt status.
virtual base::Status setOutputsSharedPtr(std::vector< std::shared_ptr< Edge >> outputs)
Set all output edges (shared pointer)
std::map< std::string, std::vector< std::string > > getDropdownParams()
Get dropdown parameters.
virtual base::Status setOutputSharedPtr(std::shared_ptr< Edge > output, int index=-1)
Set output edge (shared pointer)
base::Status removeIoParam(const std::string &io_param)
Remove IO parameter.
base::Status setCompositeNode(CompositeNode *composite_node)
Set parent composite node.
std::vector< std::shared_ptr< EdgeTypeInfo > > getOutputTypeInfo()
Get output type information.
base::Status addRequiredParam(const std::string &required_param)
Add required parameter.
base::Status setVersion(const std::string &version)
Set version number.
base::Status addIoParam(const std::string &io_param)
Add IO parameter.
base::DeviceType device_type_
Device type.
Definition: node.h:1295
virtual base::Status setInput(Edge *input, int index=-1)
Set input edge.
virtual void setTraceFlag(bool flag)
Set trace flag.
std::string getName()
Get node name.
virtual Edge * getResourceWithState(const std::string &key)
Get stateful resource.
base::Status removeUiParam(const std::string &ui_param)
Remove UI parameter.
base::Status setIoParams(const std::vector< std::string > &io_params)
Set IO parameter list.
CompositeNode * getCompositeNode()
Get parent composite node.
virtual std::shared_ptr< base::Param > getExternalParam(const std::string &key)
Get external parameter.
base::Status setDropdownParams(const std::map< std::string, std::vector< std::string >> &dropdown_params)
Set dropdown parameters.
virtual base::Status loadFile(const std::string &path)
Load from file.
std::vector< std::shared_ptr< EdgeTypeInfo > > output_type_info_
Output type information.
Definition: node.h:1316
void setInnerFlag(bool flag)
Set inner flag.
bool isRunning()
Check if it's running.
bool getGraphFlag()
Get graph flag.
std::shared_ptr< base::Param > param_
Node parameters.
Definition: node.h:1304
base::Status addDropdownParam(const std::string &dropdown_param, const std::vector< std::string > &dropdown_values)
Add dropdown parameter.
Typed node creator.
Definition: node.h:1392
virtual std::shared_ptr< Node > createNodeSharedPtr(const std::string &node_name, std::vector< Edge * > inputs, std::vector< Edge * > outputs) override
Create node (shared pointer)
Definition: node.h:1414
virtual Node * createNode(const std::string &node_name, std::vector< Edge * > inputs, std::vector< Edge * > outputs) override
Create node.
Definition: node.h:1401
#define NNDEPLOY_LOGW(fmt,...)
Definition: log.h:61
#define NNDEPLOY_LOGE(fmt,...)
Definition: log.h:59
#define NNDEPLOY_CC_API
api
Definition: macro.h:29
@ kStatusCodeOk
Definition: status.h:13
@ kStatusCodeErrorNullParam
Definition: status.h:22
@ kStatusCodeErrorDag
Definition: status.h:83
@ kParallelTypeNone
Definition: common.h:354
std::function< base::Status(std::vector< Edge * > inputs, std::vector< Edge * > outputs, base::Param *param)> NodeFunc
Node function type definition.
Definition: node.h:1595
std::shared_ptr< Node > createNodeSharedPtr(const std::string &node_key, const std::string &node_name)
Create node (shared pointer)
NodeFactory * getGlobalNodeFactory()
Get global node factory.
Node * createNode(const std::string &node_key, const std::string &node_name)
Create node.
std::set< std::string > getNodeKeys()
Get all node keys.