From f48b1264c0b9d68b72e3c7b7417935ce9bb105eb Mon Sep 17 00:00:00 2001 From: limingshu <61349199+JamesLim-sy@users.noreply.github.com> Date: Thu, 15 Sep 2022 14:33:57 +0800 Subject: [PATCH] Performance fix for broadcast kernel [Part3] (#45854) * first commit * fix some bugs in code * fix bugs * to optimize merge one dimension feature --- paddle/phi/kernels/funcs/broadcast_function.h | 8 ++++---- paddle/phi/kernels/primitive/datamover_primitives.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/paddle/phi/kernels/funcs/broadcast_function.h b/paddle/phi/kernels/funcs/broadcast_function.h index 40dfb76586..952ad90fc0 100644 --- a/paddle/phi/kernels/funcs/broadcast_function.h +++ b/paddle/phi/kernels/funcs/broadcast_function.h @@ -213,9 +213,10 @@ struct DimensionsTransform { } } }; - int swap_idx = 0; - bool has_seq_one = FindSequentialOneDim(&swap_idx); - if (has_seq_one) { + for (auto i = 0; i < dim_size; ++i) { + int swap_idx = 0; + bool has_seq_one = FindSequentialOneDim(&swap_idx); + if (!has_seq_one) break; merge_ptr = merge_sequential_one_dims; MergeDimensions(merge_ptr, N); std::swap(in_dims[swap_idx], in_dims[0]); @@ -508,7 +509,6 @@ void BroadcastKernelForDifferentVecSize( "functions is %d.", outs->size(), NumOuts)); - // mergedim and get vec_size const auto merge_dims = DimensionsTransform(ins, (*outs)[0]->dims(), axis); phi::Array configs; diff --git a/paddle/phi/kernels/primitive/datamover_primitives.h b/paddle/phi/kernels/primitive/datamover_primitives.h index 3f6148c7ef..d6139501b4 100644 --- a/paddle/phi/kernels/primitive/datamover_primitives.h +++ b/paddle/phi/kernels/primitive/datamover_primitives.h @@ -85,7 +85,7 @@ struct FastDivMod { struct BroadcastConfig { FastDivMod divmoders[phi::DDim::kMaxRank]; uint32_t strides[phi::DDim::kMaxRank]; - int kDims; + int kDims{0}; HOSTDEVICE BroadcastConfig() {} HOSTDEVICE BroadcastConfig(const std::vector& out_dims, -- GitLab