Returns a set containing the device ids contained in visible_device_list or nullopt if it is empty. It returns error in case of malformed configuration string.
| 33 | // nullopt if it is empty. It returns error in case of malformed configuration |
| 34 | // string. |
| 35 | static xla::StatusOr<absl::optional<std::set<int>>> ParseVisibleDeviceList( |
| 36 | const string& visible_device_list) { |
| 37 | std::set<int> gpu_ids; |
| 38 | if (visible_device_list.empty()) { |
| 39 | return {{absl::nullopt}}; |
| 40 | } |
| 41 | const std::vector<string> visible_devices = |
| 42 | absl::StrSplit(visible_device_list, ','); |
| 43 | for (const string& platform_gpu_id_str : visible_devices) { |
| 44 | int32 platform_gpu_id; |
| 45 | if (!absl::SimpleAtoi(platform_gpu_id_str, &platform_gpu_id)) { |
| 46 | return errors::InvalidArgument( |
| 47 | "Could not parse entry in 'visible_device_list': '", |
| 48 | platform_gpu_id_str, |
| 49 | "'. visible_device_list = ", visible_device_list); |
| 50 | } |
| 51 | gpu_ids.insert(platform_gpu_id); |
| 52 | } |
| 53 | return {{gpu_ids}}; |
| 54 | } |
| 55 | |
| 56 | class XlaGpuDeviceFactory : public DeviceFactory { |
| 57 | public: |
no test coverage detected