Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e84fa263
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
e84fa263
编写于
2月 21, 2023
作者:
Z
zhangyikun02
提交者:
GitHub
2月 21, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pad3d support fp16 for xpu (#50653)
上级
c1b5e7c2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
12 deletion
+30
-12
paddle/phi/backends/xpu/xpu2_op_list.cc
paddle/phi/backends/xpu/xpu2_op_list.cc
+1
-1
paddle/phi/kernels/xpu/pad3d_kernel.cc
paddle/phi/kernels/xpu/pad3d_kernel.cc
+11
-8
python/paddle/fluid/tests/unittests/xpu/test_pad3d_op_xpu.py
python/paddle/fluid/tests/unittests/xpu/test_pad3d_op_xpu.py
+18
-3
未找到文件。
paddle/phi/backends/xpu/xpu2_op_list.cc
浏览文件 @
e84fa263
...
...
@@ -452,7 +452,7 @@ XPUOpMap& get_kl2_ops() {
{
"p_norm"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"p_norm_grad"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"pad3d_grad"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"pad3d"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"pad3d"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
,
phi
::
DataType
::
FLOAT16
})},
{
"pixel_shuffle"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"pixel_shuffle_grad"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"pool2d_grad"
,
...
...
paddle/phi/kernels/xpu/pad3d_kernel.cc
浏览文件 @
e84fa263
...
...
@@ -28,7 +28,6 @@ void Pad3dKernel(const Context& dev_ctx,
float
pad_value
,
const
std
::
string
&
data_format
,
DenseTensor
*
out
)
{
T
value
=
static_cast
<
T
>
(
pad_value
);
std
::
vector
<
int64_t
>
pads
=
paddings
.
GetData
();
auto
in_dims
=
x
.
dims
();
...
...
@@ -142,10 +141,12 @@ void Pad3dKernel(const Context& dev_ctx,
pads_xpu
[
4
]
=
pads
[
0
];
// pl
pads_xpu
[
5
]
=
pads
[
1
];
// pr
using
XPUType
=
typename
XPUTypeTrait
<
T
>::
Type
;
if
(
mode
==
"reflect"
)
{
int
r
=
xpu
::
reflection_pad3d
(
dev_ctx
.
x_context
(),
in_data
,
out_data
,
reinterpret_cast
<
const
XPUType
*>
(
in_data
)
,
reinterpret_cast
<
XPUType
*>
(
out_data
)
,
num
,
channels
,
in_depth
,
...
...
@@ -156,8 +157,8 @@ void Pad3dKernel(const Context& dev_ctx,
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"reflection_pad3d"
);
}
else
if
(
mode
==
"replicate"
)
{
int
r
=
xpu
::
replication_pad3d
(
dev_ctx
.
x_context
(),
in_data
,
out_data
,
reinterpret_cast
<
const
XPUType
*>
(
in_data
)
,
reinterpret_cast
<
XPUType
*>
(
out_data
)
,
num
,
channels
,
in_depth
,
...
...
@@ -167,9 +168,10 @@ void Pad3dKernel(const Context& dev_ctx,
is_ncdhw
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"replication_pad3d"
);
}
else
if
(
mode
==
"constant"
)
{
XPUType
value
=
static_cast
<
XPUType
>
(
pad_value
);
int
r
=
xpu
::
constant_pad3d
(
dev_ctx
.
x_context
(),
in_data
,
out_data
,
reinterpret_cast
<
const
XPUType
*>
(
in_data
)
,
reinterpret_cast
<
XPUType
*>
(
out_data
)
,
num
,
channels
,
in_depth
,
...
...
@@ -184,4 +186,5 @@ void Pad3dKernel(const Context& dev_ctx,
}
// namespace phi
PD_REGISTER_KERNEL
(
pad3d
,
XPU
,
ALL_LAYOUT
,
phi
::
Pad3dKernel
,
float
)
{}
PD_REGISTER_KERNEL
(
pad3d
,
XPU
,
ALL_LAYOUT
,
phi
::
Pad3dKernel
,
float
,
phi
::
dtype
::
float16
)
{}
python/paddle/fluid/tests/unittests/xpu/test_pad3d_op_xpu.py
浏览文件 @
e84fa263
...
...
@@ -188,7 +188,9 @@ class XPUTestPad3dOp(XPUOpTestWrapper):
mode
=
"constant"
value
=
100
input_data
=
np
.
random
.
rand
(
*
input_shape
).
astype
(
self
.
dtype
)
x
=
paddle
.
fluid
.
data
(
name
=
"x"
,
shape
=
input_shape
)
x
=
paddle
.
fluid
.
data
(
name
=
"x"
,
shape
=
input_shape
,
dtype
=
self
.
dtype
)
result
=
F
.
pad
(
x
=
x
,
pad
=
pad
,
value
=
value
,
mode
=
mode
,
data_format
=
"NCDHW"
)
...
...
@@ -209,7 +211,9 @@ class XPUTestPad3dOp(XPUOpTestWrapper):
pad
=
[
1
,
2
,
1
,
1
,
1
,
2
]
mode
=
"reflect"
input_data
=
np
.
random
.
rand
(
*
input_shape
).
astype
(
self
.
dtype
)
x
=
paddle
.
fluid
.
data
(
name
=
"x"
,
shape
=
input_shape
)
x
=
paddle
.
fluid
.
data
(
name
=
"x"
,
shape
=
input_shape
,
dtype
=
self
.
dtype
)
result1
=
F
.
pad
(
x
=
x
,
pad
=
pad
,
mode
=
mode
,
data_format
=
"NCDHW"
)
result2
=
F
.
pad
(
x
=
x
,
pad
=
pad
,
mode
=
mode
,
data_format
=
"NDHWC"
)
exe
=
Executor
(
place
)
...
...
@@ -235,7 +239,9 @@ class XPUTestPad3dOp(XPUOpTestWrapper):
pad
=
[
1
,
2
,
1
,
1
,
3
,
4
]
mode
=
"replicate"
input_data
=
np
.
random
.
rand
(
*
input_shape
).
astype
(
self
.
dtype
)
x
=
paddle
.
fluid
.
data
(
name
=
"x"
,
shape
=
input_shape
)
x
=
paddle
.
fluid
.
data
(
name
=
"x"
,
shape
=
input_shape
,
dtype
=
self
.
dtype
)
result1
=
F
.
pad
(
x
=
x
,
pad
=
pad
,
mode
=
mode
,
data_format
=
"NCDHW"
)
result2
=
F
.
pad
(
x
=
x
,
pad
=
pad
,
mode
=
mode
,
data_format
=
"NDHWC"
)
exe
=
Executor
(
place
)
...
...
@@ -320,6 +326,9 @@ class XPUTestPad3dOp(XPUOpTestWrapper):
self
.
check_static_result_3
(
place
=
place
)
def
test_dygraph_1
(
self
):
# TODO: remove fp16 limit after support of pad op
if
self
.
dtype
==
np
.
float16
:
return
paddle
.
disable_static
()
input_shape
=
(
1
,
2
,
3
,
4
,
5
)
pad
=
[
1
,
2
,
1
,
1
,
3
,
4
]
...
...
@@ -365,6 +374,9 @@ class XPUTestPad3dOp(XPUOpTestWrapper):
np
.
testing
.
assert_allclose
(
y3
.
numpy
(),
np_out3
,
rtol
=
1e-05
)
def
test_dygraph_2
(
self
):
# TODO: remove fp16 limit after support of pad op
if
self
.
dtype
==
np
.
float16
:
return
paddle
.
disable_static
()
input_shape
=
(
2
,
3
,
4
,
5
)
pad
=
[
1
,
1
,
3
,
4
]
...
...
@@ -412,6 +424,9 @@ class XPUTestPad3dOp(XPUOpTestWrapper):
np
.
testing
.
assert_allclose
(
y3
.
numpy
(),
np_out3
,
rtol
=
1e-05
)
def
test_dygraph_3
(
self
):
# TODO: remove fp16 limit after support of pad op
if
self
.
dtype
==
np
.
float16
:
return
paddle
.
disable_static
()
input_shape
=
(
3
,
4
,
5
)
pad
=
[
3
,
4
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录