tensorflow/core/grappler/optimizers/pin_to_host_optimizer.cc
// Tries to find a Host device from `devices`. Returns empty string if no
// matching Host device is found.
Tries to find a Host device from `devices`. Returns empty string if no
matching Host device is found.
Tries to find a Host device from ` devices ` . Returns empty string if no matching Host device is found .
string TryFindHostDevice(const gtl::FlatSet<string>& devices,
                         bool has_device_cpu, const string& device) {
  if (device.empty() && has_device_cpu) {
    return "/device:CPU:0";
  } else if (absl::StrContains(device, DEVICE_GPU)) {
    for (const auto& device_match :
         {std::pair<string, string>("GPU", "CPU:0"),
          std::pair<string, string>("/device", "/device:CPU:0")}) {
      const string device_host =
          strings::StrCat(device.substr(0, device.rfind(device_match.first)),
                          device_match.second);
      if (devices.find(device_host) != devices.end()) {
        return device_host;
      }
    }
  }
  return "";
}
string TryFindHostDevice ( const gtl :: FlatSet < string > & devices , bool has_device_cpu , const string & device ) { if ( device . empty ( ) && has_device_cpu ) { return " " ; } else if ( absl :: StrContains ( device , DEVICE_GPU ) ) { for ( const auto & device_match : { std :: pair < string , string > ( " " , " " ) , std :: pair < string , string > ( " " , " " ) } ) { const string device_host = strings :: StrCat ( device . substr ( 0 , device . rfind ( device_match . first ) ) , device_match . second ) ; if ( devices . find ( device_host ) != devices . end ( ) ) { return device_host ; } } } return " " ; }
Tries to find a Host device from `devices`.
Tries to find a Host device from ` devices ` .
// Force this node onto the CPU. // Sometimes the cluster can have: //   devices = {"/device:CPU:0", "/device:XLA_GPU:0"} // and we need to handle them properly. // We couldn't find an appropriate Host device, return no device.