• 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   VirtualCluster(const std::unordered_map<string, DeviceProperties>& devices);
37   VirtualCluster(const std::unordered_map<string, DeviceProperties>& devices,
38                  std::unique_ptr<OpLevelCostEstimator> node_estimator,
39                  std::unique_ptr<ReadyNodeManager> node_manager);
40   VirtualCluster(const DeviceSet* device_set);
41 
42   ~VirtualCluster() override;
43 
type()44   string type() const override { return "virtual"; }
45 
46   Status Provision() override;
47   Status Initialize(const GrapplerItem& item) override;
48   Status Run(const GraphDef& item,
49              const std::vector<std::pair<string, Tensor>>& feed,
50              const std::vector<string>& fetch, RunMetadata* metadata) override;
GetDeviceSet()51   const DeviceSet* GetDeviceSet() const override { return device_set_; }
52 
53  private:
54   std::unique_ptr<AnalyticalCostEstimator> estimator_;
55   const DeviceSet* device_set_ = nullptr;
56 };
57 
58 }  // end namespace grappler
59 }  // end namespace tensorflow
60 
61 #endif  // TENSORFLOW_CORE_GRAPPLER_CLUSTERS_VIRTUAL_CLUSTER_H_
62