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 28 namespace tensorflow { 29 namespace tfrt_stub { 30 31 // FallbackState contains the necessary runtime states (eg. Devices) used in 32 // current tensorflow. It also provides methods used in current tensorflow. 33 class FallbackState { 34 public: 35 // The FunctionDefLibrary is passed in to initialize the 36 // ProcessFunctionLibraryRuntime member of this class 37 static StatusOr<std::unique_ptr<FallbackState>> Create( 38 const SessionOptions &session_options, 39 const tensorflow::FunctionDefLibrary &fdef_lib); 40 41 FallbackState(const SessionOptions &session_options, 42 std::vector<std::unique_ptr<Device>> devices, 43 const tensorflow::FunctionDefLibrary &fdef_lib); 44 45 // Create GraphExecutionState from the `graph_def`. The result will contain a 46 // preprocessed graph with runtime information such as devices. 47 StatusOr<std::unique_ptr<GraphExecutionState>> CreateGraphExecutionState( 48 GraphDef graph_def) const; 49 session_options()50 const SessionOptions &session_options() const { return session_options_; } 51 device_manager()52 const DeviceMgr &device_manager() const { return device_manager_; } 53 device_set()54 const DeviceSet &device_set() const { return device_set_; } 55 process_function_library_runtime()56 const ProcessFunctionLibraryRuntime &process_function_library_runtime() 57 const { 58 return pflr_; 59 } 60 61 private: 62 SessionOptions session_options_; 63 StaticDeviceMgr device_manager_; 64 DeviceSet device_set_; 65 FunctionLibraryDefinition func_lib_def_; 66 ProcessFunctionLibraryRuntime pflr_; 67 }; 68 69 } // namespace tfrt_stub 70 } // namespace tensorflow 71 72 #endif // TENSORFLOW_CORE_TFRT_FALLBACK_FALLBACK_STATE_H_ 73