diff --git a/paddle/fluid/operators/jit/benchmark.cc b/paddle/fluid/operators/jit/benchmark.cc index 8dab16c284a6f483dce2d8b1dc729391e2e76b8d..b39ce280939515ec8f4fa3b443ff4332074825fd 100644 --- a/paddle/fluid/operators/jit/benchmark.cc +++ b/paddle/fluid/operators/jit/benchmark.cc @@ -254,6 +254,7 @@ int main(int argc, char* argv[]) { // xyn BenchXYNKernel(); BenchXYNKernel(); + BenchXYNKernel(); BenchXYNKernel(); BenchXYNKernel(); BenchXYNKernel(); diff --git a/paddle/fluid/operators/jit/helper.cc b/paddle/fluid/operators/jit/helper.cc index 2465199f430b5c13a0615b6868951be2ac5996d2..5dbe22a81b4866bdf60a03710d8ffd0b7bcb597b 100644 --- a/paddle/fluid/operators/jit/helper.cc +++ b/paddle/fluid/operators/jit/helper.cc @@ -36,6 +36,7 @@ const char* to_string(KernelType kt) { ONE_CASE(kVRelu); ONE_CASE(kVIdentity); ONE_CASE(kVExp); + ONE_CASE(kVSquare); ONE_CASE(kVSigmoid); ONE_CASE(kVTanh); ONE_CASE(kLSTMCtHt); diff --git a/paddle/fluid/operators/jit/kernel_base.h b/paddle/fluid/operators/jit/kernel_base.h index 69112c0ee9e2232f604e4821f3852bfe646bdac4..adb101bd5cdf231ac330dbf44beb4c24c1fcf29e 100644 --- a/paddle/fluid/operators/jit/kernel_base.h +++ b/paddle/fluid/operators/jit/kernel_base.h @@ -30,6 +30,7 @@ typedef enum { kVAddBias, kVRelu, kVIdentity, + kVSquare, kVExp, kVSigmoid, kVTanh, diff --git a/paddle/fluid/operators/jit/more/mkl/CMakeLists.txt b/paddle/fluid/operators/jit/more/mkl/CMakeLists.txt index 7c6a75d35f654b6c2c46b4d498e401db92237341..667c6dfad6676d00ab994564bff57c90caa0cb41 100644 --- a/paddle/fluid/operators/jit/more/mkl/CMakeLists.txt +++ b/paddle/fluid/operators/jit/more/mkl/CMakeLists.txt @@ -8,6 +8,7 @@ USE_JITKERNEL_MORE(kVMul, mkl) USE_JITKERNEL_MORE(kVAdd, mkl) USE_JITKERNEL_MORE(kVScal, mkl) USE_JITKERNEL_MORE(kVExp, mkl) +USE_JITKERNEL_MORE(kVSquare, mkl) USE_JITKERNEL_MORE(kVSigmoid, mkl) USE_JITKERNEL_MORE(kVTanh, mkl) USE_JITKERNEL_MORE(kSeqPool, mkl) diff --git a/paddle/fluid/operators/jit/more/mkl/mkl.cc b/paddle/fluid/operators/jit/more/mkl/mkl.cc index 5b20ae4da96f262657e487cd231b5f319bf92641..fccdc68f5efa34bac6f5a34a41569d2f77416284 100644 --- a/paddle/fluid/operators/jit/more/mkl/mkl.cc +++ b/paddle/fluid/operators/jit/more/mkl/mkl.cc @@ -86,6 +86,16 @@ void VExp(const double* x, double* y, int n) { platform::dynload::vdExp(n, x, y); } +template <> +void VSquare(const float* x, float* y, int n) { + platform::dynload::vsSqr(n, x, y); +} + +template <> +void VSquare(const double* x, double* y, int n) { + platform::dynload::vdSqr(n, x, y); +} + template <> void VCopy(const float* x, float* y, int n) { platform::dynload::cblas_scopy(n, x, 1, y, 1); @@ -132,6 +142,11 @@ bool VExpKernel::UseMe(const int& d) const { return d > 7; } +template <> +bool VSquareKernel::UseMe(const int& d) const { + return d > 7; +} + template <> bool VSigmoidKernel::UseMe(const int& d) const { return d > 7; @@ -165,6 +180,7 @@ AWALYS_USE_ME_WITH_DOUBLE(VScal); AWALYS_USE_ME_WITH_DOUBLE(VExp); AWALYS_USE_ME_WITH_DOUBLE(VSigmoid); AWALYS_USE_ME_WITH_DOUBLE(VTanh); +AWALYS_USE_ME_WITH_DOUBLE(VSquare); #undef AWALYS_USE_ME_WITH_DOUBLE } // namespace mkl @@ -184,6 +200,7 @@ REGISTER_MKL_KERNEL(kVMul, VMul); REGISTER_MKL_KERNEL(kVAdd, VAdd); REGISTER_MKL_KERNEL(kVScal, VScal); REGISTER_MKL_KERNEL(kVExp, VExp); +REGISTER_MKL_KERNEL(kVSquare, VSquare); REGISTER_MKL_KERNEL(kVSigmoid, VSigmoid); REGISTER_MKL_KERNEL(kVTanh, VTanh); REGISTER_MKL_KERNEL(kSeqPool, SeqPool); diff --git a/paddle/fluid/operators/jit/more/mkl/mkl.h b/paddle/fluid/operators/jit/more/mkl/mkl.h index 314ef73d8a581eaaf16ff3b8a58189d209b1735f..a27196fa19f1d3e9aa6c414b6b9f99a21ef49025 100644 --- a/paddle/fluid/operators/jit/more/mkl/mkl.h +++ b/paddle/fluid/operators/jit/more/mkl/mkl.h @@ -39,6 +39,9 @@ void VScal(const T* a, const T* x, T* y, int n); template void VExp(const T* x, T* y, int n); +template +void VSquare(const T* x, T* y, int n); + template void VCopy(const T* x, T* y, int n); @@ -110,6 +113,7 @@ DECLARE_MKL_KERNEL(VScal, AXYNTuples); DECLARE_MKL_KERNEL(VExp, XYNTuples); DECLARE_MKL_KERNEL(VSigmoid, XYNTuples); DECLARE_MKL_KERNEL(VTanh, XYNTuples); +DECLARE_MKL_KERNEL(VSquare, XYNTuples); DECLARE_MKL_KERNEL(SeqPool, SeqPoolTuples); diff --git a/paddle/fluid/operators/jit/refer/CMakeLists.txt b/paddle/fluid/operators/jit/refer/CMakeLists.txt index 9a7e80740faa0245332bab2e046476c9014ef992..4b9bc5e8d49c62404d5d4ef99b7c50987fcb415a 100644 --- a/paddle/fluid/operators/jit/refer/CMakeLists.txt +++ b/paddle/fluid/operators/jit/refer/CMakeLists.txt @@ -28,3 +28,4 @@ USE_JITKERNEL_REFER(kLayerNorm) USE_JITKERNEL_REFER(kNCHW16CMulNC) USE_JITKERNEL_REFER(kSeqPool) USE_JITKERNEL_REFER(kMatMul) +USE_JITKERNEL_REFER(kVSquare) diff --git a/paddle/fluid/operators/jit/refer/refer.cc b/paddle/fluid/operators/jit/refer/refer.cc index 1b8dd0e31517f9e37ef3665af48b6707a56a9425..3512ad7fe7921381afb6152330fff6be34de5ad7 100644 --- a/paddle/fluid/operators/jit/refer/refer.cc +++ b/paddle/fluid/operators/jit/refer/refer.cc @@ -31,6 +31,7 @@ REGISTER_REFER_KERNEL(kVAddBias, VAddBias); REGISTER_REFER_KERNEL(kVRelu, VRelu); REGISTER_REFER_KERNEL(kVIdentity, VIdentity); +REGISTER_REFER_KERNEL(kVSquare, VSquare); REGISTER_REFER_KERNEL(kVExp, VExp); REGISTER_REFER_KERNEL(kVSigmoid, VSigmoid); REGISTER_REFER_KERNEL(kVTanh, VTanh); diff --git a/paddle/fluid/operators/jit/refer/refer.h b/paddle/fluid/operators/jit/refer/refer.h index 225319c059e581dd83049c5bf9b93c4ed516de0a..97d029358594d757f0e1874e9c87ecb8f97c9d50 100644 --- a/paddle/fluid/operators/jit/refer/refer.h +++ b/paddle/fluid/operators/jit/refer/refer.h @@ -83,6 +83,13 @@ inline void VIdentity(const T* x, T* y, int n) { } } +template +inline void VSquare(const T* x, T* y, int n) { + for (int i = 0; i < n; ++i) { + y[i] = x[i] * x[i]; + } +} + template void VExp(const T* x, T* y, int n) { for (int i = 0; i < n; ++i) { @@ -394,6 +401,7 @@ DECLARE_REFER_KERNEL(VIdentity, XYNTuples); DECLARE_REFER_KERNEL(VExp, XYNTuples); DECLARE_REFER_KERNEL(VSigmoid, XYNTuples); DECLARE_REFER_KERNEL(VTanh, XYNTuples); +DECLARE_REFER_KERNEL(VSquare, XYNTuples); // lstm_t*, const lstm_attr_t* DECLARE_REFER_KERNEL(LSTMCtHt, LSTMTuples); diff --git a/paddle/fluid/operators/jit/test.cc b/paddle/fluid/operators/jit/test.cc index 1246ee7c24e0de1363fb35351d15fd4bb912c9e8..f4415a54ca9678c75038a820bb5d212e61593ec7 100644 --- a/paddle/fluid/operators/jit/test.cc +++ b/paddle/fluid/operators/jit/test.cc @@ -604,6 +604,12 @@ TEST(JITKernel, kVIdentity) { TestXYNKernel(); } +TEST(JITKernel, kVSquare) { + namespace jit = paddle::operators::jit; + TestXYNKernel(); + TestXYNKernel(); +} + TEST(JITKernel, kVExp) { namespace jit = paddle::operators::jit; TestXYNKernel();