• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GRAPPLER_CLUSTERS_VIRTUAL_CLUSTER_H_
17 #define TENSORFLOW_CORE_GRAPPLER_CLUSTERS_VIRTUAL_CLUSTER_H_
18 
19 #include <unordered_map>
20 
21 #include "tensorflow/core/common_runtime/device_set.h"
22 #include "tensorflow/core/grappler/clusters/cluster.h"
23 #include "tensorflow/core/grappler/costs/analytical_cost_estimator.h"
24 #include "tensorflow/core/grappler/costs/op_level_cost_estimator.h"
25 #include "tensorflow/core/grappler/costs/virtual_scheduler.h"
26 #include "tensorflow/core/protobuf/device_properties.pb.h"
27 
28 namespace tensorflow {
29 namespace grappler {
30 
31 // Create a simple cluster that lists the devices (and their properties)
32 // available in a TensorFlow session. This cluster simulates the execution of
33 // actual graphs.
34 class VirtualCluster : public Cluster {
35  public:
36   explicit VirtualCluster(
37       const std::unordered_map<string, DeviceProperties>& devices);
38   VirtualCluster(const std::unordered_map<string, DeviceProperties>& devices,
39                  std::unique_ptr<OpLevelCostEstimator> node_estimator,
40                  std::unique_ptr<ReadyNodeManager> node_manager);
41   explicit VirtualCluster(const DeviceSet* device_set);
42 
43   ~VirtualCluster() override;
44 
type()45   string type() const override { return "virtual"; }
46 
47   Status Provision() override;
48   Status Initialize(const GrapplerItem& item) override;
49   Status Run(const GraphDef& graph,
50              const std::vector<std::pair<string, Tensor>>& feed,
51              const std::vector<string>& fetch, RunMetadata* metadata) override;
52   Status Run(const GrapplerItem& item, RunMetadata* metadata) override;
GetDeviceSet()53   const DeviceSet* GetDeviceSet() const override { return device_set_; }
54 
55  private:
56   std::unique_ptr<AnalyticalCostEstimator> estimator_;
57   const DeviceSet* device_set_ = nullptr;
58 };
59 
60 }  // end namespace grappler
61 }  // end namespace tensorflow
62 
63 #endif  // TENSORFLOW_CORE_GRAPPLER_CLUSTERS_VIRTUAL_CLUSTER_H_
64