Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_77200941
mindspore
提交
95b3f4fb
M
mindspore
项目概览
2301_77200941
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
95b3f4fb
编写于
8月 23, 2020
作者:
Z
zhaizhiqiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the issue of parallel executor
上级
75af5464
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
22 deletion
+32
-22
mindspore/lite/README.md
mindspore/lite/README.md
+0
-0
mindspore/lite/src/runtime/parallel_executor.cc
mindspore/lite/src/runtime/parallel_executor.cc
+32
-19
mindspore/lite/src/runtime/parallel_executor.h
mindspore/lite/src/runtime/parallel_executor.h
+0
-3
未找到文件。
mindspore/lite/
src/runtime/kernel/arm/nnacl/
README.md
→
mindspore/lite/README.md
浏览文件 @
95b3f4fb
文件已移动
mindspore/lite/src/runtime/parallel_executor.cc
浏览文件 @
95b3f4fb
...
...
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <utility>
#include "src/runtime/parallel_executor.h"
using
mindspore
::
predict
::
ThreadPool
;
using
mindspore
::
predict
::
TvmEnv
;
...
...
@@ -25,25 +26,15 @@ ParallelExecutor::~ParallelExecutor() {
}
int
ParallelExecutor
::
Prepare
(
std
::
vector
<
mindspore
::
kernel
::
LiteKernel
*>
&
kernels
)
{
pool
=
new
ThreadPool
();
pool
->
ConfigThreadPool
(
NO_BIND
,
MAX_THREAD_NUM
);
for
(
mindspore
::
kernel
::
LiteKernel
*
kernel
:
kernels
)
{
re
fCount
[
kernel
]
=
kernel
->
out_kernels
().
size
()
;
if
(
pool
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Memory error: fail to new ThreadPool"
;
re
turn
RET_ERROR
;
}
pool
->
ConfigMaxThreadNum
(
MAX_THREAD_NUM
);
pool
->
ConfigThreadPool
(
NO_BIND
,
MAX_THREAD_NUM
);
return
RET_OK
;
}
void
ParallelExecutor
::
PrepareReadyKernels
(
const
std
::
vector
<
mindspore
::
kernel
::
LiteKernel
*>
&
kernels
)
{
for
(
auto
iter
=
refCount
.
begin
();
iter
!=
refCount
.
end
();)
{
if
(
iter
->
second
==
0
)
{
readyKernels
.
emplace_back
(
iter
->
first
);
iter
=
refCount
.
erase
(
iter
);
}
else
{
iter
++
;
}
}
results
.
resize
(
readyKernels
.
size
());
}
static
int
RunKernel
(
int
index
,
TvmEnv
*
env
,
void
*
data
)
{
ParallelExecutor
*
executor
=
reinterpret_cast
<
ParallelExecutor
*>
(
data
);
auto
kernel
=
executor
->
GetReadyKernel
(
index
);
...
...
@@ -83,27 +74,49 @@ int ParallelExecutor::Run(std::vector<tensor::Tensor *> &in_tensors, std::vector
}
kernel
::
LiteKernelUtil
::
InitTensorRefCount
(
kernels
);
PrepareReadyKernels
(
kernels
);
for
(
auto
kernel
:
kernels
)
{
if
(
kernel
->
in_kernels
().
size
()
==
0
)
{
readyKernels
.
emplace_back
(
kernel
);
continue
;
}
refCount
[
kernel
]
=
kernel
->
in_kernels
().
size
();
}
std
::
vector
<
kernel
::
LiteKernel
*>
newReadyKernels
;
while
(
readyKernels
.
size
()
>
0
)
{
results
.
resize
(
readyKernels
.
size
(),
RET_OK
);
pool
->
LaunchWork
(
RunKernel
,
this
,
readyKernels
.
size
());
if
(
std
::
find_if
(
results
.
begin
(),
results
.
end
(),
[](
const
int
&
ret
)
{
return
(
ret
!=
0
);
})
!=
results
.
end
())
{
return
RET_ERROR
;
}
for
(
auto
completedKernel
:
readyKernels
)
{
for
(
auto
out
:
completedKernel
->
out_kernels
())
{
newReadyKernels
.
clear
();
for
(
auto
completed
:
readyKernels
)
{
for
(
auto
out
:
completed
->
out_kernels
())
{
auto
iter
=
refCount
.
find
(
out
);
if
(
iter
==
refCount
.
end
())
{
continue
;
}
(
iter
->
second
)
--
;
if
(
iter
->
second
<=
0
)
{
newReadyKernels
.
emplace_back
(
iter
->
first
);
refCount
.
erase
(
iter
);
}
}
for
(
auto
input_kernel
:
completed
->
in_kernels
())
{
MS_ASSERT
(
input_kernel
!=
nullptr
);
if
(
input_kernel
->
is_model_output
())
{
continue
;
}
auto
ret
=
input_kernel
->
DecOutTensorRefCount
();
if
(
0
!=
ret
)
{
MS_LOG
(
WARNING
)
<<
"DecOutTensorRefCount for kernel"
<<
completed
->
name
()
<<
" failed"
;
return
-
1
;
}
}
}
readyKernels
.
clear
();
PrepareReadyKernels
(
k
ernels
);
readyKernels
=
std
::
move
(
newReadyK
ernels
);
}
return
RET_OK
;
...
...
mindspore/lite/src/runtime/parallel_executor.h
浏览文件 @
95b3f4fb
...
...
@@ -39,9 +39,6 @@ class ParallelExecutor : public Executor {
inline
kernel
::
LiteKernel
*
GetReadyKernel
(
const
int
index
)
{
return
readyKernels
.
at
(
index
);
}
inline
void
SetResult
(
const
int
index
,
const
int
result
)
{
results
.
at
(
index
)
=
result
;
}
private:
void
PrepareReadyKernels
(
const
std
::
vector
<
kernel
::
LiteKernel
*>
&
kernels
);
private:
predict
::
ThreadPool
*
pool
;
std
::
unordered_map
<
kernel
::
LiteKernel
*
,
size_t
>
refCount
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录