未验证 提交 ffd35908 编写于 作者: H houj04 提交者: GitHub

[XPU] update xdnn activations. (#46246)

上级 3b89e7c0
...@@ -10,7 +10,7 @@ set(XPU_RT_LIB_NAME "libxpurt.so") ...@@ -10,7 +10,7 @@ set(XPU_RT_LIB_NAME "libxpurt.so")
if(NOT DEFINED XPU_BASE_URL) if(NOT DEFINED XPU_BASE_URL)
set(XPU_BASE_URL_WITHOUT_DATE set(XPU_BASE_URL_WITHOUT_DATE
"https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev") "https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev")
set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220907") set(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220919")
else() else()
set(XPU_BASE_URL "${XPU_BASE_URL}") set(XPU_BASE_URL "${XPU_BASE_URL}")
endif() endif()
...@@ -19,7 +19,7 @@ endif() ...@@ -19,7 +19,7 @@ endif()
if(NOT DEFINED XPU_XDNN_BASE_URL) if(NOT DEFINED XPU_XDNN_BASE_URL)
set(XPU_XDNN_BASE_URL_WITHOUT_DATE set(XPU_XDNN_BASE_URL_WITHOUT_DATE
"https://klx-sdk-release-public.su.bcebos.com/xdnn/dev") "https://klx-sdk-release-public.su.bcebos.com/xdnn/dev")
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL_WITHOUT_DATE}/20220907") set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL_WITHOUT_DATE}/20220919")
else() else()
set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL}") set(XPU_XDNN_BASE_URL "${XPU_XDNN_BASE_URL}")
endif() endif()
......
...@@ -82,18 +82,43 @@ int xpu_activation_func( ...@@ -82,18 +82,43 @@ int xpu_activation_func(
} }
template <typename Context, typename T, typename XPUType> template <typename Context, typename T, typename XPUType>
int xpu_activation_1attr_func( int xpu_activation_func_with_max_x_y(
const Context& dev_ctx, const Context& dev_ctx,
const DenseTensor& x, const DenseTensor& x,
DenseTensor* out, DenseTensor* out,
float attr, std::function<
std::function<int(xpu::Context*, const XPUType*, XPUType*, int, float)> int(xpu::Context*, const XPUType*, XPUType*, int, const float*, float*)>
func) { func) {
// does not support "const float* max_x, float* max_y" now
int r = func(dev_ctx.x_context(), int r = func(dev_ctx.x_context(),
reinterpret_cast<const XPUType*>(x.data<T>()), reinterpret_cast<const XPUType*>(x.data<T>()),
reinterpret_cast<XPUType*>(out->data<T>()), reinterpret_cast<XPUType*>(out->data<T>()),
x.numel(), x.numel(),
attr); nullptr,
nullptr);
return r;
}
template <typename Context, typename T, typename XPUType>
int xpu_activation_1attr_func(const Context& dev_ctx,
const DenseTensor& x,
DenseTensor* out,
float attr,
std::function<int(xpu::Context*,
const XPUType*,
XPUType*,
int,
float,
const float*,
float*)> func) {
// does not support "const float* max_x, float* max_y" now
int r = func(dev_ctx.x_context(),
reinterpret_cast<const XPUType*>(x.data<T>()),
reinterpret_cast<XPUType*>(out->data<T>()),
x.numel(),
attr,
nullptr,
nullptr);
return r; return r;
} }
...@@ -213,7 +238,7 @@ struct XPUHardSwishFunctor : public funcs::BaseActivationFunctor<T> { ...@@ -213,7 +238,7 @@ struct XPUHardSwishFunctor : public funcs::BaseActivationFunctor<T> {
offset, offset,
3.0f, 3.0f,
errors::External("Not support offset [%f] in XPU", offset)); errors::External("Not support offset [%f] in XPU", offset));
int r = xpu_activation_func<Context, T, XPUType>( int r = xpu_activation_func_with_max_x_y<Context, T, XPUType>(
dev_ctx, x, out, xpu::hard_swish<XPUType>); dev_ctx, x, out, xpu::hard_swish<XPUType>);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "hard_swish"); PADDLE_ENFORCE_XDNN_SUCCESS(r, "hard_swish");
} }
...@@ -259,7 +284,7 @@ struct XPURelu6Functor : public funcs::BaseActivationFunctor<T> { ...@@ -259,7 +284,7 @@ struct XPURelu6Functor : public funcs::BaseActivationFunctor<T> {
void operator()(const Context& dev_ctx, void operator()(const Context& dev_ctx,
const DenseTensor& x, const DenseTensor& x,
DenseTensor* out) const { DenseTensor* out) const {
int r = xpu_activation_func<Context, T, XPUType>( int r = xpu_activation_func_with_max_x_y<Context, T, XPUType>(
dev_ctx, x, out, xpu::relu6<XPUType>); dev_ctx, x, out, xpu::relu6<XPUType>);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "relu6"); PADDLE_ENFORCE_XDNN_SUCCESS(r, "relu6");
} }
...@@ -272,7 +297,7 @@ struct XPUSigmoidFunctor : public funcs::BaseActivationFunctor<T> { ...@@ -272,7 +297,7 @@ struct XPUSigmoidFunctor : public funcs::BaseActivationFunctor<T> {
void operator()(const Context& dev_ctx, void operator()(const Context& dev_ctx,
const DenseTensor& x, const DenseTensor& x,
DenseTensor* out) const { DenseTensor* out) const {
int r = xpu_activation_func<Context, T, XPUType>( int r = xpu_activation_func_with_max_x_y<Context, T, XPUType>(
dev_ctx, x, out, xpu::sigmoid<XPUType>); dev_ctx, x, out, xpu::sigmoid<XPUType>);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "sigmoid"); PADDLE_ENFORCE_XDNN_SUCCESS(r, "sigmoid");
} }
...@@ -363,7 +388,7 @@ struct XPUTanhFunctor : public funcs::BaseActivationFunctor<T> { ...@@ -363,7 +388,7 @@ struct XPUTanhFunctor : public funcs::BaseActivationFunctor<T> {
void operator()(const Context& dev_ctx, void operator()(const Context& dev_ctx,
const DenseTensor& x, const DenseTensor& x,
DenseTensor* out) const { DenseTensor* out) const {
int r = xpu_activation_func<Context, T, XPUType>( int r = xpu_activation_func_with_max_x_y<Context, T, XPUType>(
dev_ctx, x, out, xpu::tanh<XPUType>); dev_ctx, x, out, xpu::tanh<XPUType>);
PADDLE_ENFORCE_XDNN_SUCCESS(r, "tanh"); PADDLE_ENFORCE_XDNN_SUCCESS(r, "tanh");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册