• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 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 #ifndef TENSORFLOW_CORE_TFRT_FALLBACK_FALLBACK_STATE_H_
16 #define TENSORFLOW_CORE_TFRT_FALLBACK_FALLBACK_STATE_H_
17 
18 #include <memory>
19 
20 #include "tensorflow/core/common_runtime/device_mgr.h"
21 #include "tensorflow/core/common_runtime/device_set.h"
22 #include "tensorflow/core/common_runtime/graph_execution_state.h"
23 #include "tensorflow/core/common_runtime/process_function_library_runtime.h"
24 #include "tensorflow/core/framework/device.h"
25 #include "tensorflow/core/framework/graph.pb.h"
26 #include "tensorflow/core/public/session_options.h"
27 #include "tensorflow/core/tfrt/utils/statusor.h"
28 
29 namespace tensorflow {
30 namespace tfrt_stub {
31 
32 // FallbackState contains the necessary runtime states (eg. Devices) used in
33 // current tensorflow. It also provides methods used in current tensorflow.
34 class FallbackState {
35  public:
36   // The FunctionDefLibrary is passed in to initialize the
37   // ProcessFunctionLibraryRuntime member of this class
38   static StatusOr<std::unique_ptr<FallbackState>> Create(
39       const SessionOptions &session_options,
40       const tensorflow::FunctionDefLibrary &fdef_lib);
41 
42   FallbackState(const SessionOptions &session_options,
43                 std::vector<std::unique_ptr<Device>> devices,
44                 const tensorflow::FunctionDefLibrary &fdef_lib);
45 
46   // Create GraphExecutionState from the `graph_def`. The result will contain a
47   // preprocessed graph with runtime information such as devices.
48   StatusOr<std::unique_ptr<GraphExecutionState>> CreateGraphExecutionState(
49       GraphDef graph_def) const;
50 
session_options()51   const SessionOptions &session_options() const { return session_options_; }
52 
device_manager()53   const DeviceMgr &device_manager() const { return device_manager_; }
54 
process_function_library_runtime()55   const ProcessFunctionLibraryRuntime &process_function_library_runtime()
56       const {
57     return pflr_;
58   }
59 
60  private:
61   SessionOptions session_options_;
62   StaticDeviceMgr device_manager_;
63   DeviceSet device_set_;
64   FunctionLibraryDefinition func_lib_def_;
65   ProcessFunctionLibraryRuntime pflr_;
66 };
67 
68 }  // namespace tfrt_stub
69 }  // namespace tensorflow
70 
71 #endif  // TENSORFLOW_CORE_TFRT_FALLBACK_FALLBACK_STATE_H_
72