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