Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
0a47387b
P
Paddle
项目概览
OPTHREE
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0a47387b
编写于
8月 07, 2020
作者:
L
Leo Chen
提交者:
GitHub
8月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use static local variable instead of global variable for safty (#26018)
* remove global variable * refine code
上级
07f509a8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
33 deletion
+36
-33
paddle/fluid/framework/unused_var_check.cc
paddle/fluid/framework/unused_var_check.cc
+36
-33
未找到文件。
paddle/fluid/framework/unused_var_check.cc
浏览文件 @
0a47387b
...
...
@@ -28,38 +28,6 @@ DEFINE_bool(enable_unused_var_check, false,
"Checking whether operator contains unused inputs, "
"especially for grad operator. It should be in unittest."
);
// NOTE(zhiqiu): Currently, there are some operators which involves unused
// inputs and cannot be removed from the allow_list below.
// They can be mainly divided into four categories:
// 0: the inputs of which are only used in if branch, or used in cuda kernel but
// not in cpu kernel;
// 1: the inputs of which are used to indicate dtype of outputs;
// 2: the inputs of which are used in fused operators.
// The category number is presented in the comments after each operator.
const
std
::
unordered_set
<
std
::
string
>
op_with_unsed_vars_allow_list
=
{
"batch_norm"
,
// 0
"batch_norm_grad"
,
// 0
"sync_batch_norm"
,
// 0
"sync_batch_norm_grad"
,
// 0
"inplace_abn"
,
// 0
"inplace_abn_grad"
,
// 0
"dgc_momentum"
,
// 0
"fake_quantize_range_abs_max"
,
// 0
"rmsprop"
,
// 0
"sequence_conv_grad"
,
// 0
"roi_perspective_transform_grad"
,
// 0
"fill_zeros_like"
,
// 1
"fill_any_like"
,
// 1
"nce_grad"
,
// 1
"precision_recall"
,
// 1
"fusion_seqpool_cvm_concat"
,
// 2
"fused_batch_norm_act"
,
// 2
"fused_batch_norm_act_grad"
,
// 2
"data_norm"
,
// 0
"data_norm_grad"
,
// 0
};
namespace
paddle
{
namespace
framework
{
...
...
@@ -75,9 +43,44 @@ void LogVarUsageIfUnusedVarCheckEnabled(const std::string &name) {
}
}
static
const
std
::
unordered_set
<
std
::
string
>
&
GetOpWithUnusedVarAllowSet
()
{
// NOTE(zhiqiu): Currently, there are some operators which involves unused
// inputs and cannot be removed from the allow_list below.
// They can be mainly divided into four categories:
// 0: the inputs of which are only used in if branch, or used in cuda kernel
// but not in cpu kernel; 1: the inputs of which are used to indicate dtype of
// outputs; 2: the inputs of which are used in fused operators. The category
// number is presented in the comments after each operator.
// Use pointer here for safe static deinitialization
static
auto
*
allow_set
=
new
std
::
unordered_set
<
std
::
string
>
({
// called once
"batch_norm"
,
// 0
"batch_norm_grad"
,
// 0
"sync_batch_norm"
,
// 0
"sync_batch_norm_grad"
,
// 0
"inplace_abn"
,
// 0
"inplace_abn_grad"
,
// 0
"dgc_momentum"
,
// 0
"fake_quantize_range_abs_max"
,
// 0
"rmsprop"
,
// 0
"sequence_conv_grad"
,
// 0
"roi_perspective_transform_grad"
,
// 0
"fill_zeros_like"
,
// 1
"fill_any_like"
,
// 1
"nce_grad"
,
// 1
"precision_recall"
,
// 1
"fusion_seqpool_cvm_concat"
,
// 2
"fused_batch_norm_act"
,
// 2
"fused_batch_norm_act_grad"
,
// 2
"data_norm"
,
// 0
"data_norm_grad"
,
// 0);
});
return
*
allow_set
;
}
void
CheckUnusedVar
(
const
OperatorBase
&
op
,
const
Scope
&
scope
)
{
// skip op in allow list.
if
(
op_with_unsed_vars_allow_list
.
count
(
op
.
Type
())
!=
0
)
{
if
(
GetOpWithUnusedVarAllowSet
()
.
count
(
op
.
Type
())
!=
0
)
{
return
;
}
auto
*
used_set
=
GetThreadLocalUsedVarNameSet
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录