| 349 | |
| 350 | template <class Map> |
| 351 | Status LookupDevice(const DeviceSet& device_set, const string& tensor_name, |
| 352 | const Map& tensor2device, |
| 353 | const tensorflow::DeviceAttributes** out_device_attrs) { |
| 354 | *out_device_attrs = nullptr; |
| 355 | if (tensor2device.empty()) { |
| 356 | *out_device_attrs = &device_set.client_device()->attributes(); |
| 357 | return Status::OK(); |
| 358 | } |
| 359 | const auto it = tensor2device.find(tensor_name); |
| 360 | if (it == tensor2device.end()) { |
| 361 | *out_device_attrs = &device_set.client_device()->attributes(); |
| 362 | return Status::OK(); |
| 363 | } |
| 364 | DeviceNameUtils::ParsedName parsed_name; |
| 365 | if (!DeviceNameUtils::ParseFullName(it->second, &parsed_name)) { |
| 366 | return errors::InvalidArgument("Invalid device name ('", it->second, |
| 367 | "') provided for the tensor '", tensor_name, |
| 368 | "' in CallableOptions"); |
| 369 | } |
| 370 | Device* device = device_set.FindDeviceByName( |
| 371 | DeviceNameUtils::ParsedNameToString(parsed_name)); |
| 372 | if (device == nullptr) { |
| 373 | return errors::InvalidArgument("Device '", it->second, |
| 374 | "' specified for tensor '", tensor_name, |
| 375 | "' in CallableOptions does not exist"); |
| 376 | } |
| 377 | *out_device_attrs = &device->attributes(); |
| 378 | return Status::OK(); |
| 379 | } |
| 380 | |
| 381 | struct TensorAndDevice { |
| 382 | // WARNING: backing memory for the 'tensor' field is NOT owend. |
no test coverage detected