From 1412d3bc2f731f33279c27b229e84b804e247760 Mon Sep 17 00:00:00 2001 From: arlesniak Date: Fri, 9 Jul 2021 11:09:32 +0200 Subject: [PATCH] Use CBLAS for SelectedRows elementwise add operation. (#34008) * Use CBLAS for SelectedRows elementwise add operation. It's faster. * template compilation fix * reverted template compilation fix * slimmed template compilation fix Co-authored-by: Adam Osewski --- .../operators/math/selected_rows_functor.cc | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/paddle/fluid/operators/math/selected_rows_functor.cc b/paddle/fluid/operators/math/selected_rows_functor.cc index a72bdec05d7..757cac4e4ff 100644 --- a/paddle/fluid/operators/math/selected_rows_functor.cc +++ b/paddle/fluid/operators/math/selected_rows_functor.cc @@ -300,33 +300,26 @@ template struct SelectedRowsAddToTensor -typename std::enable_if::value || - std::is_same::value>::type +typename std::enable_if::value>::type elementwise_add_to(BlasT* blas, size_t data_len, const T* in, T* out) { +#ifdef PADDLE_WITH_MKLDNN onednn_handler_axpy(data_len, T(1.f), in, out); -} - -template -typename std::enable_if::value || - std::is_same>::value || - std::is_same>::value>::type -elementwise_add_to(BlasT* blas, size_t data_len, - const T* in, T* out) { +#else blas->AXPY(data_len, T(1.f), in, out); +#endif } -#else + template -typename std::enable_if::value || +typename std::enable_if::value || + std::is_same::value || std::is_same>::value || std::is_same>::value>::type elementwise_add_to(BlasT* blas, size_t data_len, const T* in, T* out) { blas->AXPY(data_len, T(1.f), in, out); } -#endif template typename std::enable_if::value>::type elementwise_add_to( -- GitLab