Home | History | Annotate | Download | only in kernels
      1 /* Copyright 2017 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 
     16 #ifndef TENSORFLOW_CORE_KERNELS_REMOTE_FUSED_GRAPH_EXECUTE_OP_TEST_UTILS_H_
     17 #define TENSORFLOW_CORE_KERNELS_REMOTE_FUSED_GRAPH_EXECUTE_OP_TEST_UTILS_H_
     18 
     19 #include "tensorflow/cc/framework/ops.h"
     20 #include "tensorflow/cc/framework/scope.h"
     21 #include "tensorflow/core/framework/types.h"
     22 #include "tensorflow/core/kernels/i_remote_fused_graph_executor.h"
     23 #include "tensorflow/core/platform/macros.h"
     24 
     25 namespace tensorflow {
     26 
     27 // RemoteFusedGraphExecuteOpTestUtils is a set of utilities in tests for
     28 // RemoteFusedGraphExecuteOp.
     29 class RemoteFusedGraphExecuteOpTestUtils {
     30  public:
     31   static Output BuildAddOp(const Scope& scope, const Input& x, const Input& y);
     32   static Status BuildAddGraph(const string& name0, const float val0,
     33                               const string& name1, const float val1,
     34                               const string& name_out, GraphDef* graph_def);
     35 
     36   // BuildMultipleAddGraph builds the following graph
     37   //
     38   //  A         B         C         D         E
     39   //  |         |         |         |         |
     40   //  +----+----+         |         +----+----+
     41   //       |              |              |
     42   //       F             / \             G
     43   //       |            |   |           / \
     44   //       +-----+------+   +-----+----+   +
     45   //             |                |        |
     46   //             H                I        |
     47   //             |                |        |
     48   //             +-------+--------+        |
     49   //                     |                 |
     50   //                     J                 |
     51   //                     |                 |
     52   //                     +--------+--------+
     53   //                              |
     54   //                              K
     55   //
     56   static Status BuildMultipleAddGraph(GraphDef* graph_def);
     57 
     58  private:
     59   RemoteFusedGraphExecuteOpTestUtils() = delete;
     60   TF_DISALLOW_COPY_AND_ASSIGN(RemoteFusedGraphExecuteOpTestUtils);
     61 };
     62 
     63 class TestRemoteFusedGraphExecutor final : public IRemoteFusedGraphExecutor {
     64  public:
     65   TestRemoteFusedGraphExecutor(const std::unordered_set<string>& fused_op_types,
     66                                const string& executor_name);
     67 
     68   int GetVersion() final;
     69   bool Init(const RemoteFusedGraphExecuteInfo&) final;
     70   bool Finalize() final;
     71   bool SetupGraph() final;
     72   bool ExecuteGraph() final;
     73   bool TeardownGraph() final;
     74   bool FillInputNode(const string&, const Tensor&) final;
     75   bool ReadOutputNode(const string&, TensorAllocatorFunc) final;
     76   Status FuseRemoteGraph(const GraphDef& original_graph_def,
     77                          const std::vector<string>& inputs,
     78                          const std::vector<string>& outputs,
     79                          GraphDef* fused_graph_def) final;
     80   bool IsEnabled() const final;
     81 
     82  private:
     83   const std::unordered_set<string> fused_op_types_;
     84   const string executor_name_;
     85 };
     86 
     87 }  // namespace tensorflow
     88 
     89 #endif  // TENSORFLOW_CORE_KERNELS_REMOTE_FUSED_GRAPH_EXECUTE_OP_TEST_UTILS_H_
     90