Skip to content

Commit a5996a6

Browse files
Hao Lufacebook-github-bot
authored andcommitted
[SR] Wrap check_for_memory_leak with DCHECK (pytorch#69588)
Summary: Pull Request resolved: pytorch#69588 Code cleanup Reviewed By: mikeiovine Differential Revision: D32938333 fbshipit-source-id: d15dc405b281411c4c3c27a1dabf82f430c3ed08
1 parent 3bb20ae commit a5996a6

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

torch/csrc/jit/runtime/static/impl.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ StaticRuntime::Deallocator::~Deallocator() {
10131013
// Assume cleanup cannot throw.
10141014
cleanupImpl();
10151015
#ifndef NDEBUG
1016-
runtime_.check_for_memory_leak(false);
1016+
runtime_.check_for_memory_leak(/*output_returned*/ false);
10171017
#endif
10181018
}
10191019

@@ -1074,8 +1074,11 @@ c10::IValue StaticRuntime::run_impl(
10741074
if (static_module_.num_outputs() > 1) {
10751075
return move_outputs_to_tuple(static_module_.num_outputs());
10761076
}
1077+
1078+
DCHECK(check_for_memory_leak(/*output_returned*/ false));
10771079
// The exact output tensor should never be managed.
10781080
DCHECK(!isManagedOutputTensor(*outputs_[0]));
1081+
10791082
// use move here. Otherwise, clean up outputs_[0] explicitly
10801083
return std::move(*outputs_[0]);
10811084
}
@@ -1437,9 +1440,7 @@ StaticRuntime::IndividualMetrics StaticRuntime::benchmark_individual_ops(
14371440
output = move_outputs_to_tuple(static_module_.num_outputs());
14381441
}
14391442

1440-
#ifndef NDEBUG
1441-
check_for_memory_leak(false);
1442-
#endif
1443+
DCHECK(check_for_memory_leak(/*output_returned*/ false));
14431444

14441445
// use move here. Otherwise, clean up outputs_[0] explicitly
14451446
output = std::move(*outputs_[0]);
@@ -1478,9 +1479,9 @@ StaticRuntime::IndividualMetrics StaticRuntime::benchmark_individual_ops(
14781479
return results;
14791480
}
14801481

1481-
void StaticRuntime::check_for_memory_leak(bool output_returned) {
1482+
bool StaticRuntime::check_for_memory_leak(bool output_returned) {
14821483
if (!static_module_.opts().cleanup_activations) {
1483-
return;
1484+
return true;
14841485
}
14851486

14861487
// check for inputs
@@ -1531,6 +1532,7 @@ void StaticRuntime::check_for_memory_leak(bool output_returned) {
15311532
}
15321533
}
15331534
VLOG(1) << "Finished checking for memory leak";
1535+
return true;
15341536
}
15351537

15361538
void StaticRuntime::deallocateOutputTensors() {

torch/csrc/jit/runtime/static/impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class TORCH_API StaticRuntime {
448448
return planner_.get();
449449
}
450450

451-
void check_for_memory_leak(bool output_returned = true);
451+
bool check_for_memory_leak(bool output_returned = true);
452452

453453
bool is_optimizable_container_type(Node* n) const {
454454
return static_module_.is_optimizable_container_type(n);

0 commit comments

Comments
 (0)