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

Function MakeGenerator

oneflow/core/framework/random_generator.cpp:196–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196Maybe<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
211Maybe<Generator> DefaultGenerator(DeviceType device, int device_index) {
212 return DefaultGenerator(*JUST(DeviceTag4DeviceType(device)), device_index);

Callers 11

CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateOpKernelStateMethod · 0.85
CreateGeneratorFunction · 0.85

Calls 5

GetFunction · 0.85
DeviceTag4DeviceTypeFunction · 0.85
GetDeviceManagerMethod · 0.45
CreateRandomGeneratorMethod · 0.45

Tested by

no test coverage detected