Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
b4d7ef9d
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b4d7ef9d
编写于
10月 11, 2022
作者:
H
HongyuJia
提交者:
GitHub
10月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Opt Code] Opt GetExpectedKernelType code of conv_op (#46681)
* refine conv_op mkldnn code * fix customized_type_value
上级
d6c69d7c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
57 addition
and
62 deletion
+57
-62
paddle/fluid/operators/conv_op.cc
paddle/fluid/operators/conv_op.cc
+57
-62
未找到文件。
paddle/fluid/operators/conv_op.cc
浏览文件 @
b4d7ef9d
...
...
@@ -189,35 +189,9 @@ std::vector<int64_t> ConvOp::ComputeOutputShape(
framework
::
OpKernelType
ConvOp
::
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
int
customized_type_value
=
framework
::
OpKernelType
::
kDefaultCustomizedTypeValue
;
framework
::
LibraryType
library
{
framework
::
LibraryType
::
kPlain
};
// TODO(pzelazko-intel): enable MKLDNN layout when it's ready
auto
input_data_type
=
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"Input"
);
std
::
string
data_format
=
"AnyLayout"
;
// todo enable data layout when it's ready
framework
::
DataLayout
layout
=
framework
::
StringToDataLayout
(
data_format
);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if
(
platform
::
CanCUDNNBeUsed
(
ctx
))
{
library
=
framework
::
LibraryType
::
kCUDNN
;
}
#endif
#ifdef PADDLE_WITH_MKLDNN
if
(
library
==
framework
::
LibraryType
::
kPlain
&&
this
->
CanMKLDNNBeUsed
(
ctx
,
input_data_type
))
{
library
=
framework
::
LibraryType
::
kMKLDNN
;
layout
=
framework
::
DataLayout
::
kMKLDNN
;
customized_type_value
=
(
input_data_type
==
framework
::
DataTypeTrait
<
int8_t
>::
DataType
()
||
input_data_type
==
framework
::
DataTypeTrait
<
uint8_t
>::
DataType
())
?
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"Filter"
)
==
framework
::
DataTypeTrait
<
int8_t
>::
DataType
()
?
kConvMKLDNNINT8WS8
:
kConvMKLDNNINT8
:
kConvMKLDNNFP32
;
}
#endif
// todo enable data layout when it's ready
// (https://github.com/PaddlePaddle/Paddle/pull/20042)
if
(
input_data_type
!=
framework
::
proto
::
VarType
::
INT8
&&
input_data_type
!=
framework
::
proto
::
VarType
::
UINT8
&&
...
...
@@ -234,28 +208,53 @@ framework::OpKernelType ConvOp::GetExpectedKernelType(
paddle
::
framework
::
DataTypeToString
(
input_data_type
),
paddle
::
framework
::
DataTypeToString
(
filter_data_type
)));
}
// #ifndef PADDLE_WITH_ASCEND_CL
// if (input_data_type == framework::proto::VarType::FP16) {
// PADDLE_ENFORCE_EQ(
// library, framework::LibraryType::kCUDNN,
// platform::errors::InvalidArgument(
// "float16 can only be used when CUDNN or NPU is used"));
// }
// #endif
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if
(
platform
::
CanCUDNNBeUsed
(
ctx
))
{
#if PADDLE_WITH_CUDA
if
(
input_data_type
==
framework
::
proto
::
VarType
::
BF16
&&
library
==
framework
::
LibraryType
::
kCUDNN
)
{
PADDLE_ENFORCE_GE
(
platform
::
DnnVersion
(),
8100
,
platform
::
errors
::
InvalidArgument
(
"bfloat16 can only be used when CUDNN_VERSION >= 8100"
));
}
if
(
input_data_type
==
framework
::
proto
::
VarType
::
BF16
)
{
PADDLE_ENFORCE_GE
(
platform
::
DnnVersion
(),
8100
,
platform
::
errors
::
InvalidArgument
(
"bfloat16 can only be used when CUDNN_VERSION >= 8100"
));
}
#endif // PADDLE_WITH_CUDA
return
framework
::
OpKernelType
(
input_data_type
,
ctx
.
GetPlace
(),
framework
::
DataLayout
::
kAnyLayout
,
framework
::
LibraryType
::
kCUDNN
);
}
#endif // PADDLE_WITH_CUDA || PADDLE_WITH_HIP
auto
type
=
framework
::
OpKernelType
(
input_data_type
,
ctx
.
GetPlace
(),
layout
,
library
,
customized_type_value
);
return
type
;
#ifdef PADDLE_WITH_MKLDNN
if
(
this
->
CanMKLDNNBeUsed
(
ctx
,
input_data_type
))
{
int
customized_type_value
=
(
input_data_type
==
framework
::
DataTypeTrait
<
int8_t
>::
DataType
()
||
input_data_type
==
framework
::
DataTypeTrait
<
uint8_t
>::
DataType
())
?
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"Filter"
)
==
framework
::
DataTypeTrait
<
int8_t
>::
DataType
()
?
kConvMKLDNNINT8WS8
:
kConvMKLDNNINT8
:
kConvMKLDNNFP32
;
return
framework
::
OpKernelType
(
input_data_type
,
ctx
.
GetPlace
(),
framework
::
DataLayout
::
kMKLDNN
,
framework
::
LibraryType
::
kMKLDNN
,
customized_type_value
);
}
#endif
// #ifndef PADDLE_WITH_ASCEND_CL
// if (input_data_type == framework::proto::VarType::FP16) {
// PADDLE_ENFORCE_EQ(
// library, framework::LibraryType::kCUDNN,
// platform::errors::InvalidArgument(
// "float16 can only be used when CUDNN or NPU is used"));
// }
// #endif
return
framework
::
OpKernelType
(
input_data_type
,
ctx
.
GetPlace
());
}
framework
::
OpKernelType
ConvOp
::
GetKernelTypeForVar
(
...
...
@@ -502,32 +501,28 @@ void ConvOpGrad::InferShape(framework::InferShapeContext* ctx) const {
framework
::
OpKernelType
ConvOpGrad
::
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
int
customized_type_value
=
framework
::
OpKernelType
::
kDefaultCustomizedTypeValue
;
framework
::
LibraryType
library_
{
framework
::
LibraryType
::
kPlain
};
// TODO(pzelazko-intel): enable MKLDNN layout when it's ready
std
::
string
data_format
=
"AnyLayout"
;
framework
::
DataLayout
layout_
=
framework
::
StringToDataLayout
(
data_format
);
auto
data_type
=
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"Input"
);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if
(
platform
::
CanCUDNNBeUsed
(
ctx
))
{
library_
=
framework
::
LibraryType
::
kCUDNN
;
return
framework
::
OpKernelType
(
data_type
,
ctx
.
GetPlace
(),
framework
::
DataLayout
::
kAnyLayout
,
framework
::
LibraryType
::
kCUDNN
);
}
#endif
#ifdef PADDLE_WITH_MKLDNN
if
(
library_
==
framework
::
LibraryType
::
kPlain
&&
this
->
CanMKLDNNBeUsed
(
ctx
,
data_type
))
{
const
std
::
string
data_format
=
ctx
.
Attr
<
std
::
string
>
(
"data_format"
);
library_
=
framework
::
LibraryType
::
kMKLDNN
;
layout_
=
framework
::
DataLayout
::
kMKLDNN
;
customized_type_value
=
kConvMKLDNNFP32
;
if
(
this
->
CanMKLDNNBeUsed
(
ctx
,
data_type
))
{
return
framework
::
OpKernelType
(
data_type
,
ctx
.
GetPlace
(),
framework
::
DataLayout
::
kMKLDNN
,
framework
::
LibraryType
::
kMKLDNN
,
kConvMKLDNNFP32
)
;
}
#endif
auto
type
=
framework
::
OpKernelType
(
data_type
,
ctx
.
GetPlace
(),
layout_
,
library_
,
customized_type_value
);
return
type
;
return
framework
::
OpKernelType
(
data_type
,
ctx
.
GetPlace
());
}
framework
::
OpKernelType
ConvOpGrad
::
GetKernelTypeForVar
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录