From 0c40d889c65416d163e2f2096953cdae6f348332 Mon Sep 17 00:00:00 2001 From: Li Min <11663212+limin2021@users.noreply.github.com> Date: Thu, 15 Sep 2022 11:26:10 +0800 Subject: [PATCH] add determine action for embed_grad and index_add. (#46040) --- paddle/phi/kernels/gpu/embedding_grad_kernel.cu | 7 +++++++ paddle/phi/kernels/gpu/index_add_kernel.cu | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/paddle/phi/kernels/gpu/embedding_grad_kernel.cu b/paddle/phi/kernels/gpu/embedding_grad_kernel.cu index f11fd0191b9..6694216214c 100644 --- a/paddle/phi/kernels/gpu/embedding_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/embedding_grad_kernel.cu @@ -23,6 +23,8 @@ #include "paddle/phi/kernels/funcs/eigen/common.h" #include "paddle/phi/kernels/funcs/embedding_util.h" +DECLARE_bool(cudnn_deterministic); + namespace phi { template @@ -101,6 +103,11 @@ struct EmbeddingGradCUDAFunctor { const int gridx = 2 * dev_ctx_.GetSMCount(); dim3 threads(128, 8); dim3 grids(gridx, 1); + + if (FLAGS_cudnn_deterministic) { + VLOG(2) << "Run grad kernel of embedding with single thread."; + grids.x = 1; + } EmbeddingGrad<<>>( d_table, d_output, ids, N, K, D); } diff --git a/paddle/phi/kernels/gpu/index_add_kernel.cu b/paddle/phi/kernels/gpu/index_add_kernel.cu index 9783687ba5f..ff8fb170207 100644 --- a/paddle/phi/kernels/gpu/index_add_kernel.cu +++ b/paddle/phi/kernels/gpu/index_add_kernel.cu @@ -20,6 +20,8 @@ #include "paddle/phi/core/kernel_registry.h" #include "paddle/phi/core/utils/data_type.h" +DECLARE_bool(cudnn_deterministic); + namespace phi { using paddle::platform::PADDLE_CUDA_NUM_THREADS; @@ -79,6 +81,12 @@ void IndexAddKernel(const Context& ctx, // todo(@limin29): inplace do not need copy. phi::Copy(ctx, x, ctx.GetPlace(), false, output); + if (FLAGS_cudnn_deterministic) { + VLOG(2) << "Run grad kernel of index_add with single thread."; + block_dim = 1; + grid_dim.x = 1; + } + if (index_type == phi::DataType::INT64) { const int64_t* index_data = index.data(); index_add_cuda_kernel -- GitLab