• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 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_COMMON_RUNTIME_GRAPH_RUNNER_H_
17 #define TENSORFLOW_CORE_COMMON_RUNTIME_GRAPH_RUNNER_H_
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "tensorflow/core/common_runtime/device.h"
24 #include "tensorflow/core/framework/function.h"
25 #include "tensorflow/core/framework/tensor.h"
26 #include "tensorflow/core/graph/graph.h"
27 #include "tensorflow/core/lib/core/status.h"
28 #include "tensorflow/core/platform/env.h"
29 
30 namespace tensorflow {
31 
32 // GraphRunner takes a Graph, some inputs to feed, and some outputs
33 // to fetch and executes the graph required to feed and fetch the
34 // inputs and outputs.
35 //
36 // This class is only meant for internal use where one needs to
37 // partially evaluate inexpensive nodes in a graph, such as for shape
38 // inference or for constant folding.  Because of its limited, simple
39 // use-cases, it executes all computation on the given device (CPU by default)
40 // and is not meant to be particularly lightweight, fast, or efficient.
41 class GraphRunner {
42  public:
43   // REQUIRES: `env` is not nullptr.
44   GraphRunner(Env* env);
45   // REQUIRES: 'device' is not nullptr. Not owned.
46   GraphRunner(Device* device);
47   ~GraphRunner();
48 
49   // Function semantics for `inputs`, `output_names` and `outputs`
50   // matches those from Session::Run().
51   //
52   // NOTE: The output tensors share lifetime with the GraphRunner, and could
53   // be destroyed once the GraphRunner is destroyed.
54   //
55   // REQUIRES: `graph`, `env`, and `outputs` are not nullptr.
56   // `function_library` may be nullptr.
57   typedef std::vector<std::pair<string, Tensor>> NamedTensorList;
58   Status Run(Graph* graph, FunctionLibraryRuntime* function_library,
59              const NamedTensorList& inputs,
60              const std::vector<string>& output_names,
61              std::vector<Tensor>* outputs);
62 
63  private:
64   std::unique_ptr<Device> device_deleter_;
65   Device* const device_;
66 };
67 
68 }  // namespace tensorflow
69 
70 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_GRAPH_RUNNER_H_
71