Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
d9487155
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看板
提交
d9487155
编写于
4月 26, 2020
作者:
Z
zhaocai
提交者:
jackzhang235
4月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
save offline model
上级
53b6e51b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
2 deletion
+64
-2
lite/kernels/mlu/bridges/graph.h
lite/kernels/mlu/bridges/graph.h
+10
-1
lite/kernels/mlu/subgraph_compute.h
lite/kernels/mlu/subgraph_compute.h
+54
-1
未找到文件。
lite/kernels/mlu/bridges/graph.h
浏览文件 @
d9487155
...
...
@@ -19,9 +19,11 @@
#include <string>
#include <unordered_map>
#include <vector>
#include "lite/core/op_lite.h"
#include "lite/core/tensor.h"
#include "lite/kernels/mlu/bridges/tensor.h"
#include "lite/utils/env.h"
#define PRINT_HW_TIME false
...
...
@@ -96,7 +98,14 @@ class Graph {
std
::
vector
<
std
::
shared_ptr
<
MLUTensor
>>*
MutableOutputs
()
{
return
&
output_tensors_
;
}
void
GenOfflineModel
(
const
std
::
string
&
name
)
{
cnmlModel_t
model
;
std
::
string
filename
=
name
+
".offline.cambricon"
;
CNML_CALL
(
cnmlCreateModel
(
&
model
,
name
.
c_str
()));
CNML_CALL
(
cnmlAddFusionOpToModel
(
model
,
fusion_op_
,
filename
.
c_str
()));
CNML_CALL
(
cnmlSaveModel
(
model
,
filename
.
c_str
()));
CNML_CALL
(
cnmlDestroyModel
(
model
));
}
void
FuseOp
(
cnmlBaseOp_t
op
)
{
CNML_CALL
(
cnmlFuseOp
(
op
,
fusion_op_
));
}
void
Compile
(
cnmlCoreVersion_t
core_version
,
int
core_number
)
{
...
...
lite/kernels/mlu/subgraph_compute.h
浏览文件 @
d9487155
...
...
@@ -14,10 +14,12 @@
#pragma once
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "lite/api/paddle_place.h"
#include "lite/core/kernel.h"
#include "lite/core/op_registry.h"
...
...
@@ -156,9 +158,60 @@ class SubgraphEngine : public subgraph::Engine {
auto
core_number
=
mlu_context
.
MLUCoreNumber
();
graph
->
Compile
(
core_version
,
core_number
);
shape_graph_map_
[
new_shape
]
=
graph
;
if
(
GetBoolFromEnv
(
"SAVE_MLU_OFFLINE_MODEL"
))
{
graph
->
GenOfflineModel
(
GetOfflineModName
());
}
return
status
;
}
std
::
string
TrimStrings
(
std
::
string
origin_str
)
{
std
::
string
str
=
origin_str
;
std
::
size_t
found
=
str
.
find
(
"0x"
);
std
::
size_t
found_end
=
0
;
std
::
vector
<
std
::
string
>
del_strs
=
{
"/trans_io_copy"
,
"/trans_cast"
,
"/trans_layout"
};
for
(
auto
iterm
:
del_strs
)
{
found_end
=
str
.
find
(
iterm
);
// trim point address and one of the del_strs
if
(
found
!=
std
::
string
::
npos
&&
found_end
!=
std
::
string
::
npos
)
{
str
.
replace
(
found
,
found_end
-
found
,
""
);
found_end
=
str
.
find
(
iterm
);
str
.
replace
(
found_end
,
iterm
.
size
(),
""
);
break
;
}
}
return
str
;
}
std
::
string
GetOfflineModName
()
{
sort
(
input_names_
.
begin
(),
input_names_
.
end
());
sort
(
output_names_
.
begin
(),
output_names_
.
end
());
std
::
string
name
=
""
;
std
::
string
delimiter
=
"__"
;
std
::
string
delimiter_num
=
"_"
;
std
::
string
tmp
=
""
;
for
(
auto
input_name
:
input_names_
)
{
tmp
=
input_name
;
name
+=
TrimStrings
(
tmp
)
+
delimiter
+
"input_shape_"
;
auto
input_tensor
=
scope_
->
FindMutableTensor
(
input_name
);
for
(
auto
iterm
:
input_tensor
->
dims
().
Vectorize
())
{
name
+=
std
::
to_string
(
iterm
)
+
delimiter_num
;
}
name
+=
delimiter
;
}
for
(
auto
output_name
:
output_names_
)
{
tmp
=
output_name
;
name
+=
TrimStrings
(
tmp
)
+
delimiter
+
"output_shape_"
;
auto
output_tensor
=
scope_
->
FindMutableTensor
(
output_name
);
for
(
auto
iterm
:
output_tensor
->
dims
().
Vectorize
())
{
name
+=
std
::
to_string
(
iterm
)
+
delimiter_num
;
}
name
+=
delimiter
;
}
std
::
replace
(
name
.
begin
(),
name
.
end
(),
'/'
,
'-'
);
return
name
;
}
int
LaunchDeviceProgram
()
override
{
// prepare input and output memory
auto
graph
=
shape_graph_map_
[
inputs_shape_
];
...
...
@@ -226,7 +279,7 @@ class SubgraphEngine : public subgraph::Engine {
std
::
map
<
std
::
vector
<
std
::
vector
<
int64_t
>>
,
std
::
shared_ptr
<
paddle
::
lite
::
subgraph
::
mlu
::
Graph
>>
shape_graph_map_
{};
};
};
// namespace mlu
template
<
PrecisionType
Precision
>
class
SubgraphCompute
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录