提交 225579b9 编写于 作者: Y Yu Yang

Remove own for add_op

* add_op could take a unique_ptr or a const reference. If unique_ptr is
  taken, the NetOp will take care of that operator's life cycle. If a
  const reference is taken, that op will be Cloned.
上级 4932f752
...@@ -89,33 +89,18 @@ class NetOp : public framework::OperatorBase { ...@@ -89,33 +89,18 @@ class NetOp : public framework::OperatorBase {
/** /**
* @brief Add an operator by ptr * @brief Add an operator by ptr
*/ */
void AddOp(framework::OperatorBase* op, bool own) { void AddOp(std::unique_ptr<framework::OperatorBase>&& op) {
PADDLE_ENFORCE(!add_op_done_, "Cannot AddOp when this network is sealed"); PADDLE_ENFORCE(!add_op_done_, "Cannot AddOp when this network is sealed");
PADDLE_ENFORCE_NOT_NULL(op, "Cannot Insert Null op"); PADDLE_ENFORCE_NOT_NULL(op, "Cannot Insert Null op");
if (!own) { ops_.push_back(std::move(op));
op = op->Clone().release();
}
ops_.emplace_back(op);
}
void AddOp(std::unique_ptr<framework::OperatorBase>&& op) {
AddOp(op.release(), true);
} }
void InsertOp(size_t pos, framework::OperatorBase* op, bool own) { void InsertOp(size_t pos, std::unique_ptr<framework::OperatorBase>&& op) {
PADDLE_ENFORCE(!add_op_done_, PADDLE_ENFORCE(!add_op_done_,
"Cannot InsertOp when this network is sealed"); "Cannot InsertOp when this network is sealed");
PADDLE_ENFORCE_NOT_NULL(op, "Cannot Insert Null op"); PADDLE_ENFORCE_NOT_NULL(op, "Cannot Insert Null op");
PADDLE_ENFORCE_LE(pos, ops_.size(), "Out of range"); PADDLE_ENFORCE_LE(pos, ops_.size(), "Out of range");
if (!own) { ops_.insert(ops_.begin() + pos, std::move(op));
op = op->Clone().release();
}
ops_.insert(ops_.begin() + pos,
std::unique_ptr<framework::OperatorBase>(op));
}
void InsertOp(size_t pos, std::unique_ptr<framework::OperatorBase>&& op) {
InsertOp(pos, op.release(), true);
} }
void InsertOp(size_t pos, const framework::OperatorBase& op) { void InsertOp(size_t pos, const framework::OperatorBase& op) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册