From 87248281f7ac0bf78712f29bd17ef26941c1fc6d Mon Sep 17 00:00:00 2001 From: Yiqun Liu Date: Thu, 28 Feb 2019 12:09:52 +0800 Subject: [PATCH] Fix error in CUDA kernel of beam_search. (#15957) test=develop --- paddle/fluid/operators/math/beam_search.cu | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/paddle/fluid/operators/math/beam_search.cu b/paddle/fluid/operators/math/beam_search.cu index 61d021ef627..d66778a6fe0 100644 --- a/paddle/fluid/operators/math/beam_search.cu +++ b/paddle/fluid/operators/math/beam_search.cu @@ -119,6 +119,18 @@ __device__ __forceinline__ int SelectTopBeam( __syncthreads(); } + if ((num_used_threads & 0x1) != 0) { + // If num_used_threads is a odd number, merge local top_beam of thread 0 + // and num_used_threads - 1 + if (tid_of_seq == 0) { + int index_in_sh = (num_used_threads - 1 + tid) * beam_size; + for (int i = 0; i < beam_size; i++) { + Insert(top_beam_local, top_beam[index_in_sh], beam_size); + index_in_sh++; + } + } + } + num_used_threads = num_used_threads >> 1; if (tid_of_seq < num_used_threads) { int index_in_sh = (num_used_threads + tid) * beam_size; -- GitLab