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_COSTS_VIRTUAL_PLACER_H_ 17 #define TENSORFLOW_CORE_GRAPPLER_COSTS_VIRTUAL_PLACER_H_ 18 19 #include "tensorflow/core/platform/types.h" 20 #include "tensorflow/core/protobuf/device_properties.pb.h" 21 22 namespace tensorflow { 23 class NodeDef; 24 25 namespace grappler { 26 class Cluster; 27 28 // The virtual placer emulates the behavior of the TF placer. 29 class VirtualPlacer { 30 public: 31 VirtualPlacer(const Cluster* cluster); 32 33 const DeviceProperties& get_device(const NodeDef& node) const; 34 35 // Returns device name from cluster, which best matches the node.device() 36 // specification. Returns default device if no match was found or the 37 // node.device() could not be parsed. 38 string get_canonical_device_name(const NodeDef& node) const; 39 40 private: 41 // Converts given device name to Lowercase Fully-Qualified Name (LFQN) string. 42 // This helps us disambiguate device names internally and simplify matching. 43 // If device_name couldn't be parsed successfully, returns empty string. 44 string to_lfqn_or_empty(const string& device_name) const; 45 46 // Map based on the cluster info: cluster device name -> device properties. 47 std::unordered_map<string, DeviceProperties> devices_; 48 49 // Maps LFQN to original device name as it was declared in cluster. 50 std::unordered_map<string, string> lfqn_map_; 51 52 string default_device_name_; 53 string default_job_name_lowercase_; 54 }; 55 56 } // namespace grappler 57 } // end namespace tensorflow 58 59 #endif // TENSORFLOW_CORE_GRAPPLER_COSTS_VIRTUAL_PLACER_H_ 60