MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / GetCPURandomEngine

Function GetCPURandomEngine

paddle/phi/core/generator.cc:158–177  ·  view source on GitHub ↗

There are 3 conditions: (1) op seed is set, use op seed. (2) op seed is not set, global seed is set, use global seed. (3) op seed is not set, global seed is not set too, use random seed from RandomGenerator.

Source from the content-addressed store, hash-verified

156// (3) op seed is not set, global seed is not set too, use random seed from
157// RandomGenerator.
158std::shared_ptr<std::mt19937_64> GetCPURandomEngine(uint64_t seed) {
159 if (seed == 0) {
160 VLOG(4) << "Use random cpu_engine from generator";
161 return DefaultCPUGenerator()->GetCPUEngine();
162 } else {
163 // NOTE(zhiqiu): creating an cpu_engine instance everytime instead of using
164 // OpDefaultCPUEngine(), this is the legacy behavior of random operators.
165 // The benefit is that when running PE with fixed-seed in multiple threads,
166 // each thread has their own cpu_engine, and doesn't affect each other.
167 //
168 // And we need to measure the determinacy of Generator in PE.
169 auto cpu_engine = std::make_shared<std::mt19937_64>();
170 static std::mutex mu_;
171 {
172 std::lock_guard<std::mutex> lock(mu_);
173 cpu_engine->seed(seed);
174 }
175 return cpu_engine;
176 }
177}
178
179inline void Generator::print_state_info() {
180 VLOG(7) << "Generator Random state "

Callers 7

UniformRealDistributionFunction · 0.85
operator()Method · 0.85
operator()Method · 0.85
UniformSamplerMethod · 0.85
LogUniformSamplerMethod · 0.85
CustomSamplerMethod · 0.85

Calls 2

GetCPUEngineMethod · 0.80
seedMethod · 0.45

Tested by

no test coverage detected