!27190 update random normal op seed logic

Merge pull request !27190 from zichun_ye/random_normal_seed
This commit is contained in:
i-robot 2021-12-14 06:32:24 +00:00 committed by Gitee
commit 707e53910c
1 changed files with 11 additions and 16 deletions

View File

@ -81,23 +81,18 @@ class RandomOpGpuKernel : public GpuKernel {
switch (random_op_type_) {
case RANDOM_OP_NORMAL: {
float *mask_f = GetDeviceAddress<float>(outputs, 0);
if (!states_init_) {
int RNG_seed = 0;
std::random_device rd;
int RNG_seed = static_cast<int>(rd());
if (seed2_ != 0) {
RNG_seed = seed2_;
} else if (seed_ != 0) {
RNG_seed = seed_;
} else {
RNG_seed = static_cast<int>(rd());
}
CHECK_CURAND_RET_WITH_EXCEPT(curandCreateGenerator(&mask_generator_, CURAND_RNG_PSEUDO_PHILOX4_32_10),
"Failed to create generator");
CHECK_CURAND_RET_WITH_EXCEPT(curandSetPseudoRandomGeneratorSeed(mask_generator_, RNG_seed),
"Failed to SetPseudoRandomGeneratorSeed");
MS_EXCEPTION_IF_NULL(mask_generator_);
states_init_ = true;
}
CHECK_CURAND_RET_WITH_EXCEPT(curandSetStream(mask_generator_, reinterpret_cast<cudaStream_t>(stream_ptr)),
"Failed to set stream for generator");
// curandGen only support float or double for mask.