diff --git a/cmake/external/xpu.cmake b/cmake/external/xpu.cmake index d03f5b8b15e7c9e5f7d7976797e7f9c3d5295adb..04948cb9f76e23e91f0611c5abc214a1cb5b5126 100644 --- a/cmake/external/xpu.cmake +++ b/cmake/external/xpu.cmake @@ -8,7 +8,7 @@ set(XPU_API_LIB_NAME "libxpuapi.so") set(XPU_RT_LIB_NAME "libxpurt.so") set(XPU_XFT_LIB_NAME "libxft.so") -set(XPU_BASE_DATE "20230529") +set(XPU_BASE_DATE "20230602") set(XPU_XCCL_BASE_VERSION "1.0.49.2") set(XPU_XFT_BASE_VERSION "latest") diff --git a/paddle/phi/kernels/xpu/gelu_grad_kernel.cc b/paddle/phi/kernels/xpu/gelu_grad_kernel.cc index 9a99c93ccb58c89fee4f724ab728fd84105ca398..675af2d387c9e0854fb0aa3ea5e7f0ac94285266 100644 --- a/paddle/phi/kernels/xpu/gelu_grad_kernel.cc +++ b/paddle/phi/kernels/xpu/gelu_grad_kernel.cc @@ -28,16 +28,30 @@ void GeluGradKernel(const Context& dev_ctx, bool approximate, DenseTensor* x_grad) { using XPUType = typename XPUTypeTrait::Type; - dev_ctx.template Alloc(x_grad); - int r = xpu::gelu_grad( - dev_ctx.x_context(), - reinterpret_cast(x.data()), - nullptr, - reinterpret_cast(out_grad.data()), - reinterpret_cast(x_grad->data()), - x_grad->numel()); - PADDLE_ENFORCE_XDNN_SUCCESS(r, "gelu_grad"); + if (approximate) { + // int approximate_gelu_grad(Context* ctx, const T* x, const T* y, const T* + // dy, T* dx, int64_t len); + int r = xpu::approximate_gelu_grad( + dev_ctx.x_context(), + reinterpret_cast(x.data()), + nullptr, + reinterpret_cast(out_grad.data()), + reinterpret_cast(x_grad->data()), + x_grad->numel()); + PADDLE_ENFORCE_XDNN_SUCCESS(r, "approximate_gelu_grad"); + } else { + // int gelu_grad(Context* ctx, const T* x, const T* y, const T* dy, T* dx, + // int64_t len); + int r = xpu::gelu_grad( + dev_ctx.x_context(), + reinterpret_cast(x.data()), + nullptr, + reinterpret_cast(out_grad.data()), + reinterpret_cast(x_grad->data()), + x_grad->numel()); + PADDLE_ENFORCE_XDNN_SUCCESS(r, "gelu_grad"); + } } } // namespace phi diff --git a/paddle/phi/kernels/xpu/gelu_kernel.cc b/paddle/phi/kernels/xpu/gelu_kernel.cc index 59438a5fb9242116fc999f327a3bf44b89874e24..54303f557716c6b4f216984da2762077a44b5dfd 100644 --- a/paddle/phi/kernels/xpu/gelu_kernel.cc +++ b/paddle/phi/kernels/xpu/gelu_kernel.cc @@ -27,16 +27,26 @@ void GeluKernel(const Context& dev_ctx, const DenseTensor& x, bool approximate, DenseTensor* out) { - if (approximate) { - LOG_FIRST_N(INFO, 1) << "XPU does not support gelu with approximate."; - } using XPUType = typename XPUTypeTrait::Type; dev_ctx.template Alloc(out); - int r = xpu::gelu(dev_ctx.x_context(), - reinterpret_cast(x.data()), - reinterpret_cast(out->data()), - out->numel()); - PADDLE_ENFORCE_XDNN_SUCCESS(r, "gelu"); + if (approximate) { + // int approximate_gelu(Context* ctx, const T* x, T* y, int64_t len, const + // float* max_x = nullptr, float* max_y = nullptr); + int r = xpu::approximate_gelu( + dev_ctx.x_context(), + reinterpret_cast(x.data()), + reinterpret_cast(out->data()), + out->numel()); + PADDLE_ENFORCE_XDNN_SUCCESS(r, "approximate_gelu"); + } else { + // int gelu(Context* ctx, const T* x, T* y, int64_t len, const float* max_x + // = nullptr, float* max_y = nullptr); + int r = xpu::gelu(dev_ctx.x_context(), + reinterpret_cast(x.data()), + reinterpret_cast(out->data()), + out->numel()); + PADDLE_ENFORCE_XDNN_SUCCESS(r, "gelu"); + } } } // namespace phi diff --git a/test/xpu/test_activation_op_xpu.py b/test/xpu/test_activation_op_xpu.py index ed13954352d5066a9e35a4b99ce64feb63b55c85..50d9aec5b66ff362ca39e0dd0676fcf899f48132 100644 --- a/test/xpu/test_activation_op_xpu.py +++ b/test/xpu/test_activation_op_xpu.py @@ -377,6 +377,19 @@ class XPUTestGeluOP(XPUOpTestWrapper): self.outputs = {'Out': out} self.attrs = {"approximate": approximate, 'use_xpu': True} + class XPUTestGeluApproximate(TestActivationOPBase): + def set_case(self): + self.op_type = "gelu" + self.dtype = self.in_type + + approximate = True + x = np.random.uniform(-1, 1, [11, 17]).astype(self.dtype) + out = gelu(x, approximate) + + self.inputs = {'X': x} + self.outputs = {'Out': out} + self.attrs = {"approximate": approximate, 'use_xpu': True} + support_types = get_xpu_op_support_types('gelu') for stype in support_types: diff --git a/test/xpu/test_rnn_op_xpu.py b/test/xpu/test_rnn_op_xpu.py index 86673181d8723043cc151427d10dab3ff892e209..eaeafc5e01c580f6801f9c16c499ca6ce1033f2f 100755 --- a/test/xpu/test_rnn_op_xpu.py +++ b/test/xpu/test_rnn_op_xpu.py @@ -11,9 +11,13 @@ # limitations under the License. import random +import sys import unittest import numpy as np + +sys.path.append('../rnn') + from convert import get_params_for_net from get_test_cover_info import ( XPUOpTestWrapper,