Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a4d4c116
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a4d4c116
编写于
4月 13, 2022
作者:
H
houj04
提交者:
GitHub
4月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update sign op xpu (#41685)
* update sign op on xpu. test=kunlun * fix typo. test=kunlun
上级
6a486ec2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
93 addition
and
44 deletion
+93
-44
cmake/external/xpu.cmake
cmake/external/xpu.cmake
+31
-15
paddle/fluid/operators/sign_op_xpu.cc
paddle/fluid/operators/sign_op_xpu.cc
+4
-4
paddle/fluid/platform/device/xpu/xpu2_op_list.h
paddle/fluid/platform/device/xpu/xpu2_op_list.h
+1
-0
python/paddle/fluid/tests/unittests/xpu/test_sign_op_xpu.py
python/paddle/fluid/tests/unittests/xpu/test_sign_op_xpu.py
+57
-25
未找到文件。
cmake/external/xpu.cmake
浏览文件 @
a4d4c116
...
@@ -7,46 +7,62 @@ SET(XPU_PROJECT "extern_xpu")
...
@@ -7,46 +7,62 @@ SET(XPU_PROJECT "extern_xpu")
SET
(
XPU_API_LIB_NAME
"libxpuapi.so"
)
SET
(
XPU_API_LIB_NAME
"libxpuapi.so"
)
SET
(
XPU_RT_LIB_NAME
"libxpurt.so"
)
SET
(
XPU_RT_LIB_NAME
"libxpurt.so"
)
if
(
NOT DEFINED XPU_BASE_URL
)
SET
(
XPU_BASE_URL_WITHOUT_DATE
"https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev"
)
SET
(
XPU_BASE_URL
"
${
XPU_BASE_URL_WITHOUT_DATE
}
/20220411"
)
else
()
SET
(
XPU_BASE_URL
"
${
XPU_BASE_URL
}
"
)
endif
()
# ubuntu and centos: use output by XDNN API team
if
(
NOT DEFINED XPU_XDNN_BASE_URL
)
SET
(
XPU_XDNN_BASE_URL_WITHOUT_DATE
"https://klx-sdk-release-public.su.bcebos.com/xdnn/dev"
)
SET
(
XPU_XDNN_BASE_URL
"
${
XPU_XDNN_BASE_URL_WITHOUT_DATE
}
/20220412"
)
else
()
SET
(
XPU_XDNN_BASE_URL
"
${
XPU_XDNN_BASE_URL
}
"
)
endif
()
IF
(
WITH_AARCH64
)
IF
(
WITH_AARCH64
)
SET
(
XPU_XRE_DIR_NAME
"xre-kylin_aarch64"
)
SET
(
XPU_XRE_DIR_NAME
"xre-kylin_aarch64"
)
SET
(
XPU_XDNN_DIR_NAME
"xdnn-kylin_aarch64"
)
SET
(
XPU_XDNN_DIR_NAME
"xdnn-kylin_aarch64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-kylin_aarch64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-kylin_aarch64"
)
SET
(
XPU_XDNN_URL
"
${
XPU_BASE_URL
}
/
${
XPU_XDNN_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
ELSEIF
(
WITH_SUNWAY
)
ELSEIF
(
WITH_SUNWAY
)
SET
(
XPU_XRE_DIR_NAME
"xre-deepin_sw6_64"
)
SET
(
XPU_XRE_DIR_NAME
"xre-deepin_sw6_64"
)
SET
(
XPU_XDNN_DIR_NAME
"xdnn-deepin_sw6_64"
)
SET
(
XPU_XDNN_DIR_NAME
"xdnn-deepin_sw6_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-deepin_sw6_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-deepin_sw6_64"
)
SET
(
XPU_XDNN_URL
"
${
XPU_BASE_URL
}
/
${
XPU_XDNN_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
ELSEIF
(
WITH_BDCENTOS
)
ELSEIF
(
WITH_BDCENTOS
)
SET
(
XPU_XRE_DIR_NAME
"xre-bdcentos_x86_64"
)
SET
(
XPU_XRE_DIR_NAME
"xre-bdcentos_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
xdnn
-bdcentos_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
XDNN
-bdcentos_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
# ubuntu and centos: use output by XDNN API team
SET
(
XPU_XDNN_URL
"
${
XPU_XDNN_BASE_URL
}
/
${
XPU_XDNN_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
ELSEIF
(
WITH_UBUNTU
)
ELSEIF
(
WITH_UBUNTU
)
SET
(
XPU_XRE_DIR_NAME
"xre-ubuntu_x86_64"
)
SET
(
XPU_XRE_DIR_NAME
"xre-ubuntu_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
xdnn
-ubuntu_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
XDNN
-ubuntu_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
# ubuntu and centos: use output by XDNN API team
SET
(
XPU_XDNN_URL
"
${
XPU_XDNN_BASE_URL
}
/
${
XPU_XDNN_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
ELSEIF
(
WITH_CENTOS
)
ELSEIF
(
WITH_CENTOS
)
SET
(
XPU_XRE_DIR_NAME
"xre-centos7_x86_64"
)
SET
(
XPU_XRE_DIR_NAME
"xre-centos7_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
xdnn-centos7
_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
XDNN-bdcentos
_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
# ubuntu and centos: use output by XDNN API team
ELSE
()
SET
(
XPU_XDNN_URL
"
${
XPU_XDNN_BASE_URL
}
/
${
XPU_XDNN_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
ELSE
()
SET
(
XPU_XRE_DIR_NAME
"xre-ubuntu_x86_64"
)
SET
(
XPU_XRE_DIR_NAME
"xre-ubuntu_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
xdnn-ubuntu
_x86_64"
)
SET
(
XPU_XDNN_DIR_NAME
"
XDNN-bdcentos
_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
SET
(
XPU_XCCL_DIR_NAME
"xccl-bdcentos_x86_64"
)
# default: use output by XDNN API team
SET
(
XPU_XDNN_URL
"
${
XPU_XDNN_BASE_URL
}
/
${
XPU_XDNN_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
ENDIF
()
ENDIF
()
if
(
NOT DEFINED XPU_BASE_URL
)
SET
(
XPU_BASE_URL_WITHOUT_DATE
"https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev"
)
SET
(
XPU_BASE_URL
"
${
XPU_BASE_URL_WITHOUT_DATE
}
/20220411"
)
else
()
SET
(
XPU_BASE_URL
"
${
XPU_BASE_URL
}
"
)
endif
()
SET
(
XPU_XRE_URL
"
${
XPU_BASE_URL
}
/
${
XPU_XRE_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
SET
(
XPU_XRE_URL
"
${
XPU_BASE_URL
}
/
${
XPU_XRE_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
SET
(
XPU_XDNN_URL
"
${
XPU_BASE_URL
}
/
${
XPU_XDNN_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
SET
(
XPU_XCCL_URL
"
${
XPU_BASE_URL_WITHOUT_DATE
}
/20220411/
${
XPU_XCCL_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
SET
(
XPU_XCCL_URL
"
${
XPU_BASE_URL_WITHOUT_DATE
}
/20220411/
${
XPU_XCCL_DIR_NAME
}
.tar.gz"
CACHE STRING
""
FORCE
)
SET
(
XPU_PACK_DEPENCE_URL
"https://baidu-kunlun-public.su.bcebos.com/paddle_depence/pack_paddle_depence.sh"
CACHE STRING
""
FORCE
)
SET
(
XPU_PACK_DEPENCE_URL
"https://baidu-kunlun-public.su.bcebos.com/paddle_depence/pack_paddle_depence.sh"
CACHE STRING
""
FORCE
)
SET
(
SNAPPY_PREFIX_DIR
"
${
THIRD_PARTY_PATH
}
/xpu"
)
SET
(
SNAPPY_PREFIX_DIR
"
${
THIRD_PARTY_PATH
}
/xpu"
)
SET
(
XPU_DOWNLOAD_DIR
"
${
SNAPPY_PREFIX_DIR
}
/src/
${
XPU_PROJECT
}
"
)
SET
(
XPU_DOWNLOAD_DIR
"
${
SNAPPY_PREFIX_DIR
}
/src/
${
XPU_PROJECT
}
"
)
SET
(
XPU_INSTALL_DIR
"
${
THIRD_PARTY_PATH
}
/install/xpu"
)
SET
(
XPU_INSTALL_DIR
"
${
THIRD_PARTY_PATH
}
/install/xpu"
)
SET
(
XPU_INC_DIR
"
${
THIRD_PARTY_PATH
}
/install/xpu/include"
)
SET
(
XPU_INC_DIR
"
${
THIRD_PARTY_PATH
}
/install/xpu/include"
)
...
...
paddle/fluid/operators/sign_op_xpu.cc
浏览文件 @
a4d4c116
...
@@ -14,6 +14,7 @@ limitations under the License. */
...
@@ -14,6 +14,7 @@ limitations under the License. */
#ifdef PADDLE_WITH_XPU
#ifdef PADDLE_WITH_XPU
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/platform/device/device_wrapper.h"
#include "paddle/fluid/platform/device/xpu/xpu_header.h"
#include "paddle/fluid/platform/device/xpu/xpu_header.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -26,10 +27,9 @@ class SignXPUKernel : public framework::OpKernel<T> {
...
@@ -26,10 +27,9 @@ class SignXPUKernel : public framework::OpKernel<T> {
auto
*
in
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
in
=
context
.
Input
<
framework
::
Tensor
>
(
"X"
);
out
->
mutable_data
<
T
>
(
in
->
place
());
out
->
mutable_data
<
T
>
(
in
->
place
());
auto
xpu_context
=
context
.
device_context
<
DeviceContext
>
().
x_context
();
auto
xpu_context
=
context
.
device_context
<
DeviceContext
>
().
x_context
();
int
r
=
xpu
::
activation_forward
(
xpu_context
,
xpu
::
Activation_t
::
SIGN
,
// int sign(Context* ctx, const T* x , T* y, int len);
in
->
numel
(),
in
->
data
<
T
>
(),
out
->
data
<
T
>
());
int
r
=
xpu
::
sign
(
xpu_context
,
in
->
data
<
T
>
(),
out
->
data
<
T
>
(),
in
->
numel
());
PADDLE_ENFORCE_EQ
(
r
,
xpu
::
Error_t
::
SUCCESS
,
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"sign"
);
platform
::
errors
::
Fatal
(
"XPU sign kernel error!"
));
}
}
};
};
...
...
paddle/fluid/platform/device/xpu/xpu2_op_list.h
浏览文件 @
a4d4c116
...
@@ -316,6 +316,7 @@ XPUOpMap& get_kl2_ops() {
...
@@ -316,6 +316,7 @@ XPUOpMap& get_kl2_ops() {
{
"sigmoid"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
())})},
{
"sigmoid"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
())})},
{
"sigmoid_grad"
,
{
"sigmoid_grad"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
())})},
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
())})},
{
"sign"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
())})},
{
"slice_grad"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
{
"slice_grad"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
()),
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
()),
pOpKernelType
(
vartype
::
INT32
,
XPUPlace
())})},
pOpKernelType
(
vartype
::
INT32
,
XPUPlace
())})},
...
...
python/paddle/fluid/tests/unittests/xpu/test_sign_op_xpu.py
浏览文件 @
a4d4c116
...
@@ -18,37 +18,69 @@ import unittest
...
@@ -18,37 +18,69 @@ import unittest
import
numpy
as
np
import
numpy
as
np
import
sys
import
sys
sys
.
path
.
append
(
".."
)
sys
.
path
.
append
(
".."
)
from
op_test
import
OpTest
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid
import
Program
,
program_guard
import
paddle
import
paddle
from
op_test
import
OpTest
from
op_test_xpu
import
XPUOpTest
from
xpu.get_test_cover_info
import
create_test_class
,
get_xpu_op_support_types
,
XPUOpTestWrapper
paddle
.
enable_static
()
paddle
.
enable_static
()
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_xpu
(),
class
XPUTestSignOP
(
XPUOpTestWrapper
):
"core is not compiled with XPU"
)
def
__init__
(
self
):
class
TestXPUSignOp
(
OpTest
):
self
.
op_name
=
'sign'
def
setUp
(
self
):
self
.
use_dynamic_create_class
=
False
self
.
op_type
=
"sign"
self
.
dtype
=
np
.
float32
class
TestSignOPBase
(
XPUOpTest
):
self
.
inputs
=
{
def
setUp
(
self
):
'X'
:
np
.
random
.
uniform
(
-
10
,
10
,
(
10
,
10
)).
astype
(
self
.
dtype
)
self
.
place
=
paddle
.
XPUPlace
(
0
)
}
self
.
init_dtype
()
self
.
outputs
=
{
'Out'
:
np
.
sign
(
self
.
inputs
[
'X'
])}
self
.
set_case
()
self
.
attrs
=
{
'use_xpu'
:
True
}
def
set_case
(
self
):
def
test_check_output
(
self
):
self
.
op_type
=
'sign'
if
paddle
.
is_compiled_with_xpu
():
self
.
dtype
=
self
.
in_type
place
=
paddle
.
XPUPlace
(
0
)
self
.
init_config
()
self
.
check_output_with_place
(
place
)
self
.
x
=
np
.
random
.
uniform
(
-
10
,
10
,
self
.
input_shape
).
astype
(
self
.
dtype
)
def
test_check_grad
(
self
):
self
.
inputs
=
{
'X'
:
self
.
x
}
if
paddle
.
is_compiled_with_xpu
():
self
.
outputs
=
{
'Out'
:
np
.
sign
(
self
.
x
)}
place
=
paddle
.
XPUPlace
(
0
)
self
.
attrs
=
{
'use_xpu'
:
True
}
self
.
check_grad_with_place
(
place
,
[
'X'
],
'Out'
)
def
init_dtype
(
self
):
self
.
dtype
=
np
.
float32
def
test_check_output
(
self
):
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad
(
self
):
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
def
init_config
(
self
):
self
.
input_shape
=
[
864
]
class
XPUTestSign1
(
TestSignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
2
,
768
]
class
XPUTestSign2
(
TestSignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
3
,
8
,
4096
]
class
XPUTestSign3
(
TestSignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
1024
]
class
XPUTestSign4
(
TestSignOPBase
):
def
init_config
(
self
):
self
.
input_shape
=
[
2
,
2
,
255
]
support_types
=
get_xpu_op_support_types
(
'sign'
)
for
stype
in
support_types
:
create_test_class
(
globals
(),
XPUTestSignOP
,
stype
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录