Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
e118edd3
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e118edd3
编写于
4月 18, 2022
作者:
F
furnace
提交者:
GitHub
4月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] fix conv2d and top_k_v2 fp16 (#41409)
[NPU] fix conv2d and top_k_v2 fp16
上级
7ee9ba2f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
47 addition
and
7 deletion
+47
-7
paddle/fluid/operators/conv_op_npu.cc
paddle/fluid/operators/conv_op_npu.cc
+45
-7
paddle/fluid/operators/top_k_v2_op_npu.cc
paddle/fluid/operators/top_k_v2_op_npu.cc
+2
-0
未找到文件。
paddle/fluid/operators/conv_op_npu.cc
浏览文件 @
e118edd3
...
@@ -20,6 +20,29 @@ namespace operators {
...
@@ -20,6 +20,29 @@ namespace operators {
using
Tensor
=
framework
::
Tensor
;
using
Tensor
=
framework
::
Tensor
;
using
NPUDeviceContext
=
platform
::
NPUDeviceContext
;
using
NPUDeviceContext
=
platform
::
NPUDeviceContext
;
static
void
CastToFP16
(
const
framework
::
ExecutionContext
&
ctx
,
const
aclrtStream
&
stream
,
const
Tensor
&
in
,
Tensor
*
out
)
{
out
->
mutable_data
<
paddle
::
platform
::
float16
>
(
ctx
.
GetPlace
());
NpuOpRunner
runner
;
runner
.
SetType
(
"Cast"
)
.
AddInput
(
in
)
.
AddOutput
(
*
out
)
.
AddAttr
(
"dst_type"
,
ACL_FLOAT16
)
.
Run
(
stream
);
}
static
void
CastToFP32
(
const
framework
::
ExecutionContext
&
ctx
,
const
aclrtStream
&
stream
,
const
Tensor
&
in
,
Tensor
*
out
)
{
out
->
mutable_data
<
float
>
(
ctx
.
GetPlace
());
NpuOpRunner
runner
;
runner
.
SetType
(
"Cast"
)
.
AddInput
(
in
)
.
AddOutput
(
*
out
)
.
AddAttr
(
"dst_type"
,
ACL_FLOAT
)
.
Run
(
stream
);
}
template
<
typename
T
>
template
<
typename
T
>
class
DepthwiseConvNPUKernel
:
public
framework
::
OpKernel
<
T
>
{
class
DepthwiseConvNPUKernel
:
public
framework
::
OpKernel
<
T
>
{
...
@@ -356,18 +379,33 @@ class NPUConvGradOpKernel : public framework::OpKernel<T> {
...
@@ -356,18 +379,33 @@ class NPUConvGradOpKernel : public framework::OpKernel<T> {
auto
stream
=
ctx
.
template
device_context
<
NPUDeviceContext
>().
stream
();
auto
stream
=
ctx
.
template
device_context
<
NPUDeviceContext
>().
stream
();
if
(
filter_grad
)
{
if
(
filter_grad
)
{
filter_grad
->
mutable_data
<
float
>
(
ctx
.
GetPlace
());
filter_grad
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
std
::
vector
<
int
>
filter_shape_vec
=
phi
::
vectorize
<
int
>
(
filter
->
dims
());
std
::
vector
<
int
>
filter_shape_vec
=
phi
::
vectorize
<
int
>
(
filter
->
dims
());
Tensor
filter_grad_fp32
(
experimental
::
DataType
::
FLOAT32
);
filter_grad_fp32
.
Resize
(
filter_grad
->
dims
());
if
(
framework
::
TransToProtoVarType
(
input
->
dtype
())
==
framework
::
proto
::
VarType
::
FP16
)
{
CastToFP32
(
ctx
,
stream
,
*
filter_grad
,
&
filter_grad_fp32
);
}
else
{
filter_grad_fp32
.
ShareDataWith
(
*
filter_grad
);
}
const
auto
&
runner
=
NpuOpRunner
(
const
auto
&
runner
=
NpuOpRunner
(
"Conv2DBackpropFilterD"
,
{
input_tensor
,
output_grad_tensor
},
"Conv2DBackpropFilterD"
,
{
input_tensor
,
output_grad_tensor
},
{
*
filter_grad
},
{{
"filter_size"
,
filter_shape_vec
},
{
filter_grad_fp32
},
{{
"filter_size"
,
filter_shape_vec
},
{
"strides"
,
strides_vec
},
{
"strides"
,
strides_vec
},
{
"pads"
,
paddings
},
{
"pads"
,
paddings
},
{
"dilations"
,
dilations_vec
},
{
"dilations"
,
dilations_vec
},
{
"groups"
,
groups
},
{
"groups"
,
groups
},
{
"data_format"
,
data_format
}});
{
"data_format"
,
data_format
}});
runner
.
Run
(
stream
);
runner
.
Run
(
stream
);
if
(
framework
::
TransToProtoVarType
(
input
->
dtype
())
==
framework
::
proto
::
VarType
::
FP16
)
{
CastToFP16
(
ctx
,
stream
,
filter_grad_fp32
,
filter_grad
);
}
}
}
if
(
input_grad
)
{
if
(
input_grad
)
{
input_grad
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
input_grad
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
...
paddle/fluid/operators/top_k_v2_op_npu.cc
浏览文件 @
e118edd3
...
@@ -89,7 +89,9 @@ class TopkV2NPUKernel : public framework::OpKernel<T> {
...
@@ -89,7 +89,9 @@ class TopkV2NPUKernel : public framework::OpKernel<T> {
}
// namespace paddle
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_NPU_KERNEL
(
top_k_v2
,
ops
::
TopkV2NPUKernel
<
float
>
,
REGISTER_OP_NPU_KERNEL
(
top_k_v2
,
ops
::
TopkV2NPUKernel
<
float
>
,
ops
::
TopkV2NPUKernel
<
plat
::
float16
>
,
ops
::
TopkV2NPUKernel
<
double
>
,
ops
::
TopkV2NPUKernel
<
double
>
,
ops
::
TopkV2NPUKernel
<
int32_t
>
,
ops
::
TopkV2NPUKernel
<
int32_t
>
,
ops
::
TopkV2NPUKernel
<
int64_t
>
);
ops
::
TopkV2NPUKernel
<
int64_t
>
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录