From 9aa39584feab51a8b92862fcef713477f88deaec Mon Sep 17 00:00:00 2001 From: yaoxuefeng Date: Sat, 5 Sep 2020 15:50:15 +0800 Subject: [PATCH] fix cuda generator hard-coded offset step (#27027) --- paddle/fluid/operators/gaussian_random_op.cu | 12 ++---------- .../fluid/operators/truncated_gaussian_random_op.cu | 6 +----- paddle/fluid/operators/uniform_random_op.cu | 6 +----- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/paddle/fluid/operators/gaussian_random_op.cu b/paddle/fluid/operators/gaussian_random_op.cu index eca42ac581..69c8b60040 100644 --- a/paddle/fluid/operators/gaussian_random_op.cu +++ b/paddle/fluid/operators/gaussian_random_op.cu @@ -71,11 +71,7 @@ class GPUGaussianRandomKernel : public framework::OpKernel { if (gen_cuda->GetIsInitPy() && seed_flag) { auto seed_offset = gen_cuda->IncrementOffset(1); - int offset_step = 100; - // NOTE(xuefeng): Currently, we let offset step fixed to avoid - // unexpected results which may cause ut fail. - // we will fix this in future. - int gen_offset = offset_step * seed_offset.second; + int gen_offset = size * seed_offset.second; thrust::transform( index_sequence_begin, index_sequence_begin + size, thrust::device_ptr(data), @@ -112,11 +108,7 @@ class GPUGaussianRandomBatchSizeLikeKernel : public framework::OpKernel { if (gen_cuda->GetIsInitPy() && seed_flag) { auto seed_offset = gen_cuda->IncrementOffset(1); - int offset_step = 100; - // NOTE(xuefeng): Currently, we let offset step fixed to avoid - // unexpected results which may cause ut fail. - // we will fix this in future. - int gen_offset = offset_step * seed_offset.second; + int gen_offset = size * seed_offset.second; thrust::transform(index_sequence_begin, index_sequence_begin + size, thrust::device_ptr(data), GaussianGenerator(mean, std, seed_offset.first, diff --git a/paddle/fluid/operators/truncated_gaussian_random_op.cu b/paddle/fluid/operators/truncated_gaussian_random_op.cu index ef1e40b46d..a838c30771 100644 --- a/paddle/fluid/operators/truncated_gaussian_random_op.cu +++ b/paddle/fluid/operators/truncated_gaussian_random_op.cu @@ -103,11 +103,7 @@ class GPUTruncatedGaussianRandomKernel : public framework::OpKernel { if (gen_cuda->GetIsInitPy() && seed_flag) { auto seed_offset = gen_cuda->IncrementOffset(1); - int offset_step = 100; - // NOTE(xuefeng): Currently, we let offset step fixed to avoid - // unexpected results which may cause ut fail. - // we will fix this in future. - int gen_offset = offset_step * seed_offset.second; + int gen_offset = size * seed_offset.second; thrust::transform( index_sequence_begin, index_sequence_begin + size, thrust::device_ptr(data), diff --git a/paddle/fluid/operators/uniform_random_op.cu b/paddle/fluid/operators/uniform_random_op.cu index 43a25a098b..6237137ccc 100644 --- a/paddle/fluid/operators/uniform_random_op.cu +++ b/paddle/fluid/operators/uniform_random_op.cu @@ -143,11 +143,7 @@ class GPUUniformRandomKernel : public framework::OpKernel { auto gen_cuda = framework::GetDefaultCUDAGenerator(device_id); if (gen_cuda->GetIsInitPy() && seed_flag) { auto seed_offset = gen_cuda->IncrementOffset(1); - int offset_step = 100; - // NOTE(xuefeng): Currently, we let offset step fixed to avoid - // unexpected results which may cause ut fail. - // we will fix this in future. - int gen_offset = offset_step * seed_offset.second; + int gen_offset = size * seed_offset.second; thrust::transform( index_sequence_begin, index_sequence_begin + size, thrust::device_ptr(data), -- GitLab