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.
| 156 | // (3) op seed is not set, global seed is not set too, use random seed from |
| 157 | // RandomGenerator. |
| 158 | std::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 | |
| 179 | inline void Generator::print_state_info() { |
| 180 | VLOG(7) << "Generator Random state " |
no test coverage detected