|
|
|
|
@ -210,9 +210,10 @@ void RecurrentOp::RunImpl(const framework::Scope &scope,
|
|
|
|
|
auto *block = Attr<framework::BlockDesc *>(kStepBlock);
|
|
|
|
|
|
|
|
|
|
auto *program = block->Program();
|
|
|
|
|
auto ctx = executor.Prepare(
|
|
|
|
|
*program, block->ID(), Attr<std::vector<std::string>>(
|
|
|
|
|
kSkipEagerDeletionVars) /*skip_ref_cnt_vars*/);
|
|
|
|
|
auto ctx = executor.Prepare(*program, block->ID(),
|
|
|
|
|
Attr<std::vector<std::string>>(
|
|
|
|
|
kSkipEagerDeletionVars), /*skip_ref_cnt_vars*/
|
|
|
|
|
true);
|
|
|
|
|
|
|
|
|
|
static std::mutex mutex;
|
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
|
@ -255,16 +256,6 @@ void RecurrentOp::RunImpl(const framework::Scope &scope,
|
|
|
|
|
// Link inside::output -> outside::output
|
|
|
|
|
// outside::output[seq_offset: seq_offset + 1] = inside::output
|
|
|
|
|
executor.CreateVariables(ctx->prog_, &cur_scope, ctx->block_id_);
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
LinkTensorWithCallback(scope, Outputs(kOutputs), cur_scope,
|
|
|
|
|
Outputs(kOutputs),
|
|
|
|
|
[&](const framework::LoDTensor &src_tensor,
|
|
|
|
|
framework::LoDTensor *dst_tensor) {
|
|
|
|
|
framework::Tensor src_slice =
|
|
|
|
|
src_tensor.Slice(seq_offset, seq_offset + 1);
|
|
|
|
|
dst_tensor->ShareDataWith(src_slice);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Linked now, execute!
|
|
|
|
|
executor.RunPreparedContext(ctx.get(), &cur_scope,
|
|
|
|
|
@ -284,6 +275,14 @@ void RecurrentOp::RunImpl(const framework::Scope &scope,
|
|
|
|
|
// early.
|
|
|
|
|
framework::TensorCopy(src_tensor, place, dev_ctx, &dst_out);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
LinkTensorWithCallback(
|
|
|
|
|
cur_scope, Outputs(kOutputs), scope, Outputs(kOutputs),
|
|
|
|
|
[&](const framework::LoDTensor &src_tensor,
|
|
|
|
|
framework::LoDTensor *dst_tensor) {
|
|
|
|
|
auto dst_out = dst_tensor->Slice(seq_offset, seq_offset + 1);
|
|
|
|
|
framework::TensorCopy(src_tensor, place, dev_ctx, &dst_out);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scopes.ForwardNext();
|
|
|
|
|
|