diff --git a/paddle/framework/operator.h b/paddle/framework/operator.h index 92032478661be65481bbd66693df95df83a678e7..9e4d0d5e398d74c9a22b1f9fa70860190b6c5d49 100644 --- a/paddle/framework/operator.h +++ b/paddle/framework/operator.h @@ -111,6 +111,8 @@ class OperatorBase { std::string Type() const { return type_; } const AttributeMap& Attrs() const { return attrs_; } + // Return a new operator instance, which is as same as this. + // NOTE: It is caller's responsibility to delete that operator instance. virtual OperatorBase* Clone() const = 0; public: @@ -127,9 +129,16 @@ class OperatorBase { AttributeMap attrs_; }; +// Macro for define a clone method. +// If you are writing an kernel operator, `Clone` will be defined when you +// register it. #define DEFINE_OP_CLONE_METHOD(CLS) \ OperatorBase* Clone() const final { return new CLS(*this); } +// Macro for define a default constructor for Operator. +// You can also use +// using PARENT_CLASS::PARENT_CLASS; +// to use parent's constructor. #define DEFINE_OP_CTOR(CLS, PARENT_CLS) \ CLS(const std::string& type, const VarNameMap& inputs, \ const VarNameMap& outputs, const paddle::framework::AttributeMap& attrs) \