diff --git a/cmake/external/xpu.cmake b/cmake/external/xpu.cmake index 1ba00fe42c6d7660583745a218021ee7b61f699f..d03f5b8b15e7c9e5f7d7976797e7f9c3d5295adb 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 "20230523") +set(XPU_BASE_DATE "20230529") set(XPU_XCCL_BASE_VERSION "1.0.49.2") set(XPU_XFT_BASE_VERSION "latest") diff --git a/paddle/phi/kernels/xpu/gaussian_kernel.cc b/paddle/phi/kernels/xpu/gaussian_kernel.cc index ca74b19d312c0b6c94c54f6dda88107aca1d8798..f8058f94e872f4441cb191315b57803cbf9b2a2a 100644 --- a/paddle/phi/kernels/xpu/gaussian_kernel.cc +++ b/paddle/phi/kernels/xpu/gaussian_kernel.cc @@ -15,7 +15,6 @@ #include "paddle/phi/kernels/gaussian_kernel.h" #include "paddle/phi/backends/xpu/enforce_xpu.h" -#include "paddle/phi/common/memory_utils.h" #include "paddle/phi/core/generator.h" #include "paddle/phi/core/kernel_registry.h" @@ -29,30 +28,19 @@ void GaussianKernel(const Context& ctx, int seed, DataType dtype, DenseTensor* out) { - std::normal_distribution dist(mean, std); - int64_t size = out->numel(); - ctx.template Alloc(out); - auto* data = out->data(); - uint64_t seed_v = static_cast(seed); - // TODO(pangyoki): implement GetXPURandomEngine to set different seeds on - // corresponding XPU device. - std::shared_ptr engine; - if (seed_v) { - engine = std::make_shared(); - engine->seed(seed_v); - } else { - engine = ctx.GetGenerator()->GetCPUEngine(); - } + out->Resize(phi::make_ddim(shape.GetData())); + T* data = ctx.template Alloc(out); + using XPUType = typename XPUTypeTrait::Type; + int64_t real_seed = seed != 0 ? seed : ctx.GetGenerator()->Random64(); - std::unique_ptr data_cpu(new T[size]); - for (int64_t i = 0; i < size; ++i) { - data_cpu[i] = dist(*engine); - } - memory_utils::Copy(ctx.GetPlace(), - data, - phi::CPUPlace(), - reinterpret_cast(data_cpu.get()), - size * sizeof(T)); + // int normal(Context* ctx, T* x, T mean, T std, int64_t len, int64_t seed); + int r = xpu::normal(ctx.x_context(), + reinterpret_cast(data), + mean, + std, + out->numel(), + real_seed); + PADDLE_ENFORCE_XDNN_SUCCESS(r, "normal"); } } // namespace phi diff --git a/paddle/phi/kernels/xpu/gelu_kernel.cc b/paddle/phi/kernels/xpu/gelu_kernel.cc index d69d4ab8dd1415c18d39b816b92c2c6bc686b10e..59438a5fb9242116fc999f327a3bf44b89874e24 100644 --- a/paddle/phi/kernels/xpu/gelu_kernel.cc +++ b/paddle/phi/kernels/xpu/gelu_kernel.cc @@ -14,6 +14,7 @@ #include "paddle/phi/kernels/gelu_kernel.h" +#include "glog/logging.h" #include "paddle/phi/backends/xpu/enforce_xpu.h" #include "paddle/phi/backends/xpu/xpu_context.h" #include "paddle/phi/common/float16.h" @@ -26,6 +27,9 @@ 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(),