aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2021-07-02 11:16:23 -0700
committerXusong Wang <xusongw@google.com>2021-07-02 11:16:23 -0700
commitbb026242e605c2254f2d0fba7731eb9fe49bdcda (patch)
tree177085913fb6126ccb250fbbf83d093fe6074360
parentb3b00f42171a5dc460aed387120722b71bd863c6 (diff)
downloadNeuralNetworks-bb026242e605c2254f2d0fba7731eb9fe49bdcda.tar.gz
Fix sync fence FD leak in fenced compute.
Fixes: 192403402 Test: NNT_static Test: Run TestGpuNnapi 100 times Change-Id: I75ce4b32d6375cc9f6e87bb4dd2c4e78cbb1ea52
-rw-r--r--runtime/ExecutionBuilder.cpp3
-rw-r--r--runtime/ExecutionBuilder.h6
-rw-r--r--runtime/NeuralNetworks.cpp1
3 files changed, 2 insertions, 8 deletions
diff --git a/runtime/ExecutionBuilder.cpp b/runtime/ExecutionBuilder.cpp
index b2728a4fc..d9ccb0d30 100644
--- a/runtime/ExecutionBuilder.cpp
+++ b/runtime/ExecutionBuilder.cpp
@@ -996,9 +996,8 @@ int ExecutionBuilder::computeFenced(const std::vector<int>& waitFor,
VLOG(EXECUTION) << "ExecutionBuilder::computeFenced";
int result;
const auto deadline = makeDeadline(mTimeoutDuration);
- std::tie(result, mSyncFenceFd, mFencedExecutionCallback) =
+ std::tie(result, *syncFence, mFencedExecutionCallback) =
computeFencedInternal(waitFor, timeoutDurationAfterFence, deadline);
- *syncFence = mSyncFenceFd;
// If there is an error, call finishComputation to mark the computation as completed.
// Otherwise, we will call finishComputation in SyncFenceEvent::wait().
if (result != ANEURALNETWORKS_NO_ERROR) {
diff --git a/runtime/ExecutionBuilder.h b/runtime/ExecutionBuilder.h
index a8709a748..4b3b1906f 100644
--- a/runtime/ExecutionBuilder.h
+++ b/runtime/ExecutionBuilder.h
@@ -166,8 +166,6 @@ class ExecutionBuilder {
bool updateMemories();
- bool hasSyncFence() const { return mSyncFenceFd > 0; }
-
const ModelBuilder* mModel;
const ExecutionPlan* mPlan;
@@ -243,10 +241,6 @@ class ExecutionBuilder {
std::optional<bool> mOutputsFullySpecified;
bool areOutputsFullySpecified();
- // The sync fence fd that is created in the computeFenced call, if any.
- // (Sometimes no sync fence fd will be created.)
- int mSyncFenceFd = -1;
-
// The callback used to query execution related info in the case of fenced
// execution; otherwise, nullptr. If the execution plan has multiple steps,
// this is the callback associated with the last step. If the last step
diff --git a/runtime/NeuralNetworks.cpp b/runtime/NeuralNetworks.cpp
index 053a8b780..b91d3ce45 100644
--- a/runtime/NeuralNetworks.cpp
+++ b/runtime/NeuralNetworks.cpp
@@ -1596,6 +1596,7 @@ int ANeuralNetworksExecution_startComputeWithDependencies(
// TODO(miaowang): support dynamic output shape only with memory domain.
// For now just return empty output shapes.
[r](ErrorStatus status) { return r->finishComputation(status, {}); });
+ close(syncFenceToSignal);
if (n != ANEURALNETWORKS_NO_ERROR) {
*event = nullptr;
} else {