MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / GetOrCreate

Method GetOrCreate

oneflow/core/framework/auto_random_generator.cpp:150–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150Maybe<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

Callers 1

DefaultGeneratorFunction · 0.45

Calls 7

GetFunction · 0.85
findMethod · 0.80
NewFunction · 0.70
endMethod · 0.45
GetDeviceManagerMethod · 0.45
CreateRandomGeneratorMethod · 0.45

Tested by

no test coverage detected