| 194 | } |
| 195 | |
| 196 | Maybe<Generator> MakeGenerator(const std::string& device, int device_index) { |
| 197 | if (device == "auto") { |
| 198 | return std::make_shared<Generator>(std::make_shared<AutoGenerator>(default_rng_seed_val)); |
| 199 | } |
| 200 | auto device_type = ep::DeviceManagerRegistry::GetDeviceTypeByDeviceTypeName(device); |
| 201 | if (device_type == DeviceType::kInvalidDevice) { |
| 202 | return Error::RuntimeError() << "Expected one of " << PrintGeneratorAvailableDevices() |
| 203 | << " device type at start of device string: " << device; |
| 204 | } |
| 205 | auto device_mgr = Singleton<ep::DeviceManagerRegistry>::Get()->GetDeviceManager(device_type); |
| 206 | if (device_index == -1) { device_index = (device == "cpu" ? 0 : GlobalProcessCtx::LocalRank()); } |
| 207 | return std::make_shared<Generator>( |
| 208 | device_mgr->CreateRandomGenerator(default_rng_seed_val, device_index)); |
| 209 | } |
| 210 | |
| 211 | Maybe<Generator> DefaultGenerator(DeviceType device, int device_index) { |
| 212 | return DefaultGenerator(*JUST(DeviceTag4DeviceType(device)), device_index); |
no test coverage detected