Store operation into graph

because the operation is a shared pointor, in app, the operation is
created as:
    auto op = graph->CreateOperation();

uses natively think the operation had been register into the graph and
would not manage the op locally.

if running the graph in another fucntion instead of the function that
create the operation, the operation would had been delete.

so the operation should be stored into the graph.

Signed-off-by: Jia <juku.jia@verisilicon.com>
This commit is contained in:
Jia 2021-04-14 10:49:19 +08:00 committed by Kainan Cha
parent dc67e9ac63
commit 11480f18f3
1 changed files with 8 additions and 1 deletions

View File

@ -33,6 +33,8 @@ namespace vx {
class Tensor; class Tensor;
class TensorSpec; class TensorSpec;
class Operation;
class Graph { class Graph {
public: public:
virtual ~Graph() {} virtual ~Graph() {}
@ -54,8 +56,13 @@ class Graph {
template <typename OpType, typename... Params> template <typename OpType, typename... Params>
std::shared_ptr<OpType> CreateOperation(Params... parameters) { std::shared_ptr<OpType> CreateOperation(Params... parameters) {
return std::make_shared<OpType>(this, parameters...); auto op = std::make_shared<OpType>(this, parameters...);
opVector.push_back(op);
return op;
} }
private:
std::vector<std::shared_ptr<tim::vx::Operation>> opVector;
}; };
} // namespace vx } // namespace vx