| 162 | } |
| 163 | |
| 164 | std::unique_ptr<Device> DeviceFactory::NewDevice(const string& type, |
| 165 | const SessionOptions& options, |
| 166 | const string& name_prefix) { |
| 167 | auto device_factory = GetFactory(type); |
| 168 | if (!device_factory) { |
| 169 | return nullptr; |
| 170 | } |
| 171 | SessionOptions opt = options; |
| 172 | (*opt.config.mutable_device_count())[type] = 1; |
| 173 | std::vector<std::unique_ptr<Device>> devices; |
| 174 | TF_CHECK_OK(device_factory->CreateDevices(opt, name_prefix, &devices)); |
| 175 | int expected_num_devices = 1; |
| 176 | auto iter = options.config.device_count().find(type); |
| 177 | if (iter != options.config.device_count().end()) { |
| 178 | expected_num_devices = iter->second; |
| 179 | } |
| 180 | DCHECK_EQ(devices.size(), static_cast<size_t>(expected_num_devices)); |
| 181 | return std::move(devices[0]); |
| 182 | } |
| 183 | |
| 184 | } // namespace tensorflow |
nothing calls this directly
no test coverage detected