Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
3bad26ec
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看板
未验证
提交
3bad26ec
编写于
9月 09, 2022
作者:
X
xiaoxiaohehe001
提交者:
GitHub
9月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
convfusion_cache (#45902)
上级
d6b5d91c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
45 deletion
+67
-45
paddle/fluid/framework/conv_search_cache.h
paddle/fluid/framework/conv_search_cache.h
+4
-2
paddle/fluid/framework/operator_kernel_configs.h
paddle/fluid/framework/operator_kernel_configs.h
+10
-0
paddle/fluid/operators/fused/conv_fusion_op.cu
paddle/fluid/operators/fused/conv_fusion_op.cu
+53
-43
未找到文件。
paddle/fluid/framework/conv_search_cache.h
浏览文件 @
3bad26ec
...
...
@@ -55,7 +55,8 @@ class ConvSearchCache {
AlgorithmsCache
<
cudnnConvolutionBwdFilterAlgo_t
>*
GetBackwardFilter
()
{
return
&
backward_filter_cache_
;
}
AlgorithmsCache
<
cudnnConvolutionFwdAlgo_t
>*
GetConvFusion
()
{
AlgorithmsCache
<
SearchFuseResult
<
cudnnConvolutionFwdAlgo_t
>>*
GetConvFusion
()
{
return
&
fusion_forward_cache_
;
}
#endif
...
...
@@ -75,7 +76,8 @@ class ConvSearchCache {
AlgorithmsCache
<
cudnnConvolutionFwdAlgo_t
>
forward_cache_
;
AlgorithmsCache
<
cudnnConvolutionBwdDataAlgo_t
>
backward_data_cache_
;
AlgorithmsCache
<
cudnnConvolutionBwdFilterAlgo_t
>
backward_filter_cache_
;
AlgorithmsCache
<
cudnnConvolutionFwdAlgo_t
>
fusion_forward_cache_
;
AlgorithmsCache
<
SearchFuseResult
<
cudnnConvolutionFwdAlgo_t
>>
fusion_forward_cache_
;
#endif
};
...
...
paddle/fluid/framework/operator_kernel_configs.h
浏览文件 @
3bad26ec
...
...
@@ -24,6 +24,16 @@ limitations under the License. */
namespace
paddle
{
namespace
framework
{
template
<
typename
AlgoT
>
struct
SearchFuseResult
{
SearchFuseResult
()
{}
explicit
SearchFuseResult
(
AlgoT
a
)
:
algo
(
a
)
{}
AlgoT
algo
=
static_cast
<
AlgoT
>
(
0
);
float
time
=
-
1.
f
;
size_t
workspace_size
=
0
;
};
// thread-safe.
template
<
typename
TAlgorithm
>
class
AlgorithmsCache
{
...
...
paddle/fluid/operators/fused/conv_fusion_op.cu
浏览文件 @
3bad26ec
...
...
@@ -35,6 +35,7 @@ using ScopedActivationDescriptor = platform::ScopedActivationDescriptor;
using
DataLayout
=
platform
::
DataLayout
;
using
framework
::
AlgorithmsCache
;
using
framework
::
ConvSearchCache
;
using
framework
::
SearchFuseResult
;
template
<
typename
T
>
using
ScalingParamType
=
typename
platform
::
CudnnDataType
<
T
>::
ScalingParamType
;
...
...
@@ -348,34 +349,35 @@ class CUDNNConvFusionOpKernel : public framework::OpKernel<T> {
&
perf_count
,
perf_results
.
get
()));
algo
=
(
perf_results
.
get
())[
best_algo_idx
].
algo
;
#else
PADDLE_ENFORCE_GPU_SUCCESS
(
platform
::
dynload
::
cudnnGetConvolutionForward
WorkspaceSize
(
platform
::
dynload
::
cudnnGetConvolutionForward
Algorithm
(
handle
,
cudnn_input_desc
,
cudnn_filter_desc
,
cudnn_conv_desc
,
cudnn_output_desc
,
algo
,
&
workspace_size_in_bytes
));
if
(
workspace_size_in_bytes
>
workspace_size_limit
)
workspace_size_limit
=
workspace_size_in_bytes
;
#else
CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT
,
workspace_size_limit
,
&
algo
));
#endif
PADDLE_ENFORCE_GPU_SUCCESS
(
platform
::
dynload
::
cudnnGetConvolutionForward
Algorithm
(
platform
::
dynload
::
cudnnGetConvolutionForward
WorkspaceSize
(
handle
,
cudnn_input_desc
,
cudnn_filter_desc
,
cudnn_conv_desc
,
cudnn_output_desc
,
CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT
,
workspace_size_limit
,
&
algo
));
algo
,
&
workspace_size_in_bytes
));
if
(
workspace_size_in_bytes
>
workspace_size_limit
)
workspace_size_limit
=
workspace_size_in_bytes
;
VLOG
(
3
)
<<
"cuDNN forward algo "
<<
algo
;
#endif
}
else
{
std
::
function
<
cudnnConvolutionFwdAlgo_t
()
>
search_func
=
[
&
]()
->
cudnnConvolutionFwdAlgo_t
{
std
::
function
<
SearchFuseResult
<
cudnnConvolutionFwdAlgo_t
>
()
>
search_func
=
[
&
]()
->
SearchFuseResult
<
cudnnConvolutionFwdAlgo_t
>
{
int
returned_algo_count
;
SearchFuseResult
<
cudnnConvolutionFwdAlgo_t
>
fwd_result
;
std
::
array
<
cudnnConvolutionFwdAlgoPerf_t
,
kNUM_CUDNN_FWD_ALGS
>
fwd_perf_stat
;
auto
cudnn_find_func
=
[
&
](
void
*
cudnn_workspace
)
{
...
...
@@ -402,11 +404,34 @@ class CUDNNConvFusionOpKernel : public framework::OpKernel<T> {
VLOG
(
3
)
<<
stat
.
algo
<<
": "
<<
stat
.
status
<<
" "
<<
stat
.
time
<<
" "
<<
stat
.
memory
;
}
return
fwd_perf_stat
[
0
].
algo
;
PADDLE_ENFORCE_GPU_SUCCESS
(
platform
::
dynload
::
cudnnGetConvolutionForwardWorkspaceSize
(
handle
,
cudnn_input_desc
,
cudnn_filter_desc
,
cudnn_conv_desc
,
cudnn_output_desc
,
fwd_perf_stat
[
0
].
algo
,
&
workspace_size_in_bytes
));
// PADDLE_ENFORCE_LE(
// workspace_size_in_bytes,
// workspace_size_limit,
// platform::errors::InvalidArgument(
// "The actual workspace size to be allocated for cuDNN is
// expected " "to be less than the limit. But received: the
// actual workspace " "size = %d, limit = %d.",
// workspace_size_in_bytes,
// workspace_size_limit));
fwd_result
.
algo
=
fwd_perf_stat
[
0
].
algo
;
fwd_result
.
workspace_size
=
workspace_size_in_bytes
;
return
fwd_result
;
};
AlgorithmsCache
<
cudnnConvolutionFwdAlgo_t
>&
algo_cache
=
AlgorithmsCache
<
SearchFuseResult
<
cudnnConvolutionFwdAlgo_t
>
>&
algo_cache
=
*
(
framework
::
ConvSearchCache
::
Instance
().
GetConvFusion
());
int
search_times
=
ctx
.
Attr
<
int
>
(
"search_times"
);
SearchFuseResult
<
cudnnConvolutionFwdAlgo_t
>
algo_result
;
search_times
=
std
::
max
(
static_cast
<
int
>
(
FLAGS_cudnn_exhaustive_search_times
),
search_times
);
// TODO(dangqingqing): Unify this if-else.
...
...
@@ -414,39 +439,24 @@ class CUDNNConvFusionOpKernel : public framework::OpKernel<T> {
// The searched algo will be cached by `search_times` times for
// different input dimension. For other dimensions, select the algo
// of closest area.
algo
=
algo_cache
.
GetAlgorithm
(
algo
_result
=
algo_cache
.
GetAlgorithm
(
x_dims
[
2
]
*
x_dims
[
3
],
search_times
,
0
,
search_func
);
algo
=
algo_result
.
algo
;
workspace_size_in_bytes
=
algo_result
.
workspace_size
;
}
else
{
algo
=
algo_cache
.
GetAlgorithm
(
x_dims
,
f_dims
,
strides
,
paddings
,
dilations
,
0
,
dtype
,
search_func
);
algo_result
=
algo_cache
.
GetAlgorithm
(
x_dims
,
f_dims
,
strides
,
paddings
,
dilations
,
0
,
dtype
,
search_func
);
algo
=
algo_result
.
algo
;
workspace_size_in_bytes
=
algo_result
.
workspace_size
;
}
VLOG
(
3
)
<<
"choose algo "
<<
algo
;
}
PADDLE_ENFORCE_GPU_SUCCESS
(
platform
::
dynload
::
cudnnGetConvolutionForwardWorkspaceSize
(
handle
,
cudnn_input_desc
,
cudnn_filter_desc
,
cudnn_conv_desc
,
cudnn_output_desc
,
algo
,
&
workspace_size_in_bytes
));
// PADDLE_ENFORCE_LE(
// workspace_size_in_bytes,
// workspace_size_limit,
// platform::errors::InvalidArgument(
// "The actual workspace size to be allocated for cuDNN is expected
// " "to be less than the limit. But received: the actual workspace
// " "size = %d, limit = %d.", workspace_size_in_bytes,
// workspace_size_limit));
if
((
activation
==
"identity"
)
&&
(
!
residual
))
{
// Only the CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM algo is
// enabled with CUDNN_ACTIVATION_IDENTITY in cuDNN lib.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录