1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 vcyou 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_CORE_KERNELS_I_REMOTE_GRAPH_EXECUTOR_H_ 17 #define TENSORFLOW_CORE_KERNELS_I_REMOTE_GRAPH_EXECUTOR_H_ 18 19 #include "tensorflow/core/framework/remote_fused_graph_execute_info.pb.h" 20 #include "tensorflow/core/framework/tensor.h" 21 #include "tensorflow/core/framework/types.h" 22 #include "tensorflow/core/platform/macros.h" 23 24 namespace tensorflow { 25 26 class IRemoteFusedGraphExecutor { 27 public: 28 using TensorAllocatorFunc = std::function<Tensor*(const TensorShape& shape)>; 29 30 IRemoteFusedGraphExecutor() = default; 31 virtual ~IRemoteFusedGraphExecutor() = default; 32 33 // Return version of executor. 34 // This function is mainly for a debug purpose to verify version of 35 // executor info. 36 virtual int GetVersion() = 0; 37 38 // Initialize executor. This function is called before 39 // starting graph transfer. 40 virtual bool Init(const RemoteFusedGraphExecuteInfo& info) = 0; 41 42 // Finalize executor. This function is called when all graph executions 43 // are finished. 44 virtual bool Finalize() = 0; 45 46 // Setup graph 47 virtual bool SetupGraph() = 0; 48 49 // Execute graph 50 virtual bool ExecuteGraph() = 0; 51 52 // Teardown Graph 53 virtual bool TeardownGraph() = 0; 54 55 // Fill input node's output with Tensor 56 virtual bool FillInputNode(const string& node_name, const Tensor& tensor) = 0; 57 58 // Read output node's outputs as ByteArrays 59 virtual bool ReadOutputNode(const string& node_name, 60 TensorAllocatorFunc tensor_allocator) = 0; 61 62 virtual Status FuseRemoteGraph(const GraphDef& original_graph_def, 63 const std::vector<string>& inputs, 64 const std::vector<string>& outputs, 65 GraphDef* fused_graph_def) = 0; 66 67 virtual bool IsEnabled() const = 0; 68 69 private: 70 TF_DISALLOW_COPY_AND_ASSIGN(IRemoteFusedGraphExecutor); 71 }; 72 73 } // namespace tensorflow 74 75 #endif // TENSORFLOW_CORE_KERNELS_I_REMOTE_GRAPH_EXECUTOR_H_ 76