diff --git a/paddle/fluid/operators/jit/helper.cc b/paddle/fluid/operators/jit/helper.cc index fe508788efe7e880a2e0b64e3a57351e982de2f0..f868c847bd80e874da2d2babde58129122e0bc70 100644 --- a/paddle/fluid/operators/jit/helper.cc +++ b/paddle/fluid/operators/jit/helper.cc @@ -56,7 +56,7 @@ const char* to_string(KernelType kt) { ONE_CASE(kMatMul); ONE_CASE(kHMax); ONE_CASE(kHSum); - ONE_CASE(kStrideSum); + ONE_CASE(kStrideASum); ONE_CASE(kSoftmax); ONE_CASE(kEmbSeqPool); ONE_CASE(kSgd); diff --git a/paddle/fluid/operators/jit/kernel_base.h b/paddle/fluid/operators/jit/kernel_base.h index 6fd8a59d55926e38fc5dd8a538e06c5f3834c34e..fdd41a830a2ca4337091faf2dc412f36c036974c 100644 --- a/paddle/fluid/operators/jit/kernel_base.h +++ b/paddle/fluid/operators/jit/kernel_base.h @@ -53,7 +53,7 @@ typedef enum { kVSquare, kVSub, kVTanh, - kStrideSum, + kStrideASum, kStrideScal, } KernelType; @@ -132,7 +132,7 @@ DECLARE_KERNELTUPLE(XYNTuple, VCopy); DECLARE_KERNELTUPLE(XRNTuple, HMax); DECLARE_KERNELTUPLE(XRNTuple, HSum); -DECLARE_KERNELTUPLE(XRNSTuple, StrideSum); +DECLARE_KERNELTUPLE(XRNSTuple, StrideASum); typedef struct { void* gates; // gates: x_ch, x_ih, x_fh, x_oh diff --git a/paddle/fluid/operators/jit/more/mix/mix.cc b/paddle/fluid/operators/jit/more/mix/mix.cc index 58a44d4b55c30dc98e755466ff7f92c43fa5d206..463e45f6ce1bc8f9085e8efe05ae53486242b181 100644 --- a/paddle/fluid/operators/jit/more/mix/mix.cc +++ b/paddle/fluid/operators/jit/more/mix/mix.cc @@ -54,7 +54,7 @@ void Softmax(const T* x, T* y, int n, int bs, int m) { auto compute_hmax = KernelFuncs, CPUPlace>::Cache().At(n); auto compute_hsum = KernelFuncs, CPUPlace>::Cache().At(n); auto compute_vscal = KernelFuncs, CPUPlace>::Cache().At(n); - auto compute_stridesum = KernelFuncs, CPUPlace>::Cache().At(n); + auto compute_stridesum = KernelFuncs, CPUPlace>::Cache().At(n); auto compute_stridescal = KernelFuncs, CPUPlace>::Cache().At(n); auto compute_vaddbias = KernelFuncs, CPUPlace>::Cache().At(n); diff --git a/paddle/fluid/operators/jit/more/mkl/mkl.cc b/paddle/fluid/operators/jit/more/mkl/mkl.cc index 2828d758159df1ecc97f9b05f3298cc1bc847842..9e21e2b8d39c4827e78c63f9dcf6a08f9be67cf9 100644 --- a/paddle/fluid/operators/jit/more/mkl/mkl.cc +++ b/paddle/fluid/operators/jit/more/mkl/mkl.cc @@ -147,12 +147,12 @@ void ASum(const double* x, double* res, int n) { } template <> -void StrideSum(const float* x, float* res, int n, int stride) { +void StrideASum(const float* x, float* res, int n, int stride) { res[0] = platform::dynload::cblas_sasum(n, x, stride); } template <> -void StrideSum(const double* x, double* res, int n, int stride) { +void StrideASum(const double* x, double* res, int n, int stride) { res[0] = platform::dynload::cblas_dasum(n, x, stride); } @@ -174,7 +174,7 @@ bool VScalKernel::CanBeUsed(const int& d) const { template <> bool StrideScalKernel::CanBeUsed(const int& d) const { - return platform::MayIUse(platform::avx512f) && d > 512; + return true; } template <> diff --git a/paddle/fluid/operators/jit/more/mkl/mkl.h b/paddle/fluid/operators/jit/more/mkl/mkl.h index 1e974c095fb4e8387ee9e9334e638f1b1d997e92..2f135f9e7a4a1fae903ff239d6328fd5ee717b12 100644 --- a/paddle/fluid/operators/jit/more/mkl/mkl.h +++ b/paddle/fluid/operators/jit/more/mkl/mkl.h @@ -129,7 +129,7 @@ template void ASum(const T* x, T* res, int n); template -void StrideSum(const T* x, T* res, int n, int stride); +void StrideASum(const T* x, T* res, int n, int stride); template void StrideScal(const T* a, const T* x, T* y, int n, int stride); @@ -155,7 +155,7 @@ void Softmax(const T* x, T* y, int n, int bs, int m=1) { VScal(&sum, &y[i * n], &y[i * n], n); } else { for (int j = 0; j < m; ++j) { - StrideSum(&y[i * n + j], &sum, n/m, m); + StrideASum(&y[i * n + j], &sum, n/m, m); sum = static_cast(1) / sum; StrideScal(&sum, &y[i * n + j], &y[i * n + j], n/m, m); } diff --git a/paddle/fluid/operators/jit/refer/CMakeLists.txt b/paddle/fluid/operators/jit/refer/CMakeLists.txt index 9a39809c9356cb9a68a5b8113f7d66074dd2e882..7133f596620410d37ffe52a2ee92b7a9974bf1cc 100644 --- a/paddle/fluid/operators/jit/refer/CMakeLists.txt +++ b/paddle/fluid/operators/jit/refer/CMakeLists.txt @@ -33,7 +33,7 @@ USE_JITKERNEL_REFER(kMatMul) USE_JITKERNEL_REFER(kVSquare) USE_JITKERNEL_REFER(kHSum) USE_JITKERNEL_REFER(kHMax) -USE_JITKERNEL_REFER(kStrideSum) +USE_JITKERNEL_REFER(kStrideASum) USE_JITKERNEL_REFER(kSoftmax) USE_JITKERNEL_REFER(kEmbSeqPool) USE_JITKERNEL_REFER(kSgd) diff --git a/paddle/fluid/operators/jit/refer/refer.cc b/paddle/fluid/operators/jit/refer/refer.cc index 704124e805a0efc62fc6d63a22bb31fa8e75cf0b..460cb6c58076d7f6c49b60fed45584bd9b506c63 100644 --- a/paddle/fluid/operators/jit/refer/refer.cc +++ b/paddle/fluid/operators/jit/refer/refer.cc @@ -52,7 +52,7 @@ REGISTER_REFER_KERNEL(SeqPool); REGISTER_REFER_KERNEL(MatMul); REGISTER_REFER_KERNEL(HMax); REGISTER_REFER_KERNEL(HSum); -REGISTER_REFER_KERNEL(StrideSum); +REGISTER_REFER_KERNEL(StrideASum); REGISTER_REFER_KERNEL(Softmax); REGISTER_REFER_KERNEL(EmbSeqPool); REGISTER_REFER_KERNEL(Sgd); diff --git a/paddle/fluid/operators/jit/refer/refer.h b/paddle/fluid/operators/jit/refer/refer.h index dee9245524b492b422805177189dc810cfd58b67..e3387f60a6ec798130a894751cfbec0526243b64 100644 --- a/paddle/fluid/operators/jit/refer/refer.h +++ b/paddle/fluid/operators/jit/refer/refer.h @@ -412,10 +412,10 @@ void HSum(const T* x, T* res, int n) { } template -void StrideSum(const T* x, T* res, int n, int stride) { +void StrideASum(const T* x, T* res, int n, int stride) { res[0] = x[0]; for (int i = stride; i < n; i+=stride) { - res[0] += x[i]; + res[0] += std::abs(x[i]); } } @@ -442,7 +442,7 @@ void Softmax(const T* x, T* y, int n, int bs = 1, int m = 1) { VScal(&scalar, y, y, n); } else { for (int j = 0; j < m; j++) { - StrideSum(&y[j], &scalar, n, m); + StrideASum(&y[j], &scalar, n, m); scalar = static_cast(1) / scalar; StrideScal(&scalar, &y[j], &y[j], n, m); } @@ -554,7 +554,7 @@ DECLARE_REFER_KERNEL(GRUHtPart2); DECLARE_REFER_KERNEL(HMax); DECLARE_REFER_KERNEL(HSum); -DECLARE_REFER_KERNEL(StrideSum); +DECLARE_REFER_KERNEL(StrideASum); // others DECLARE_REFER_KERNEL(CRFDecoding); diff --git a/paddle/fluid/operators/jit/test.cc b/paddle/fluid/operators/jit/test.cc index 93a448166fa932878b36967419121e6c38d7c2cd..c47ec01d3e01d2a348a226798d0985b3c193a99a 100644 --- a/paddle/fluid/operators/jit/test.cc +++ b/paddle/fluid/operators/jit/test.cc @@ -727,6 +727,7 @@ void TestKernelSoftmax() { if (m > n || n % m != 0) { continue; } + VLOG(10) << "Softmax: " << bs << ", " << n << ", " << m; auto ref = jit::GetReferFunc(); EXPECT_TRUE(ref != nullptr); std::vector x(bs * n), y(bs * n);