aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Sanjoy Das <sanjoy@google.com>2017-10-23 22:00:03 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-10-23 22:06:48 -0700
commit20199e91b3503881ce9a4253d64fa783f731230f (patch)
treec4df8288f581c784e515ba4ea24d1379059b54cb
parentb7de55e9ea79d1b6b1987834015b37ee59da5a99 (diff)
Don't prematurely return streams
PiperOrigin-RevId: 173214110
-rw-r--r--tensorflow/compiler/xla/client/local_client.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/tensorflow/compiler/xla/client/local_client.cc b/tensorflow/compiler/xla/client/local_client.cc
index c885b815eb..15c744ecd3 100644
--- a/tensorflow/compiler/xla/client/local_client.cc
+++ b/tensorflow/compiler/xla/client/local_client.cc
@@ -175,10 +175,15 @@ StatusOr<std::unique_ptr<ScopedShapedBuffer>> LocalExecutable::Run(
TF_RETURN_IF_ERROR(ValidateExecutionOptions(arguments, options, *backend_));
ExecutableRunOptions actual_options = options;
+
+ Backend::StreamPtr stream;
if (options.stream() == nullptr) {
+ // NB! The lifetime of `stream` needs to match the lifetime of
+ // `actual_options` (otherwise we will end up using a returned stream in
+ // ExecuteOnStreamWrapper), which is why it isn't declared in the inner "if"
+ // scope.
TF_ASSIGN_OR_RETURN(
- Backend::StreamPtr stream,
- BorrowStreamForDevice(options.device_ordinal(), backend_));
+ stream, BorrowStreamForDevice(options.device_ordinal(), backend_));
actual_options.set_stream(stream.get());
}
if (options.allocator() == nullptr) {