Skip to content

Commit

Permalink
fix profiling (PaddlePaddle#330)
Browse files Browse the repository at this point in the history
* add reset()

* add UT

* up 1

* up x

* del UT
  • Loading branch information
gglin001 authored Dec 20, 2021
1 parent a9a1a3d commit 6c7d4cc
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
11 changes: 11 additions & 0 deletions paddle/fluid/framework/ipu/ipu_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ IpuBackend::IpuBackend() {
executor_ = std::make_unique<Executor>();
}

IpuBackend::~IpuBackend() {
compiler_.reset();
executor_.reset();
}

void IpuBackend::Compile(ir::Graph* graph,
const std::vector<std::string>& feed_list,
const std::vector<std::string>& fetch_list) {
Expand Down Expand Up @@ -75,6 +80,12 @@ void IpuBackend::Prepare() {

void IpuBackend::Detach() { executor_->Detach(); }

void IpuBackend::Reset() {
executor_->Detach();
compiler_.reset();
executor_.reset();
}

void IpuBackend::SetScope(const Scope& scope) {
scope_ = &scope;
executor_->SetScope(&scope);
Expand Down
6 changes: 5 additions & 1 deletion paddle/fluid/framework/ipu/ipu_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class IpuBackend {

public:
IpuBackend();
~IpuBackend() = default;
~IpuBackend();

// what compile does include(call compiler_):
// 1. map paddle-op -> poart op
Expand All @@ -63,6 +63,10 @@ class IpuBackend {
// detach IPU manually
void Detach();

// reset manually
// call it before destruct works
void Reset();

void SetScope(const Scope &scope);
const Scope *GetScope() { return scope_; }
void SetIpuStrategy(const IpuStrategy &strategy);
Expand Down
5 changes: 5 additions & 0 deletions paddle/fluid/framework/ipu/ipu_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ TO GetCastSigAttrAllowNull(std::string attr, OpDesc* op_desc) {

Compiler::Compiler() { RegisterOpFunc(); }

Compiler::~Compiler() {
builder_.reset();
one_builder_.reset();
}

void Compiler::Prepare() {
builder_ = popart::Builder::create();
one_builder_ = std::make_unique<OneBuilder>();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/ipu/ipu_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct OneBuilder {
class Compiler {
public:
Compiler();
~Compiler() = default;
~Compiler();

void RegisterOpFunc();
void Prepare();
Expand Down
6 changes: 6 additions & 0 deletions paddle/fluid/framework/ipu/ipu_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace paddle {
namespace framework {
namespace ipu {

Executor::~Executor() {
Detach();
session_.reset();
one_session_.reset();
}

void Executor::Prepare(const std::string &proto) {
VLOG(10) << "enter Executor::Prepare";

Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/ipu/ipu_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct OneSession {
class Executor {
public:
Executor() = default;
~Executor() = default;
~Executor();

// build popart session
void Prepare(const std::string &proto);
Expand Down Expand Up @@ -89,7 +89,7 @@ class Executor {
// popart session, where graph running
std::unique_ptr<popart::Session> session_;
// one OneSession means a graph
std::shared_ptr<OneSession> one_session_;
std::unique_ptr<OneSession> one_session_;

int step_ = 0;
};
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/pybind/pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3208,6 +3208,7 @@ All parameter, weight, gradient are variables in Paddle.
},
py::return_value_policy::reference)
.def("detach", &ipu::IpuBackend::Detach)
.def("reset", &ipu::IpuBackend::Reset)
.def("set_scope", &ipu::IpuBackend::SetScope)
.def("set_ipu_strategy", &ipu::IpuBackend::SetIpuStrategy)
.def("set_custom_ops", &ipu::IpuBackend::SetCustomOps)
Expand Down
3 changes: 3 additions & 0 deletions python/paddle/fluid/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ def compile(self, feed_list, fetch_list, feed_var_name='feed', scope=None):
def detach(self):
self._backend.detach()

def reset(self):
self._backend.reset()

def save_onnx_model(self, file_name):
self._backend.save_molde_proto(file_name)

Expand Down

0 comments on commit 6c7d4cc

Please sign in to comment.