diff --git a/paddle/phi/kernels/gpu/unique_kernel.cu b/paddle/phi/kernels/gpu/unique_kernel.cu index 70fa67b851392..59501150d6479 100644 --- a/paddle/phi/kernels/gpu/unique_kernel.cu +++ b/paddle/phi/kernels/gpu/unique_kernel.cu @@ -388,9 +388,11 @@ static void ComputeUniqueDims(const Context& context, // 3. counts: 'counts' counts->Resize(common::make_ddim({num_out})); auto* count_data = context.template Alloc(counts); - thrust::fill(exec_policy, count_data, count_data + row, 0); - thrust::adjacent_difference( - exec_policy, range_data_ptr + 1, range_data_ptr + row + 1, count_data); + thrust::fill(exec_policy, count_data, count_data + num_out, 0); + thrust::adjacent_difference(exec_policy, + range_data_ptr + 1, + range_data_ptr + num_out + 1, + count_data); } // Calculate unique when 'axis' is set