diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cu b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cu index 4c88916515..6f6f606c8e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cu +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cu @@ -46,12 +46,13 @@ __global__ void UniformRealKernel(int seed, curandState *globalState, T *output, template void StandardNormal(int seed, int seed2, curandState *globalState, T *output, size_t count, cudaStream_t cuda_stream) { int RNG_seed = 0; + std::random_device rd; if (seed2 != 0) { RNG_seed = seed2; } else if (seed != 0) { RNG_seed = seed; } else { - RNG_seed = time(NULL); + RNG_seed = static_cast(rd()); } NormalKernel<<>>(RNG_seed, globalState, output, count); return; @@ -61,12 +62,13 @@ template void UniformInt(int seed, int seed2, curandState *globalState, T *input1, size_t input_size_1, T *input2, size_t input_size_2, T *output, size_t count, cudaStream_t cuda_stream) { int RNG_seed = 0; + std::random_device rd; if (seed2 != 0) { RNG_seed = seed2; } else if (seed != 0) { RNG_seed = seed; } else { - RNG_seed = time(NULL); + RNG_seed = static_cast(rd()); } UniformIntKernel<<>> (RNG_seed, globalState, input1, input_size_1, input2, input_size_2, output, count); @@ -76,12 +78,13 @@ void UniformInt(int seed, int seed2, curandState *globalState, T *input1, size_t template void UniformReal(int seed, int seed2, curandState *globalState, T *output, size_t count, cudaStream_t cuda_stream) { int RNG_seed = 0; + std::random_device rd; if (seed2 != 0) { RNG_seed = seed2; } else if (seed != 0) { RNG_seed = seed; } else { - RNG_seed = time(NULL); + RNG_seed = static_cast(rd()); } UniformRealKernel<<>>(RNG_seed, globalState, output, count); return; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cuh b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cuh index 9c51304bb6..cd778d9bf7 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cuh +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/random_op_impl.cuh @@ -18,6 +18,7 @@ #define MINDSPORE_CCSRC_KERNEL_GPU_CUDA_IMPL_RANDOMOPIMPL_H_ #include +#include #include "runtime/device/gpu/cuda_common.h" template