From 3acc7726d27e822829f64188d870f0ba473866b2 Mon Sep 17 00:00:00 2001 From: Zichun Ye Date: Fri, 3 Dec 2021 15:52:50 +0800 Subject: [PATCH] update random normal seed logic --- .../gpu/math/random_op_gpu_kernel.h | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h index 876710c5578..a47535f6cff 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/random_op_gpu_kernel.h @@ -81,23 +81,18 @@ class RandomOpGpuKernel : public GpuKernel { switch (random_op_type_) { case RANDOM_OP_NORMAL: { float *mask_f = GetDeviceAddress(outputs, 0); - if (!states_init_) { - int RNG_seed = 0; - std::random_device rd; - if (seed2_ != 0) { - RNG_seed = seed2_; - } else if (seed_ != 0) { - RNG_seed = seed_; - } else { - RNG_seed = static_cast(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; + std::random_device rd; + int RNG_seed = static_cast(rd()); + if (seed2_ != 0) { + RNG_seed = seed2_; + } else if (seed_ != 0) { + RNG_seed = seed_; } + 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_); CHECK_CURAND_RET_WITH_EXCEPT(curandSetStream(mask_generator_, reinterpret_cast(stream_ptr)), "Failed to set stream for generator"); // curandGen only support float or double for mask.