• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_SERVICE_EXECUTABLE_RUN_OPTIONS_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_SERVICE_EXECUTABLE_RUN_OPTIONS_H_
18 
19 #include "tensorflow/compiler/xla/executable_run_options.h"
20 #include "tensorflow/compiler/xla/service/stream_pool.h"
21 #include "tensorflow/compiler/xla/statusor.h"
22 #include "tensorflow/stream_executor/stream_executor.h"
23 
24 namespace xla {
25 
26 // Class containing options for running a LocalExecutable and other auxiliary
27 // data.
28 class ServiceExecutableRunOptions {
29  public:
30   using StreamBorrower = std::function<StatusOr<StreamPool::Ptr>(int)>;
31 
ServiceExecutableRunOptions()32   ServiceExecutableRunOptions()
33       : ServiceExecutableRunOptions(ExecutableRunOptions()) {}
34 
35   explicit ServiceExecutableRunOptions(ExecutableRunOptions run_options,
36                                        StreamBorrower borrow_stream = nullptr)
run_options_(std::move (run_options))37       : run_options_(std::move(run_options)),
38         borrow_stream_(std::move(borrow_stream)) {}
39 
40   // Returns reference or pointer to `ExecutableRunOptions` member.
run_options()41   const ExecutableRunOptions& run_options() const { return run_options_; }
mutable_run_options()42   ExecutableRunOptions* mutable_run_options() { return &run_options_; }
43 
44   // Delegate to `ExecutableRunOptions` member.
stream()45   se::Stream* stream() const { return run_options_.stream(); }
allocator()46   se::DeviceMemoryAllocator* allocator() const {
47     return run_options_.allocator();
48   }
device_ordinal()49   int device_ordinal() const { return run_options_.device_ordinal(); }
50 
51   // Borrows a stream and returns a smart pointer which returns the stream on
52   // destruction.
BorrowStream(int device_ordinal)53   StatusOr<StreamPool::Ptr> BorrowStream(int device_ordinal) const {
54     return borrow_stream_
55                ? borrow_stream_(device_ordinal)
56                : Status(tensorflow::error::UNIMPLEMENTED, "No stream cache");
57   }
58 
59  private:
60   ExecutableRunOptions run_options_;
61   StreamBorrower borrow_stream_;
62 };
63 
64 }  // namespace xla
65 
66 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_SERVICE_EXECUTABLE_RUN_OPTIONS_H_
67