You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

node.h 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef PREDICT_SRC_NODE_H_
  17. #define PREDICT_SRC_NODE_H_
  18. #include <unordered_set>
  19. #include <string>
  20. #include <vector>
  21. #include "include/session.h"
  22. #include "src/op.h"
  23. namespace mindspore {
  24. namespace predict {
  25. using NODE_ID = std::string;
  26. class Node {
  27. public:
  28. Node() = default;
  29. explicit Node(const NodeDef *nodeDef);
  30. virtual ~Node();
  31. NODE_ID ID();
  32. std::string Type();
  33. void SetTensors(const NodeDef &nodeDef, const std::vector<Tensor *> &allTensors);
  34. void SetDepends(const std::unordered_set<NODE_ID> &deps);
  35. std::unordered_set<NODE_ID> GetDepends();
  36. void AddInEdge(Node *node);
  37. void AddOutEdge(Node *node);
  38. std::unordered_set<Node *> &GetAllOutEdges();
  39. std::unordered_set<Node *> &GetAllInEdges();
  40. std::vector<Tensor *> &GetOutputTensors();
  41. std::vector<Tensor *> &GetInputTensors();
  42. int InitOp(const OpDef &opDef, const Context &ctx);
  43. int Run(const Context &ctx);
  44. int MallocOutput(const Context &ctx);
  45. void FreeInput();
  46. protected:
  47. friend class GraphExecution;
  48. NODE_ID id;
  49. std::string type;
  50. OpBase *op{};
  51. std::vector<Tensor *> inputs;
  52. std::vector<Tensor *> outputs;
  53. std::unordered_set<NODE_ID> depends;
  54. std::unordered_set<Node *> inEdges;
  55. std::unordered_set<Node *> outEdges;
  56. };
  57. } // namespace predict
  58. } // namespace mindspore
  59. #endif // PREDICT_SRC_NODE_H_