From 70bc4889798fca2e43104b3401a823064bd561f8 Mon Sep 17 00:00:00 2001 From: guofei <52460041+gfwm2013@users.noreply.github.com> Date: Sat, 9 May 2020 11:49:09 +0800 Subject: [PATCH] Fix the error of recurrnet op in multithreading in eval process (#24357) CreateStepScopes in recurrent op also clears scopes, which can cause segmentation fault un multi-threading. We add a lock in this PR but it may slow the computation process. We will fix in another way in next PR. --- paddle/fluid/operators/recurrent_op.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/operators/recurrent_op.cc b/paddle/fluid/operators/recurrent_op.cc index 5ec7587b700..c1adaf2037a 100644 --- a/paddle/fluid/operators/recurrent_op.cc +++ b/paddle/fluid/operators/recurrent_op.cc @@ -197,7 +197,6 @@ void RecurrentOp::RunImpl(const framework::Scope &scope, auto &dev_ctx = *pool.Get(place); VLOG(3) << "Static RNN input sequence length = " << seq_len; - StepScopes scopes = CreateStepScopes(dev_ctx, scope, seq_len); auto reverse = Attr(kReverse); framework::Executor executor(place); @@ -208,6 +207,13 @@ void RecurrentOp::RunImpl(const framework::Scope &scope, *program, block->ID(), Attr>( kSkipEagerDeletionVars) /*skip_ref_cnt_vars*/); + static std::mutex mutex; + std::lock_guard lock(mutex); + StepScopes scopes = CreateStepScopes(dev_ctx, scope, seq_len); + // TODO(gfwm2013) Function CreateStepScopes would make segmentation fault in + // multithreading in eval process, so we use a mutex before function + // CreateStepScopes to make sure that the computing process is correct. This + // problem will fix in next pull request. for (size_t i = 0; i < seq_len; ++i) { size_t seq_offset = reverse ? seq_len - i - 1 : i; VLOG(3) << "Recurrent operate at the time step " << seq_offset; -- GitLab