Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
45ba9cf0
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看板
未验证
提交
45ba9cf0
编写于
6月 14, 2023
作者:
A
Aurelius84
提交者:
GitHub
6月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IR]Polish ProgramTranslator private member code style (#54470)
* [IR]Polish ProgramTranslator private member code style * update blog
上级
548fb821
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
35 deletion
+35
-35
paddle/fluid/ir_adaptor/translator/program_translator.cc
paddle/fluid/ir_adaptor/translator/program_translator.cc
+29
-29
paddle/fluid/ir_adaptor/translator/program_translator.h
paddle/fluid/ir_adaptor/translator/program_translator.h
+6
-6
未找到文件。
paddle/fluid/ir_adaptor/translator/program_translator.cc
浏览文件 @
45ba9cf0
...
...
@@ -40,8 +40,8 @@ using VarDesc = ::paddle::framework::VarDesc;
ProgramTranslator
::
ProgramTranslator
(
const
ProgramDesc
*
legacy_program
,
ir
::
Program
*
program
)
:
legacy_program
(
legacy_program
),
program
(
program
)
{
ctx
=
ir
::
IrContext
::
Instance
();
:
legacy_program
_
(
legacy_program
),
program_
(
program
)
{
ctx
_
=
ir
::
IrContext
::
Instance
();
}
const
std
::
unordered_set
<
std
::
string
>
ProgramTranslator
::
no_cast_var_names
=
{
...
...
@@ -51,24 +51,24 @@ const std::unordered_set<std::string> ProgramTranslator::no_cast_var_names = {
void
ProgramTranslator
::
Translate
()
{
PADDLE_ENFORCE_EQ
(
legacy_program
->
Size
(),
legacy_program
_
->
Size
(),
1u
,
platform
::
errors
::
PreconditionNotMet
(
"Not support multi block ProgramDesc translated, now has %d blocks"
,
legacy_program
->
Size
()));
legacy_program
_
->
Size
()));
for
(
size_t
block_idx
=
0
;
block_idx
<
legacy_program
->
Size
();
block_idx
++
)
{
const
BlockDesc
&
block
=
legacy_program
->
Block
(
block_idx
);
for
(
size_t
block_idx
=
0
;
block_idx
<
legacy_program
_
->
Size
();
block_idx
++
)
{
const
BlockDesc
&
block
=
legacy_program
_
->
Block
(
block_idx
);
GetParameterForSingleBlock
(
block
);
}
for
(
size_t
block_idx
=
0
;
block_idx
<
legacy_program
->
Size
();
block_idx
++
)
{
const
BlockDesc
&
block
=
legacy_program
->
Block
(
block_idx
);
for
(
size_t
block_idx
=
0
;
block_idx
<
legacy_program
_
->
Size
();
block_idx
++
)
{
const
BlockDesc
&
block
=
legacy_program
_
->
Block
(
block_idx
);
InsertOperationToSingleBlock
(
block
);
}
for
(
size_t
block_idx
=
0
;
block_idx
<
legacy_program
->
Size
();
block_idx
++
)
{
const
BlockDesc
&
block
=
legacy_program
->
Block
(
block_idx
);
for
(
size_t
block_idx
=
0
;
block_idx
<
legacy_program
_
->
Size
();
block_idx
++
)
{
const
BlockDesc
&
block
=
legacy_program
_
->
Block
(
block_idx
);
SetParameterFromSingleBlock
(
block
);
}
}
...
...
@@ -105,28 +105,28 @@ inline ir::Operation* InsertSetParamaterOp(ir::IrContext* ctx,
void
ProgramTranslator
::
GetParameterForSingleBlock
(
const
BlockDesc
&
block
)
{
for
(
auto
&
var
:
block
.
AllVars
())
{
if
(
!
var
->
Persistable
())
continue
;
if
(
param_map
.
count
(
var
->
Name
())
!=
0
)
continue
;
if
(
param_map
_
.
count
(
var
->
Name
())
!=
0
)
continue
;
if
(
no_cast_var_names
.
count
(
var
->
Name
())
!=
0
)
continue
;
parameter_name_mappings
[
var
->
Name
()]
=
var
;
parameter_name_mappings
_
[
var
->
Name
()]
=
var
;
}
for
(
auto
op_desc
:
block
.
AllOps
())
{
for
(
const
auto
&
n
:
op_desc
->
Inputs
())
{
const
auto
&
input_var_names
=
n
.
second
;
for
(
const
auto
&
var_name
:
input_var_names
)
{
bool
need_get_parameter_op
=
(
parameter_name_mappings
.
find
(
var_name
)
!=
parameter_name_mappings
.
end
());
need_get_parameter_op
&=
(
parameter_visited
.
count
(
var_name
)
==
0
);
bool
need_get_parameter_op
=
(
parameter_name_mappings
_
.
find
(
var_name
)
!=
parameter_name_mappings
_
.
end
());
need_get_parameter_op
&=
(
parameter_visited
_
.
count
(
var_name
)
==
0
);
if
(
need_get_parameter_op
)
{
ir
::
Operation
*
op
=
InsertGetParamaterOp
(
ctx
,
parameter_name_mappings
[
var_name
]);
program
->
block
()
->
push_back
(
op
);
param_map
[
var_name
]
=
VariableDefiningInfo
(
op
->
result
(
0
));
InsertGetParamaterOp
(
ctx
_
,
parameter_name_mappings_
[
var_name
]);
program
_
->
block
()
->
push_back
(
op
);
param_map
_
[
var_name
]
=
VariableDefiningInfo
(
op
->
result
(
0
));
VLOG
(
10
)
<<
"[op translated][get parameter]"
<<
op
;
program
->
SetParameter
(
var_name
,
nullptr
);
parameter_visited
.
insert
(
var_name
);
program
_
->
SetParameter
(
var_name
,
nullptr
);
parameter_visited
_
.
insert
(
var_name
);
}
}
}
...
...
@@ -137,7 +137,7 @@ void ProgramTranslator::InsertOperationToSingleBlock(const BlockDesc& block) {
auto
&
op_translator
=
OpTranslator
::
instance
();
for
(
auto
op
:
block
.
AllOps
())
{
OpTranslateFn
&
fn
=
op_translator
[
op
->
Type
()];
ir
::
Operation
*
operation
=
fn
(
ctx
,
&
param_map
,
program
,
*
op
);
ir
::
Operation
*
operation
=
fn
(
ctx
_
,
&
param_map_
,
program_
,
*
op
);
VLOG
(
10
)
<<
"[op translated][special]"
<<
operation
;
}
}
...
...
@@ -148,15 +148,15 @@ void ProgramTranslator::SetParameterFromSingleBlock(const BlockDesc& block) {
for
(
const
auto
&
n
:
(
*
op_desc
)
->
Outputs
())
{
const
auto
&
output_var_names
=
n
.
second
;
for
(
const
auto
&
var_name
:
output_var_names
)
{
bool
need_set_parameter_op
=
(
parameter_name_mappings
.
find
(
var_name
)
!=
parameter_name_mappings
.
end
());
need_set_parameter_op
&=
(
parameter_visited
.
count
(
var_name
)
==
0
);
bool
need_set_parameter_op
=
(
parameter_name_mappings
_
.
find
(
var_name
)
!=
parameter_name_mappings
_
.
end
());
need_set_parameter_op
&=
(
parameter_visited
_
.
count
(
var_name
)
==
0
);
if
(
need_set_parameter_op
)
{
ir
::
OpResult
defining_op_result
=
param_map
[
var_name
].
value
;
ir
::
OpResult
defining_op_result
=
param_map
_
[
var_name
].
value
;
ir
::
Operation
*
op
=
InsertSetParamaterOp
(
ctx
,
defining_op_result
,
parameter_name_mappings
[
var_name
]);
ctx
_
,
defining_op_result
,
parameter_name_mappings_
[
var_name
]);
ir
::
Block
*
block
=
program
->
block
();
ir
::
Block
*
block
=
program
_
->
block
();
ir
::
Block
::
iterator
insert_pos
=
std
::
find
(
block
->
begin
(),
block
->
end
(),
defining_op_result
.
owner
());
...
...
@@ -169,8 +169,8 @@ void ProgramTranslator::SetParameterFromSingleBlock(const BlockDesc& block) {
block
->
insert
(
insert_pos
,
op
);
VLOG
(
10
)
<<
"[op translated][set parameter]"
<<
op
;
program
->
SetParameter
(
var_name
,
nullptr
);
parameter_visited
.
insert
(
var_name
);
program
_
->
SetParameter
(
var_name
,
nullptr
);
parameter_visited
_
.
insert
(
var_name
);
}
}
}
...
...
paddle/fluid/ir_adaptor/translator/program_translator.h
浏览文件 @
45ba9cf0
...
...
@@ -59,13 +59,13 @@ class ProgramTranslator {
void
Translate
();
private:
const
ProgramDesc
*
legacy_program
;
// not owned
ir
::
Program
*
program
;
// not owned
ir
::
IrContext
*
ctx
;
// not owned
const
ProgramDesc
*
legacy_program
_
;
// not owned
ir
::
Program
*
program
_
;
// not owned
ir
::
IrContext
*
ctx
_
;
// not owned
TranslationContext
param_map
;
std
::
unordered_map
<
std
::
string
,
VarDesc
*>
parameter_name_mappings
;
std
::
unordered_set
<
std
::
string
>
parameter_visited
;
TranslationContext
param_map
_
;
std
::
unordered_map
<
std
::
string
,
VarDesc
*>
parameter_name_mappings
_
;
std
::
unordered_set
<
std
::
string
>
parameter_visited
_
;
/// In the legacy program desc, there are two special named varibales:
/// 1. "feed", the input variable of feed op
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录