From 64f7516aee218bf5a079fcdeae8fbec3dcca33fe Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Fri, 16 Nov 2018 10:22:40 +0800 Subject: [PATCH] fix lrn on mac (#14426) * rename and fix blas vsqr test=develop * update --- paddle/fluid/operators/lrn_op.cc | 2 +- paddle/fluid/operators/math/blas.h | 6 +++--- paddle/fluid/operators/math/blas_impl.h | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/operators/lrn_op.cc b/paddle/fluid/operators/lrn_op.cc index 8994f27086..a3bb2be5c7 100644 --- a/paddle/fluid/operators/lrn_op.cc +++ b/paddle/fluid/operators/lrn_op.cc @@ -46,7 +46,7 @@ struct LRNFunctor { int pre_pad = (n - 1) / 2; // compute batches one by one for (int i = 0; i < N; ++i) { - blas.VSQR(fea_size, idata + i * fea_size, sdata + pre_pad * img_size); + blas.VSQUARE(fea_size, idata + i * fea_size, sdata + pre_pad * img_size); // init the first channel of mid for (int c = 0; c < n; ++c) { blas.AXPY(img_size, alpha, sdata + c * img_size, mdata + i * fea_size); diff --git a/paddle/fluid/operators/math/blas.h b/paddle/fluid/operators/math/blas.h index 5d0d562030..6734df1530 100644 --- a/paddle/fluid/operators/math/blas.h +++ b/paddle/fluid/operators/math/blas.h @@ -153,7 +153,7 @@ class Blas { void VEXP(int n, const T* x, T* y) const; template - void VSQR(int n, const T* x, T* y) const; + void VSQUARE(int n, const T* x, T* y) const; template void VPOW(int n, const T* x, T alpha, T* y) const; @@ -245,8 +245,8 @@ class BlasT : private Blas { } template - void VSQR(ARGS... args) const { - Base()->template VSQR(args...); + void VSQUARE(ARGS... args) const { + Base()->template VSQUARE(args...); } template diff --git a/paddle/fluid/operators/math/blas_impl.h b/paddle/fluid/operators/math/blas_impl.h index 59454669be..93bf7c7c88 100644 --- a/paddle/fluid/operators/math/blas_impl.h +++ b/paddle/fluid/operators/math/blas_impl.h @@ -105,7 +105,7 @@ struct CBlas { } template - static void VSQR(ARGS... args) { + static void VSQUARE(ARGS... args) { platform::dynload::vsSqr(args...); } @@ -195,7 +195,7 @@ struct CBlas { } template - static void VSQR(ARGS... args) { + static void VSQUARE(ARGS... args) { platform::dynload::vdSqr(args...); } @@ -262,7 +262,9 @@ struct CBlas { } static void VMUL(...) { PADDLE_THROW("float16 VMUL not supported on CPU"); } static void VEXP(...) { PADDLE_THROW("float16 VEXP not supported on CPU"); } - static void VSQR(...) { PADDLE_THROW("float16 VSQR not supported on CPU"); } + static void VSQUARE(...) { + PADDLE_THROW("float16 VSQUARE not supported on CPU"); + } static void VPOW(...) { PADDLE_THROW("float16 VPOW not supported on CPU"); } static void DOT(...) { PADDLE_THROW("float16 DOT not supported on CPU"); }; static void SCAL(...) { PADDLE_THROW("float16 SCAL not supported on CPU"); }; @@ -423,12 +425,12 @@ void Blas::VEXP(int n, const T *x, T *y) const { template <> template -void Blas::VSQR(int n, const T *x, T *y) const { +void Blas::VSQUARE(int n, const T *x, T *y) const { #ifdef PADDLE_WITH_MKLML - CBlas::VSQR(n, x, y); + CBlas::VSQUARE(n, x, y); #else for (int i = 0; i < n; ++i) { - y[i] = std::sqrt(x[i]); + y[i] = x[i] * x[i]; } #endif } -- GitLab