Skip to content

Commit 4e4438a

Browse files
committed
Remove Op::Clone method
It is used by NetOp before.
1 parent f7fd711 commit 4e4438a

File tree

5 files changed

+22
-80
lines changed

5 files changed

+22
-80
lines changed

paddle/fluid/framework/op_registry.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,15 @@ struct OpKernelRegistrarFunctorEx<PlaceType, false, I,
182182
VarTypeInference
183183
InferShapeBase
184184
*/
185-
#define REGISTER_OPERATOR(op_type, op_class, ...) \
186-
STATIC_ASSERT_GLOBAL_NAMESPACE( \
187-
__reg_op__##op_type, \
188-
"REGISTER_OPERATOR must be called in global namespace"); \
189-
class _OpClass_##op_type##_ : public op_class { \
190-
public: \
191-
DEFINE_OP_CLONE_METHOD(_OpClass_##op_type##_); \
192-
DEFINE_OP_CONSTRUCTOR(_OpClass_##op_type##_, op_class); \
193-
}; \
194-
static ::paddle::framework::OperatorRegistrar<_OpClass_##op_type##_, \
195-
##__VA_ARGS__> \
196-
__op_registrar_##op_type##__(#op_type); \
197-
int TouchOpRegistrar_##op_type() { \
198-
__op_registrar_##op_type##__.Touch(); \
199-
return 0; \
185+
#define REGISTER_OPERATOR(op_type, op_class, ...) \
186+
STATIC_ASSERT_GLOBAL_NAMESPACE( \
187+
__reg_op__##op_type, \
188+
"REGISTER_OPERATOR must be called in global namespace"); \
189+
static ::paddle::framework::OperatorRegistrar<op_class, ##__VA_ARGS__> \
190+
__op_registrar_##op_type##__(#op_type); \
191+
int TouchOpRegistrar_##op_type() { \
192+
__op_registrar_##op_type##__.Touch(); \
193+
return 0; \
200194
}
201195

202196
#define REGISTER_OP_WITHOUT_GRADIENT(op_type, op_class, op_maker_class) \

paddle/fluid/framework/op_registry_test.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,10 @@ TEST(OpRegistry, CustomChecker) {
193193
ASSERT_EQ(test_attr, 4);
194194
}
195195

196-
class CosineOpComplete : public paddle::framework::CosineOp {
197-
public:
198-
DEFINE_OP_CONSTRUCTOR(CosineOpComplete, paddle::framework::CosineOp);
199-
DEFINE_OP_CLONE_METHOD(CosineOpComplete);
200-
};
201-
202196
TEST(OperatorRegistrar, Test) {
203197
paddle::framework::OperatorRegistrar<
204-
CosineOpComplete, paddle::framework::CosineOpProtoAndCheckerMaker>
198+
paddle::framework::CosineOp,
199+
paddle::framework::CosineOpProtoAndCheckerMaker>
205200
reg("cos");
206201
}
207202

paddle/fluid/framework/operator.h

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ class OperatorBase {
121121
//! Get all outputs variable names
122122
virtual std::vector<std::string> OutputVars(bool has_intermediate) const;
123123

124-
// Return a new operator instance, which is as same as this.
125-
// Use unique_ptr to prevent caller forget to delete this pointer.
126-
virtual std::unique_ptr<OperatorBase> Clone() const = 0;
127-
128124
protected:
129125
std::string type_;
130126
// NOTE: in case of OpGrad, inputs_ contains:
@@ -145,37 +141,6 @@ class OperatorBase {
145141
const platform::Place& place) const = 0;
146142
};
147143

148-
// Macro for define a clone method.
149-
// If you are writing an kernel operator, `Clone` will be defined when you
150-
// register it. i.e. `Clone` method is not needed to define by yourself.
151-
#define DEFINE_OP_CLONE_METHOD(cls) \
152-
std::unique_ptr<::paddle::framework::OperatorBase> Clone() const final { \
153-
return std::unique_ptr<::paddle::framework::OperatorBase>(new cls(*this)); \
154-
}
155-
156-
// Macro for define a default constructor for Operator.
157-
// You can also use
158-
// using PARENT_CLASS::PARENT_CLASS;
159-
// to use parent's constructor.
160-
#define DEFINE_OP_CONSTRUCTOR(cls, parent_cls) \
161-
cls(const std::string& type, \
162-
const ::paddle::framework::VariableNameMap& inputs, \
163-
const ::paddle::framework::VariableNameMap& outputs, \
164-
const paddle::framework::AttributeMap& attrs) \
165-
: parent_cls(type, inputs, outputs, attrs) {}
166-
167-
class NOP : public OperatorBase {
168-
public:
169-
using OperatorBase::OperatorBase;
170-
std::unique_ptr<OperatorBase> Clone() const override {
171-
return std::unique_ptr<OperatorBase>(new NOP(*this));
172-
}
173-
174-
private:
175-
void RunImpl(const Scope& scope,
176-
const platform::Place& place) const override {}
177-
};
178-
179144
class ExecutionContext {
180145
public:
181146
ExecutionContext(const OperatorBase& op, const Scope& scope,

paddle/fluid/framework/operator_test.cc

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -247,26 +247,3 @@ TEST(OpKernel, multi_inputs) {
247247
auto op = paddle::framework::OpRegistry::CreateOp(op_desc);
248248
op->Run(scope, cpu_place);
249249
}
250-
251-
class OperatorClone : public paddle::framework::OperatorBase {
252-
public:
253-
DEFINE_OP_CLONE_METHOD(OperatorClone);
254-
OperatorClone(const std::string& type,
255-
const paddle::framework::VariableNameMap& inputs,
256-
const paddle::framework::VariableNameMap& outputs,
257-
const paddle::framework::AttributeMap& attrs)
258-
: OperatorBase(type, inputs, outputs, attrs) {}
259-
260-
private:
261-
void RunImpl(const paddle::framework::Scope& scope,
262-
const paddle::platform::Place& place) const override {}
263-
};
264-
265-
TEST(Operator, Clone) {
266-
paddle::framework::InitDevices(true);
267-
OperatorClone a("ABC", paddle::framework::VariableNameMap{},
268-
paddle::framework::VariableNameMap{},
269-
paddle::framework::AttributeMap{});
270-
auto b = a.Clone();
271-
ASSERT_EQ(a.Type(), b->Type());
272-
}

paddle/fluid/framework/var_type_inference_test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ limitations under the License. */
2222
namespace paddle {
2323
namespace framework {
2424

25+
class NOP : public OperatorBase {
26+
public:
27+
NOP(const std::string &type, const VariableNameMap &inputs,
28+
const VariableNameMap &outputs, const AttributeMap &attrs)
29+
: OperatorBase(type, inputs, outputs, attrs) {}
30+
31+
private:
32+
void RunImpl(const Scope &scope,
33+
const platform::Place &place) const override {}
34+
};
35+
2536
class SumOpMaker : public OpProtoAndCheckerMaker {
2637
public:
2738
void Make() {

0 commit comments

Comments
 (0)