1 /* Copyright 2019 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_COMMON_RUNTIME_EAGER_PROCESS_FUNCTION_LIBRARY_RUNTIME_H_ 16 #define TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_PROCESS_FUNCTION_LIBRARY_RUNTIME_H_ 17 18 #include <memory> 19 #include <unordered_map> 20 21 // clang-format off 22 // Required for IS_MOBILE_PLATFORM 23 #include "tensorflow/core/platform/platform.h" 24 // clang-format on 25 26 #include "tensorflow/core/common_runtime/device_mgr.h" 27 #include "tensorflow/core/common_runtime/process_function_library_runtime.h" 28 #include "tensorflow/core/lib/gtl/array_slice.h" 29 #if !defined(IS_MOBILE_PLATFORM) 30 #include "tensorflow/core/protobuf/remote_tensor_handle.pb.h" 31 #endif // IS_MOBILE_PLATFORM 32 33 namespace tensorflow { 34 namespace eager { 35 36 // A ProcessFunctionLibraryRuntime which supports running functions with inputs 37 // on remote devices. 38 // TODO(b/134094971): Support outputting tensors on remote devices. 39 class EagerProcessFunctionLibraryRuntime 40 : public ProcessFunctionLibraryRuntime { 41 public: 42 EagerProcessFunctionLibraryRuntime( 43 const DeviceMgr* device_mgr, Env* env, const ConfigProto* config, 44 int graph_def_version, const FunctionLibraryDefinition* lib_def, 45 const OptimizerOptions& optimizer_options, 46 thread::ThreadPool* thread_pool = nullptr, 47 DistributedFunctionLibraryRuntime* parent = nullptr, 48 const CustomKernelCreator* custom_kernel_creator = nullptr) ProcessFunctionLibraryRuntime(device_mgr,env,config,graph_def_version,lib_def,optimizer_options,thread_pool,parent,custom_kernel_creator)49 : ProcessFunctionLibraryRuntime( 50 device_mgr, env, config, graph_def_version, lib_def, 51 optimizer_options, thread_pool, parent, custom_kernel_creator) {} 52 53 #if !defined(IS_MOBILE_PLATFORM) 54 void Run(const FunctionLibraryRuntime::Options& opts, 55 FunctionLibraryRuntime::Handle handle, 56 const FunctionArgsInterface& args, std::vector<Tensor>* rets, 57 FunctionLibraryRuntime::DoneCallback done) const override; 58 59 private: 60 void RunRemoteDevice( 61 const FunctionLibraryRuntime::Options& opts, 62 FunctionLibraryRuntime::Handle local_handle, const InternalArgsView& args, 63 std::vector<Tensor>* rets, 64 FunctionLibraryRuntime::DoneCallback done) const override; 65 #endif // IS_MOBILE_PLATFORM 66 }; 67 68 } // namespace eager 69 } // namespace tensorflow 70 71 #endif // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_PROCESS_FUNCTION_LIBRARY_RUNTIME_H_ 72