Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
9488cd1c
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9488cd1c
编写于
4月 26, 2022
作者:
M
Megvii Engine Team
提交者:
dengzheye
5月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(lite): fix lite cpu default not work
GitOrigin-RevId: 8fc764623cacf3994be09a343c7560cbd933d15c
上级
518c7f37
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
2 deletion
+66
-2
lite/src/mge/network_impl.cpp
lite/src/mge/network_impl.cpp
+15
-2
lite/test/test_network.cpp
lite/test/test_network.cpp
+51
-0
未找到文件。
lite/src/mge/network_impl.cpp
浏览文件 @
9488cd1c
...
@@ -67,10 +67,15 @@ void NetworkImplDft::shared_weight_with(const NetworkImplBase* src_network) {
...
@@ -67,10 +67,15 @@ void NetworkImplDft::shared_weight_with(const NetworkImplBase* src_network) {
void
NetworkImplDft
::
application_config
()
{
void
NetworkImplDft
::
application_config
()
{
auto
device_type
=
m_user_config
->
device_type
;
auto
device_type
=
m_user_config
->
device_type
;
m_compnode_locator
.
type
=
to_compnode_locator
(
device_type
).
type
;
m_compnode_locator
.
type
=
to_compnode_locator
(
device_type
).
type
;
m_compnode_locator
.
device
=
m_user_config
->
device_id
;
//! when the device id is not configured, configure it
if
(
m_compnode_locator
.
device
==
-
1
)
{
m_compnode_locator
.
device
=
m_user_config
->
device_id
;
}
if
(
m_nr_threads
>
1
&&
device_type
==
LiteDeviceType
::
LITE_CPU
)
{
if
(
m_nr_threads
>
1
&&
device_type
==
LiteDeviceType
::
LITE_CPU
)
{
m_compnode_locator
.
type
=
mgb
::
CompNode
::
DeviceType
::
MULTITHREAD
;
m_compnode_locator
.
type
=
mgb
::
CompNode
::
DeviceType
::
MULTITHREAD
;
m_compnode_locator
.
device
=
m_user_config
->
device_id
;
if
(
m_compnode_locator
.
device
==
-
1
)
{
m_compnode_locator
.
device
=
m_user_config
->
device_id
;
}
}
}
//! model options
//! model options
#define ConfigOption(mge_name, lite_name) \
#define ConfigOption(mge_name, lite_name) \
...
@@ -155,11 +160,13 @@ void NetworkImplDft::set_cpu_inplace_mode() {
...
@@ -155,11 +160,13 @@ void NetworkImplDft::set_cpu_inplace_mode() {
m_is_cpu_inplace_mode
=
true
;
m_is_cpu_inplace_mode
=
true
;
if
(
m_compnode_locator
.
type
==
mgb
::
CompNode
::
DeviceType
::
CPU
)
{
if
(
m_compnode_locator
.
type
==
mgb
::
CompNode
::
DeviceType
::
CPU
)
{
m_compnode_locator
.
device
=
mgb
::
CompNode
::
Locator
::
DEVICE_CPU_DEFAULT
;
m_compnode_locator
.
device
=
mgb
::
CompNode
::
Locator
::
DEVICE_CPU_DEFAULT
;
m_user_config
->
device_id
=
mgb
::
CompNode
::
Locator
::
DEVICE_CPU_DEFAULT
;
}
else
{
}
else
{
LITE_ASSERT
(
LITE_ASSERT
(
m_compnode_locator
.
type
==
CompNode
::
DeviceType
::
MULTITHREAD
,
m_compnode_locator
.
type
==
CompNode
::
DeviceType
::
MULTITHREAD
,
"cpu inplace mode is only avaliable in CPU."
);
"cpu inplace mode is only avaliable in CPU."
);
m_compnode_locator
.
device
=
mgb
::
CompNode
::
Locator
::
DEVICE_MULTITHREAD_DEFAULT
;
m_compnode_locator
.
device
=
mgb
::
CompNode
::
Locator
::
DEVICE_MULTITHREAD_DEFAULT
;
m_user_config
->
device_id
=
mgb
::
CompNode
::
Locator
::
DEVICE_MULTITHREAD_DEFAULT
;
}
}
}
}
...
@@ -170,6 +177,12 @@ void NetworkImplDft::set_cpu_threads_number(size_t nr_threads) {
...
@@ -170,6 +177,12 @@ void NetworkImplDft::set_cpu_threads_number(size_t nr_threads) {
if
(
nr_threads
>
1
)
{
if
(
nr_threads
>
1
)
{
m_nr_threads
=
nr_threads
;
m_nr_threads
=
nr_threads
;
m_compnode_locator
.
type
=
mgb
::
CompNode
::
DeviceType
::
MULTITHREAD
;
m_compnode_locator
.
type
=
mgb
::
CompNode
::
DeviceType
::
MULTITHREAD
;
if
(
m_is_cpu_inplace_mode
)
{
m_compnode_locator
.
device
=
mgb
::
CompNode
::
Locator
::
DEVICE_MULTITHREAD_DEFAULT
;
m_user_config
->
device_id
=
mgb
::
CompNode
::
Locator
::
DEVICE_MULTITHREAD_DEFAULT
;
}
m_compnode_locator
.
nr_threads
=
nr_threads
;
m_compnode_locator
.
nr_threads
=
nr_threads
;
}
}
}
}
...
...
lite/test/test_network.cpp
浏览文件 @
9488cd1c
...
@@ -216,6 +216,57 @@ TEST(TestNetWork, BasicInplaceAndSingleThreadAffinity) {
...
@@ -216,6 +216,57 @@ TEST(TestNetWork, BasicInplaceAndSingleThreadAffinity) {
compare_lite_tensor
<
float
>
(
output_tensor
,
result_mgb
);
compare_lite_tensor
<
float
>
(
output_tensor
,
result_mgb
);
}
}
namespace
{
void
test_multi_thread
(
bool
multi_thread_compnode
)
{
Config
config
;
auto
lite_tensor
=
get_input_data
(
"./input_data.npy"
);
std
::
string
model_path
=
"./shufflenet.mge"
;
size_t
nr_threads
=
2
;
std
::
vector
<
std
::
thread
::
id
>
thread_ids
(
nr_threads
);
auto
runner
=
[
&
](
size_t
i
)
{
std
::
shared_ptr
<
Network
>
network
=
std
::
make_shared
<
Network
>
(
config
);
Runtime
::
set_cpu_inplace_mode
(
network
);
if
(
multi_thread_compnode
)
{
Runtime
::
set_cpu_threads_number
(
network
,
2
);
}
network
->
load_model
(
model_path
);
Runtime
::
set_runtime_thread_affinity
(
network
,
[
&
thread_ids
,
i
](
int
id
)
{
if
(
id
==
0
)
{
thread_ids
[
i
]
=
std
::
this_thread
::
get_id
();
}
});
std
::
shared_ptr
<
Tensor
>
input_tensor
=
network
->
get_input_tensor
(
0
);
auto
src_ptr
=
lite_tensor
->
get_memory_ptr
();
auto
src_layout
=
lite_tensor
->
get_layout
();
input_tensor
->
reset
(
src_ptr
,
src_layout
);
network
->
forward
();
network
->
wait
();
std
::
shared_ptr
<
Tensor
>
output_tensor
=
network
->
get_output_tensor
(
0
);
};
std
::
vector
<
std
::
thread
>
threads
;
for
(
size_t
i
=
0
;
i
<
nr_threads
;
i
++
)
{
threads
.
emplace_back
(
runner
,
i
);
}
for
(
size_t
i
=
0
;
i
<
nr_threads
;
i
++
)
{
threads
[
i
].
join
();
}
ASSERT_NE
(
thread_ids
[
0
],
thread_ids
[
1
]);
}
}
// namespace
TEST
(
TestNetWork
,
InplaceAndUserMultithreadThread
)
{
test_multi_thread
(
false
);
}
TEST
(
TestNetWork
,
InplaceAndMultithread
)
{
test_multi_thread
(
true
);
}
TEST
(
TestNetWork
,
NetworkShareWeights
)
{
TEST
(
TestNetWork
,
NetworkShareWeights
)
{
Config
config
;
Config
config
;
auto
lite_tensor
=
get_input_data
(
"./input_data.npy"
);
auto
lite_tensor
=
get_input_data
(
"./input_data.npy"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录