Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
178a93b9
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
178a93b9
编写于
8月 29, 2019
作者:
T
tensor-tang
提交者:
GitHub
8月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] enable npu program rollback (#1906)
test=develop
上级
53b05ce8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
27 addition
and
30 deletion
+27
-30
lite/core/mir/subgraph/generate_npu_program_pass.cc
lite/core/mir/subgraph/generate_npu_program_pass.cc
+16
-19
lite/core/mir/subgraph/generate_npu_program_pass.h
lite/core/mir/subgraph/generate_npu_program_pass.h
+4
-4
lite/core/optimizer.h
lite/core/optimizer.h
+5
-7
lite/npu/npu_helper.cc
lite/npu/npu_helper.cc
+2
-0
未找到文件。
lite/core/mir/subgraph/generate_npu_program_pass.cc
浏览文件 @
178a93b9
...
...
@@ -127,7 +127,8 @@ std::string GenerateNPUProgramPass::BuildNPUGraph(
std
::
string
model_name
(
"hiai_npu_client_"
+
std
::
to_string
(
sub_id
)
+
".om"
);
if
(
!
npu
::
BuildNPUClient
(
inputs
,
outputs
,
model_name
))
{
LOG
(
FATAL
)
<<
"Build NPU failed subgraph "
<<
sub_id
;
LOG
(
WARNING
)
<<
"Build NPU failed subgraph "
<<
sub_id
;
throw
std
::
runtime_error
(
"Build NPU failed subgraph."
);
}
LOG
(
INFO
)
<<
"[NPU] Build NPU Client success subgraph "
<<
sub_id
;
return
model_name
;
...
...
@@ -188,7 +189,7 @@ void GenerateNPUProgramPass::InsertNewNode(
ContextScheduler
::
Global
().
NewContext
(
inst
.
picked_kernel
().
target
()));
}
void
GenerateNPUProgramPass
::
GenNPU
GraphOpNode
(
void
GenerateNPUProgramPass
::
GenNPU
Subgraph
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
,
const
std
::
unordered_set
<
Node
*>&
op_nodes
,
int
sub_id
)
{
...
...
@@ -199,9 +200,6 @@ void GenerateNPUProgramPass::GenNPUGraphOpNode(
FindInputOutputVars
(
op_nodes
,
&
in_data_vars
,
&
in_wgt_vars
,
&
out_data_vars
,
&
out_unused_vars
);
auto
nodes2rm
=
GetNode2rm
(
op_nodes
,
{
in_data_vars
,
in_wgt_vars
,
out_data_vars
,
out_unused_vars
});
auto
model_name
=
BuildNPUGraph
(
op_nodes
,
in_data_vars
,
out_data_vars
,
sub_id
);
...
...
@@ -215,33 +213,34 @@ void GenerateNPUProgramPass::GenNPUGraphOpNode(
out_data_vars
,
out_unused_vars
);
auto
nodes2rm
=
GetNode2rm
(
op_nodes
,
{
in_data_vars
,
in_wgt_vars
,
out_data_vars
,
out_unused_vars
});
GraphSafeRemoveNodes
(
graph
.
get
(),
nodes2rm
);
}
void
GenerateNPUProgramPass
::
Convert
Subgraph
(
void
GenerateNPUProgramPass
::
GenAllNPU
Subgraph
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
,
int
sub_num
)
{
std
::
unordered_map
<
int
,
std
::
unordered_set
<
Node
*>>
nodes_all
;
int
ops_num
=
0
;
std
::
unordered_map
<
int
,
std
::
unordered_set
<
Node
*>>
all_op_nodes
;
for
(
auto
&
item
:
graph
->
StmtTopologicalOrder
())
{
if
(
!
item
->
IsStmt
())
continue
;
ops_num
++
;
auto
&
stmt
=
item
->
AsStmt
();
int
sub_id
=
stmt
.
subgraph_id
();
if
(
sub_id
<
1
)
continue
;
if
(
nodes_all
.
count
(
sub_id
)
==
0
)
{
nodes_all
[
sub_id
]
=
std
::
unordered_set
<
Node
*>
();
if
(
all_op_nodes
.
count
(
sub_id
)
==
0
)
{
all_op_nodes
[
sub_id
]
=
std
::
unordered_set
<
Node
*>
();
}
nodes_all
.
at
(
sub_id
).
insert
(
item
);
all_op_nodes
.
at
(
sub_id
).
insert
(
item
);
}
for
(
int
id
=
1
;
id
<=
sub_num
;
++
id
)
{
LOG
(
INFO
)
<<
"Converting subgraph_id:"
<<
id
;
GenNPU
GraphOpNode
(
graph
,
nodes_all
.
at
(
id
),
id
);
GenNPU
Subgraph
(
graph
,
all_op_nodes
.
at
(
id
),
id
);
}
}
void
GenerateNPUProgramPass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
LOG
(
INFO
)
<<
"Before NPU Pass
\n
"
<<
Visualize
(
graph
.
get
());
VLOG
(
3
)
<<
"Before NPU Pass
\n
"
<<
Visualize
(
graph
.
get
());
const
auto
&
bridges
=
lite
::
npu
::
bridge
::
Factory
::
Instance
();
const
auto
&
op_map
=
bridges
.
AllFunctions
();
...
...
@@ -254,16 +253,14 @@ void GenerateNPUProgramPass::Apply(const std::unique_ptr<SSAGraph>& graph) {
try
{
int
num_subgraph
=
FuseSubgraph
(
graph
,
supported_op_types
);
LOG
(
INFO
)
<<
"detected "
<<
num_subgraph
<<
" NPU subgraph"
;
InferOnce
(
graph
);
Convert
Subgraph
(
graph
,
num_subgraph
);
GenAllNPU
Subgraph
(
graph
,
num_subgraph
);
}
catch
(...)
{
// exception = true;
LOG
(
WARNING
)
<<
"Build NPU graph failed"
;
throw
std
::
runtime_error
(
"Build NPU graph failed"
);
}
LOG
(
INFO
)
<<
"After NPU Pass
\n
"
<<
Visualize
(
graph
.
get
());
VLOG
(
3
)
<<
"After NPU Pass
\n
"
<<
Visualize
(
graph
.
get
());
for
(
auto
&
item
:
graph
->
StmtTopologicalOrder
())
{
if
(
item
->
IsStmt
())
{
auto
&
stmt
=
item
->
AsStmt
();
...
...
lite/core/mir/subgraph/generate_npu_program_pass.h
浏览文件 @
178a93b9
...
...
@@ -64,11 +64,11 @@ class GenerateNPUProgramPass : public SubgraphProgramPass {
std
::
unordered_set
<
Node
*>
out_data_vars
,
std
::
unordered_set
<
Node
*>
out_unused_vars
);
void
GenNPU
GraphOpNode
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
,
const
std
::
unordered_set
<
Node
*>&
nodes_all
,
int
sub_id
);
void
GenNPU
Subgraph
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
,
const
std
::
unordered_set
<
Node
*>&
nodes_all
,
int
sub_id
);
void
Convert
Subgraph
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
,
int
sub_num
);
void
GenAllNPU
Subgraph
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
,
int
sub_num
);
private:
std
::
vector
<
Instruction
>
insts_
;
...
...
lite/core/optimizer.h
浏览文件 @
178a93b9
...
...
@@ -118,18 +118,16 @@ class Optimizer {
auto
pass
=
mir
::
PassManager
::
Global
()
.
LookUp
<
mir
::
subgraph
::
GenerateNPUProgramPass
>
(
"generate_npu_program_pass"
);
pass
->
Apply
(
graph_
);
auto
program
=
pass
->
GenProgram
();
if
(
program
)
{
try
{
pass
->
Apply
(
graph_
);
auto
program
=
pass
->
GenProgram
();
CHECK
(
exec_scope_
);
program
->
set_exec_scope
(
exec_scope_
);
return
program
;
}
else
{
LOG
(
WARNING
)
<<
"Build NPU graph failed
.
"
;
}
catch
(...)
{
LOG
(
WARNING
)
<<
"Build NPU graph failed"
;
}
}
#endif
auto
pass
=
mir
::
PassManager
::
Global
().
LookUp
<
mir
::
GenerateProgramPass
>
(
"generate_program_pass"
);
...
...
lite/npu/npu_helper.cc
浏览文件 @
178a93b9
...
...
@@ -56,6 +56,7 @@ bool BuildNPUClient(const void* om_model_data,
if
(
ret
!=
hiai
::
AI_SUCCESS
)
{
LOG
(
WARNING
)
<<
"[NPU] Failed building NPU client "
<<
name
<<
", ret: "
<<
ret
;
throw
std
::
runtime_error
(
""
);
return
false
;
}
...
...
@@ -71,6 +72,7 @@ bool BuildNPUClient(const void* om_model_data,
model_desc
.
push_back
(
desc
);
if
(
client
->
Load
(
model_desc
)
!=
hiai
::
AI_SUCCESS
)
{
LOG
(
WARNING
)
<<
"[NPU] Model Load Failed: "
<<
desc
->
GetName
();
throw
std
::
runtime_error
(
""
);
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录