| 148 | } |
| 149 | |
| 150 | Maybe<ep::RandomGenerator> AutoGenerator::GetOrCreate(const std::string& device, int device_index) { |
| 151 | if (device_index == -1) { device_index = (device == "cpu" ? 0 : GlobalProcessCtx::LocalRank()); } |
| 152 | std::lock_guard<std::mutex> lock(mutex_); |
| 153 | auto device_key = JUST(Device::New(device, device_index)); |
| 154 | auto it = generators_.find(device_key); |
| 155 | if (it == generators_.end()) { |
| 156 | auto device_type = ep::DeviceManagerRegistry::GetDeviceTypeByDeviceTypeName(device); |
| 157 | if (device_type == DeviceType::kInvalidDevice) { |
| 158 | return Error::RuntimeError() << "Expected one of " << PrintGeneratorAvailableDevices() |
| 159 | << " device type at start of device string: " << device; |
| 160 | } |
| 161 | auto device_mgr = Singleton<ep::DeviceManagerRegistry>::Get()->GetDeviceManager(device_type); |
| 162 | it = generators_.emplace(device_key, device_mgr->CreateRandomGenerator(seed_, device_index)) |
| 163 | .first; |
| 164 | } |
| 165 | return it->second; |
| 166 | } |
| 167 | |
| 168 | } // namespace one |
| 169 | } // namespace oneflow |
no test coverage detected