Skip to content

Commit 612e1a3

Browse files
committed
modification
1 parent d0b2453 commit 612e1a3

File tree

11 files changed

+24
-35
lines changed

11 files changed

+24
-35
lines changed

paddle/fluid/framework/details/computation_op_handle.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "paddle/fluid/framework/scope.h"
2424
#include "paddle/fluid/platform/device_context.h"
2525

26-
#include "paddle/fluid/framework/details/reference_count_op_handle.h"
27-
2826
namespace paddle {
2927
namespace framework {
3028
namespace details {

paddle/fluid/framework/details/op_handle_base.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ class OpHandleBase {
8989

9090
ir::Node *Node() { return node_; }
9191

92-
const std::map<platform::Place, platform::DeviceContext *>
93-
&GetDeviceContexts() const {
94-
return dev_ctxes_;
95-
}
96-
9792
protected:
9893
void RunAndRecordEvent(const std::function<void()> &callback);
9994

paddle/fluid/framework/details/reference_count_op_handle.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ class ReferenceCountOpHandle : public OpHandleBase {
6969

7070
std::string Name() const override { return "reference_count"; }
7171

72-
// protected:
72+
protected:
7373
void RunImpl() override {
74-
auto *exec_scope_ = scope_->FindVar(kLocalExecScopeName)->Get<Scope *>();
74+
auto *exec_scope = scope_->FindVar(kLocalExecScopeName)->Get<Scope *>();
7575
std::vector<LoDTensor *> tensors;
7676
for (auto &name : var_names_) {
7777
auto it = ref_cnts_->find(name);
7878
if (it == ref_cnts_->end()) continue;
7979

80-
auto *var = exec_scope_->FindVar(name);
80+
auto *var = exec_scope->FindVar(name);
8181
if (var == nullptr || !var->IsType<LoDTensor>()) continue;
8282

8383
if (it->second.fetch_sub(1) <= 1) {
@@ -91,8 +91,8 @@ class ReferenceCountOpHandle : public OpHandleBase {
9191
}
9292

9393
private:
94-
void ClearTensors(const std::vector<LoDTensor *> &tensors) const {
95-
auto *gc = dynamic_cast<const StreamGarbageCollector<Tensor> *>(gc_);
94+
void ClearTensors(const std::vector<LoDTensor *> &tensors) {
95+
auto *gc = dynamic_cast<StreamGarbageCollector<Tensor> *>(gc_);
9696
if (gc != nullptr) {
9797
auto compute_stream = dev_ctx_->stream();
9898
auto callback_stream = gc->stream();

paddle/fluid/framework/details/reference_count_pass.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,10 @@ std::unique_ptr<ir::Graph> ReferenceCountPass::ApplyImpl(
128128
std::vector<std::unique_ptr<OpHandleBase>> new_all_ops;
129129
new_all_ops.reserve(compute_ref_cnt_map.size() + all_ops.size());
130130
for (auto &op : all_ops) {
131-
auto it = compute_ref_cnt_map.find(op.get());
131+
new_all_ops.emplace_back(std::move(op));
132+
auto it = compute_ref_cnt_map.find(new_all_ops.back().get());
132133
if (it != compute_ref_cnt_map.end()) {
133-
new_all_ops.emplace_back(std::move(op));
134-
new_all_ops.emplace_back(std::unique_ptr<OpHandleBase>(it->second));
135-
} else {
136-
new_all_ops.emplace_back(std::move(op));
134+
new_all_ops.emplace_back(it->second);
137135
}
138136
}
139137

paddle/fluid/framework/executor.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ int kProgramId = -1;
3737

3838
ExecutorPrepareContext::ExecutorPrepareContext(
3939
const framework::ProgramDesc& prog, size_t block_id)
40-
: prog_(prog),
41-
block_id_(block_id),
42-
ref_cnts_(GetNonPersistableReferenceCount<int>(prog, block_id)) {}
40+
: prog_(prog), block_id_(block_id) {
41+
if (GetEagerDeletionThreshold() >= 0) {
42+
ref_cnts_ = GetNonPersistableReferenceCount<int>(prog_, block_id_);
43+
}
44+
}
4345

4446
ExecutorPrepareContext::~ExecutorPrepareContext() {
4547
VLOG(5) << "destroy ExecutorPrepareContext";
@@ -331,8 +333,6 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
331333
CreateVariables(ctx->prog_, local_scope, ctx->block_id_);
332334
}
333335

334-
std::shared_ptr<std::vector<framework::LoDTensor*>> erase_tensors(
335-
new std::vector<framework::LoDTensor*>());
336336
int64_t max_memory_size = GetEagerDeletionThreshold();
337337

338338
std::unique_ptr<GarbageCollector<Tensor>> gc;
@@ -353,7 +353,6 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
353353
for (auto& op : ctx->ops_) {
354354
op->Run(*local_scope, place_);
355355

356-
#ifdef PADDLE_WITH_CUDA
357356
if (gc != nullptr) {
358357
std::vector<std::string> erase_vars;
359358
for (auto& input : op->Inputs()) {
@@ -395,18 +394,18 @@ void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope,
395394
if (!erase_tensors.empty()) gc->Add(erase_tensors);
396395
}
397396
}
398-
#endif
399397

400398
if (FLAGS_benchmark) {
401399
VLOG(2) << "Memory used after operator " + op->Type() + " running: "
402400
<< memory::memory_usage(place_);
403401
}
404402
}
405403

406-
if (gc != nullptr)
404+
if (gc != nullptr) {
407405
gc->Wait();
408-
else
406+
} else {
409407
platform::DeviceContextPool::Instance().Get(place_)->Wait();
408+
}
410409

411410
if (local_scope != scope) {
412411
scope->DeleteScope(local_scope);

paddle/fluid/framework/executor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ namespace paddle {
2828
namespace framework {
2929
extern void InitializeVariable(Variable* var, proto::VarType::Type var_type);
3030

31-
int64_t GetEagerDeletionThreshold();
32-
3331
template <typename T>
3432
std::unordered_map<std::string, T> GetNonPersistableReferenceCount(
3533
const ProgramDesc& prog, size_t block_id) {

paddle/fluid/framework/parallel_executor.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ limitations under the License. */
2222
#include "paddle/fluid/framework/ir/graph_viz_pass.h"
2323

2424
#ifdef PADDLE_WITH_CUDA
25-
#include "paddle/fluid/framework/details/reference_count_pass.h"
2625
#include "paddle/fluid/platform/nccl_helper.h"
2726
#endif
2827

paddle/fluid/framework/parallel_executor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ limitations under the License. */
2929
#include "paddle/fluid/framework/tensor.h"
3030
#include "paddle/fluid/platform/device_context.h"
3131

32+
#ifdef PADDLE_WITH_CUDA
33+
#include "paddle/fluid/framework/details/reference_count_pass.h"
34+
#endif
35+
3236
namespace paddle {
3337
namespace framework {
3438

paddle/fluid/framework/scope.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ DEFINE_bool(
3232
"slow down the destruction of variables.(around 1% performance harm)");
3333

3434
DEFINE_double(
35-
eager_delete_tensor_GB, -1.0,
35+
eager_delete_tensor_gb, -1.0,
3636
"Memory size threshold (GB) when the garbage collector clear tensors."
3737
"Disabled when this value is less than 0");
3838

3939
namespace paddle {
4040
namespace framework {
4141

4242
int64_t GetEagerDeletionThreshold() {
43-
return FLAGS_eager_delete_tensor_GB < 0
43+
return FLAGS_eager_delete_tensor_gb < 0
4444
? -1
45-
: static_cast<int64_t>(FLAGS_eager_delete_tensor_GB *
45+
: static_cast<int64_t>(FLAGS_eager_delete_tensor_gb *
4646
(static_cast<int64_t>(1) << 30));
4747
}
4848

paddle/fluid/platform/device_context.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ limitations under the License. */
3636
#endif
3737
#include "unsupported/Eigen/CXX11/Tensor"
3838

39-
DECLARE_bool(clear_gpu_memory_when_unused);
40-
4139
namespace paddle {
4240
namespace platform {
4341

0 commit comments

Comments
 (0)