Skip to content

Conversation

@reyoung
Copy link
Collaborator

@reyoung reyoung commented Aug 16, 2017

Fix #3521

* Clone method will create a new object instance, which is as same as
  itself.
* This is the first step to remove shared_ptr for OperatorBase
// You can also use
// using PARENT_CLASS::PARENT_CLASS;
// to use parent's constructor.
#define DEFINE_OP_CTOR(CLS, PARENT_CLS) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFINE_OP_CREATOR 还是 DEFINE_OP_CONSTRUCTOR 的简写?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Change it to DEFINE_OP_CONSTRUCTOR

op->Run(scope, cpu_device_context);
}

class OperatorClone : public paddle::framework::OperatorBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是当成一个普通 op ,train 跑起来的时候去run吗? 感觉没必要直接写就行了吧

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是测试一下Clone返回的结果对不对。只是一个单测。

};

class RecurrentGradientOp final : public framework::OperatorBase {
class RecurrentGradientOp : public framework::OperatorBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是 final吧,如果继承,可以继承 RecurrentGradientAlgorithm

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为注册Op的时候会插入新的Clone函数,这样用户开发Kernel的时候就不需要关注Clone的逻辑了。

所以注册进OpRegistry的Op,不能是Final的。


// Return a new operator instance, which is as same as this.
// Use unique_ptr to prevent caller forget to delete this pointer.
virtual std::unique_ptr<OperatorBase> Clone() const = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers
In google C++ style, says

Prefer to use std::unique_ptr to make ownership transfer explicit.

Copy link
Contributor

@Superjomn Superjomn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@reyoung reyoung merged commit 9806e7f into PaddlePaddle:develop Aug 17, 2017
std::string type_;
// NOTE: in case of OpGrad, inputs_ contains:
// I (Inputs)
// I (Inputs)opear
Copy link
Collaborator

@JiayiFeng JiayiFeng Aug 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

@reyoung reyoung deleted the feature/clone_op branch October 2, 2017 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants