Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
d42cc8d1
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看板
未验证
提交
d42cc8d1
编写于
5月 07, 2020
作者:
Z
zhupengyang
提交者:
GitHub
5月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] init device tensor when needed (#3552)
上级
17a0837f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
15 deletion
+39
-15
lite/kernels/npu/bridges/engine.cc
lite/kernels/npu/bridges/engine.cc
+3
-0
lite/kernels/npu/bridges/engine.h
lite/kernels/npu/bridges/engine.h
+1
-0
lite/kernels/npu/subgraph_compute.cc
lite/kernels/npu/subgraph_compute.cc
+30
-14
lite/kernels/npu/subgraph_compute.h
lite/kernels/npu/subgraph_compute.h
+4
-0
lite/tools/ci_build.sh
lite/tools/ci_build.sh
+1
-1
未找到文件。
lite/kernels/npu/bridges/engine.cc
浏览文件 @
d42cc8d1
...
...
@@ -95,6 +95,8 @@ int Engine::Build() {
return
build_device_program_status_
;
}
void
Engine
::
InitDeviceTensor
()
{
return
;
}
bool
Engine
::
InputShapeChanged
()
{
for
(
size_t
i
=
0
;
i
<
origin_itensors_
.
size
();
i
++
)
{
if
(
origin_itensors_
[
i
]
->
dims
()
!=
origin_idims_
[
i
])
{
...
...
@@ -110,6 +112,7 @@ int Engine::Launch() {
CHECK_REBUILD_WHEN_SHAPE_CHANGED
(
build_device_program_status_
)
&&
InputShapeChanged
())
{
Build
();
InitDeviceTensor
();
}
if
(
CHECK_FAILED
(
build_device_program_status_
))
{
LaunchOriginProgram
();
...
...
lite/kernels/npu/bridges/engine.h
浏览文件 @
d42cc8d1
...
...
@@ -55,6 +55,7 @@ class Engine {
virtual
int
BuildOriginProgram
();
virtual
int
LaunchOriginProgram
();
virtual
void
InitDeviceTensor
();
virtual
bool
InputShapeChanged
();
KernelContext
*
ctx_
{
nullptr
};
...
...
lite/kernels/npu/subgraph_compute.cc
浏览文件 @
d42cc8d1
...
...
@@ -195,18 +195,6 @@ int SubgraphEngine::LaunchDeviceProgram() {
// Copy the data of origin input tensors to the buffer of input HiAI tensors
// init device_itensors_, device_otensors_, origin_otensors_
auto
device_program
=
device_program_map_
[
inputs_shape_
];
for
(
size_t
i
=
0
;
i
<
device_itensors_
.
size
();
i
++
)
{
device_itensors_
[
i
]
->
Init
(
&
(
device_program
->
device_idims
[
i
]));
std
::
memcpy
(
device_itensors_
[
i
]
->
GetBuffer
(),
origin_itensors_
[
i
]
->
raw_data
(),
origin_itensors_
[
i
]
->
memory_size
());
}
for
(
size_t
i
=
0
;
i
<
device_otensors_
.
size
();
i
++
)
{
device_otensors_
[
i
]
->
Init
(
&
(
device_program
->
device_odims
[
i
]));
}
for
(
size_t
i
=
0
;
i
<
origin_otensors_
.
size
();
i
++
)
{
origin_otensors_
[
i
]
->
Resize
(
device_program
->
origin_odims
[
i
]);
}
// Run the HiAI model by name
std
::
string
key
=
"model_name"
;
// Note: key seems must be model_name
...
...
@@ -233,15 +221,43 @@ int SubgraphEngine::LaunchDeviceProgram() {
return
0
;
}
int
SubgraphEngine
::
Build
()
{
if
(
device_program_map_
.
count
(
inputs_shape_
)
>
0
)
{
return
subgraph
::
SUCCESS
;
}
// In order to attach all of the ops of the block desc, we need to build the
// original program firstly.
BuildOriginProgram
();
// Run InferShape() of all of ops, and convert Paddle ops to NPU/XPU IR graph
build_device_program_status_
=
BuildDeviceProgram
();
return
build_device_program_status_
;
}
void
SubgraphEngine
::
InitDeviceTensor
()
{
auto
device_program
=
device_program_map_
[
inputs_shape_
];
for
(
size_t
i
=
0
;
i
<
device_itensors_
.
size
();
i
++
)
{
device_itensors_
[
i
]
->
Init
(
&
(
device_program
->
device_idims
[
i
]));
std
::
memcpy
(
device_itensors_
[
i
]
->
GetBuffer
(),
origin_itensors_
[
i
]
->
raw_data
(),
origin_itensors_
[
i
]
->
memory_size
());
}
for
(
size_t
i
=
0
;
i
<
device_otensors_
.
size
();
i
++
)
{
device_otensors_
[
i
]
->
Init
(
&
(
device_program
->
device_odims
[
i
]));
}
for
(
size_t
i
=
0
;
i
<
origin_otensors_
.
size
();
i
++
)
{
origin_otensors_
[
i
]
->
Resize
(
device_program
->
origin_odims
[
i
]);
}
}
bool
SubgraphEngine
::
InputShapeChanged
()
{
std
::
vector
<
std
::
vector
<
int64_t
>>
new_shape
;
for
(
auto
origin_itensor
:
origin_itensors_
)
{
new_shape
.
push_back
(
origin_itensor
->
dims
().
Vectorize
());
}
inputs_shape_
=
new_shape
;
if
(
device_program_map_
.
count
(
inputs_shape_
)
>
0
)
{
if
(
inputs_shape_
==
new_shape
)
{
return
false
;
}
inputs_shape_
=
new_shape
;
return
true
;
}
...
...
lite/kernels/npu/subgraph_compute.h
浏览文件 @
d42cc8d1
...
...
@@ -49,9 +49,13 @@ class SubgraphEngine : public subgraph::Engine {
std
::
vector
<
hiai
::
TensorDimension
>
device_odims
{};
};
int
Build
()
override
;
protected:
int
BuildDeviceProgram
()
override
;
int
LaunchDeviceProgram
()
override
;
void
InitDeviceTensor
()
override
;
bool
InputShapeChanged
()
override
;
std
::
string
model_name_
{
"model.om"
};
...
...
lite/tools/ci_build.sh
浏览文件 @
d42cc8d1
...
...
@@ -396,7 +396,7 @@ function test_arm_android {
adb
-s
${
device
}
push
${
testpath
}
${
adb_work_dir
}
adb
-s
${
device
}
shell
"cd
${
adb_work_dir
}
&& ./
${
test_name
}
"
adb
-s
${
device
}
shell
"rm
${
adb_work_dir
}
/
${
test_name
}
"
adb
-s
${
device
}
shell
"rm
-f
${
adb_work_dir
}
/
${
test_name
}
"
}
# test_npu <some_test_name> <adb_port_number>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录