Skip to content

Commit 81dfc0c

Browse files
author
Yang Yang(Tony)
authored
Clean up unused code in operator class (#10035)
* delete unused IsNetOp() and Rename() * rm OperatorBase::Rename implementation * delete Operator::InputVars() * remove unused OperatorBase::ShareLoD; ShareLoD has been implemented in infershape * organize operatorbase; remove unused set_type * add comments * fix comment
1 parent f09aed0 commit 81dfc0c

File tree

2 files changed

+15
-48
lines changed

2 files changed

+15
-48
lines changed

paddle/fluid/framework/operator.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,6 @@ std::string OperatorBase::DebugStringEx(const Scope* scope) const {
171171
return ss.str();
172172
}
173173

174-
void OperatorBase::Rename(const std::string& old_name,
175-
const std::string& new_name) {
176-
for (auto& input : inputs_) {
177-
std::replace(input.second.begin(), input.second.end(), old_name, new_name);
178-
}
179-
for (auto& output : outputs_) {
180-
std::replace(output.second.begin(), output.second.end(), old_name,
181-
new_name);
182-
}
183-
}
184-
185174
OperatorBase::OperatorBase(const std::string& type,
186175
const VariableNameMap& inputs,
187176
const VariableNameMap& outputs,
@@ -327,7 +316,6 @@ bool OpSupportGPU(const std::string& op_type) {
327316
auto it = all_kernels.find(op_type);
328317
if (it == all_kernels.end()) {
329318
// All control operator must support GPU
330-
331319
return true;
332320
}
333321
for (auto& kern_pair : it->second) {

paddle/fluid/framework/operator.h

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,28 @@ class OperatorBase {
7979

8080
virtual ~OperatorBase() {}
8181

82-
template <typename T>
83-
inline const T& Attr(const std::string& name) const {
84-
PADDLE_ENFORCE(attrs_.count(name) != 0, "%s should be in AttributeMap",
85-
name);
86-
return boost::get<T>(attrs_.at(name));
87-
}
88-
89-
/// if scope is not null, also show dimensions of arguments
90-
virtual std::string DebugStringEx(const Scope* scope) const;
91-
92-
std::string DebugString() const { return DebugStringEx(nullptr); }
93-
94-
/// Net will call this interface function to Run an op.
82+
/// Executor will call this interface function to Run an op.
9583
// The implementation should be written at RunImpl
9684
void Run(const Scope& scope, const platform::Place& place);
9785

9886
// FIXME(typhoonzero): this is only used for recv_op to stop event_loop.
9987
virtual void Stop() {}
10088

101-
virtual bool IsNetOp() const { return false; }
89+
/// if scope is not null, also show dimensions of arguments
90+
virtual std::string DebugStringEx(const Scope* scope) const;
91+
std::string DebugString() const { return DebugStringEx(nullptr); }
10292

10393
virtual bool SupportGPU() const { return false; }
10494

105-
/// rename inputs outputs name
106-
void Rename(const std::string& old_name, const std::string& new_name);
95+
const std::string& Type() const { return type_; }
96+
97+
template <typename T>
98+
inline const T& Attr(const std::string& name) const {
99+
PADDLE_ENFORCE(attrs_.count(name) != 0, "%s should be in AttributeMap",
100+
name);
101+
return boost::get<T>(attrs_.at(name));
102+
}
103+
const AttributeMap& Attrs() const { return attrs_; }
107104

108105
const VariableNameMap& Inputs() const { return inputs_; }
109106
const VariableNameMap& Outputs() const { return outputs_; }
@@ -112,21 +109,17 @@ class OperatorBase {
112109
std::string Input(const std::string& name) const;
113110
//! Get a input which has multiple variables.
114111
const std::vector<std::string>& Inputs(const std::string& name) const;
115-
112+
//! Get all inputs variable names
116113
std::vector<std::string> InputVars() const;
117114

118115
//! Get a output with argument's name described in `op_proto`
119116
std::string Output(const std::string& name) const;
120117
//! Get an output which has multiple variables.
121118
//! TODO add a vector_view to prevent memory copy.
122119
const std::vector<std::string>& Outputs(const std::string& name) const;
123-
120+
//! Get all outputs variable names
124121
virtual std::vector<std::string> OutputVars(bool has_intermediate) const;
125122

126-
const std::string& Type() const { return type_; }
127-
void SetType(const std::string& type) { type_ = type; }
128-
const AttributeMap& Attrs() const { return attrs_; }
129-
130123
// Return a new operator instance, which is as same as this.
131124
// Use unique_ptr to prevent caller forget to delete this pointer.
132125
virtual std::unique_ptr<OperatorBase> Clone() const = 0;
@@ -278,20 +271,6 @@ class ExecutionContext {
278271
return res;
279272
}
280273

281-
void ShareLoD(const std::string& in, const std::string& out, size_t i = 0,
282-
size_t j = 0) const {
283-
PADDLE_ENFORCE_LT(i, InputSize(in));
284-
PADDLE_ENFORCE_LT(j, OutputSize(out));
285-
auto* in_var = MultiInputVar(in)[i];
286-
auto* out_var = MultiOutputVar(out)[j];
287-
if (!in_var->IsType<LoDTensor>()) return;
288-
PADDLE_ENFORCE(out_var->IsType<LoDTensor>(),
289-
"The %d-th output of Output(%s) must be LoDTensor.", j, out);
290-
auto in_tensor = in_var->Get<LoDTensor>();
291-
auto* out_tensor = out_var->GetMutable<LoDTensor>();
292-
out_tensor->set_lod(in_tensor.lod());
293-
}
294-
295274
platform::Place GetPlace() const { return device_context_.GetPlace(); }
296275

297276
template <typename DeviceContextType>

0 commit comments

Comments
 (0)