Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
044695aa
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
044695aa
编写于
4月 02, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mgb/plugin): add profiler for dynamic graph
GitOrigin-RevId: 10a6cccff9d2889ea2abd05faccccb82263e3cfe
上级
8b0315b3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
121 addition
and
0 deletion
+121
-0
python_module/CMakeLists.txt
python_module/CMakeLists.txt
+3
-0
python_module/src/swig/comp_graph.i
python_module/src/swig/comp_graph.i
+9
-0
python_module/test/unit/core/test_dynamic_profiling.py
python_module/test/unit/core/test_dynamic_profiling.py
+53
-0
src/core/impl/graph/cg_impl.cpp
src/core/impl/graph/cg_impl.cpp
+44
-0
src/core/impl/graph/cg_impl.h
src/core/impl/graph/cg_impl.h
+4
-0
src/core/include/megbrain/graph/cg.h
src/core/include/megbrain/graph/cg.h
+8
-0
未找到文件。
python_module/CMakeLists.txt
浏览文件 @
044695aa
...
...
@@ -10,6 +10,9 @@ find_package(Numpy REQUIRED)
find_package
(
SWIG REQUIRED
)
set
(
SWIG_SRC src/swig/mgb.i
)
set
(
CMAKE_SWIG_FLAGS -Wall -threads -py3 -modern -DSWIGWORDSIZE64
)
if
(
MGB_ENABLE_JSON
)
set
(
CMAKE_SWIG_FLAGS
${
CMAKE_SWIG_FLAGS
}
-DMGB_ENABLE_JSON
)
endif
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-unused-parameter"
)
if
(
MGE_WITH_DISTRIBUTED
)
...
...
python_module/src/swig/comp_graph.i
浏览文件 @
044695aa
...
...
@@ -69,6 +69,15 @@ class CompGraph {
return
reinterpret_cast
<
size_t
>
(
&
$self->get());
}
std
::
string
get_dynamic_info
()
const
{
#
ifdef
MGB_ENABLE_JSON
auto
jsonstr
=
self-
>
get
()
.
get_dynamic_info
()
;
return
jsonstr-
>
to_string
()
;
#
else
return
std
::
string
(
""
)
;
#
endif
}
std
::
string
__repr__
()
const
{
auto
&
&graph
=
$self->get();
return
mgb
::
ssprintf
(
"<CompGraph #%zu at %p>"
,
graph
.
id
(),
&
graph);
...
...
python_module/test/unit/core/test_dynamic_profiling.py
0 → 100644
浏览文件 @
044695aa
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import
json
import
numpy
as
np
import
megengine.functional
as
F
from
megengine
import
graph
,
tensor
def
test_dynmaic_profiling
():
sz
=
16
cg
=
graph
.
get_default_graph
()
x
=
tensor
(
np
.
arange
(
0
,
sz
,
dtype
=
np
.
float32
))
y
=
F
.
relu
(
x
)
str1
=
cg
.
get_dynamic_info
()
if
str1
==
""
:
return
json_str1
=
json
.
loads
(
str1
)
z
=
F
.
add_update
(
x
,
y
)
json_str2
=
json
.
loads
(
cg
.
get_dynamic_info
())
diff
=
lambda
l1
,
l2
:
[
x
for
x
in
l1
if
x
not
in
l2
]
jdiff
=
diff
(
json_str2
,
json_str1
)
assert
len
(
jdiff
)
==
1
,
"add_update operator should produce only one opr internally"
dest_key
=
list
(
jdiff
[
0
].
keys
())[
0
]
assert
(
jdiff
[
0
][
dest_key
][
"output"
][
0
][
"memory"
]
==
sz
*
4
),
"output of add_update operator has wrong allocated size"
# check add_update is inplace or not
dest_ptr
=
jdiff
[
0
][
dest_key
][
"output"
][
0
][
"dev_ptr"
]
found
=
False
for
li
in
json_str1
:
if
"0"
in
li
.
keys
():
src_ptr
=
li
[
"0"
][
"output"
][
0
][
"dev_ptr"
]
found
=
dest_ptr
==
src_ptr
assert
found
==
True
,
"add_update is not inplace"
src/core/impl/graph/cg_impl.cpp
浏览文件 @
044695aa
...
...
@@ -726,4 +726,48 @@ std::string ComputingGraphImpl::VarReceiverInfo::to_string() const {
allow_empty_value
);
}
#if MGB_ENABLE_JSON
std
::
shared_ptr
<
json
::
Value
>
ComputingGraphImpl
::
get_dynamic_info
()
const
{
auto
make_var_json
=
[](
VarNode
*
single_var
)
{
auto
&&
cur_mem_plan
=
single_var
->
mem_plan
();
if
(
cur_mem_plan
.
valid
())
return
json
::
Object
::
make
({
{
"name"
,
json
::
String
::
make
(
single_var
->
name
())},
{
"memory"
,
json
::
Number
::
make
(
cur_mem_plan
.
chunk
().
size
())},
{
"dev_ptr"
,
json
::
NumberInt
::
make
(
reinterpret_cast
<
size_t
>
(
single_var
->
dev_tensor
().
raw_ptr
()))}
});
else
return
json
::
Object
::
make
({
{
"name"
,
json
::
String
::
make
(
single_var
->
name
())},
{
"memory"
,
json
::
Null
::
make
()},
{
"dev_ptr"
,
json
::
Null
::
make
()}
});
};
auto
objlist
=
json
::
Array
::
make
();
for
(
auto
&
opri
:
m_opr_refkeeper
){
auto
cur_opr
=
opri
.
get
();
auto
objptr
=
json
::
Object
::
make
();
auto
&&
objbody
=
*
objptr
;
objbody
[
"name"
]
=
json
::
String
::
make
(
cur_opr
->
name
());
auto
jvars
=
json
::
Array
::
make
();
for
(
auto
&
outputi
:
cur_opr
->
output
()){
jvars
->
add
(
make_var_json
(
outputi
));
}
objbody
[
"output"
]
=
jvars
;
auto
obj
=
json
::
Object
::
make
({{
std
::
to_string
(
cur_opr
->
id
()),
objptr
}});
objlist
->
add
(
obj
);
}
return
objlist
;
}
#endif // MGB_ENABLE_JSON
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
src/core/impl/graph/cg_impl.h
浏览文件 @
044695aa
...
...
@@ -146,6 +146,10 @@ public:
return
m_var_receiver
.
at
(
var
);
}
#if MGB_ENABLE_JSON
std
::
shared_ptr
<
json
::
Value
>
get_dynamic_info
()
const
override
;
#endif
VarNode
*
find_var_by_id
(
size_t
id
)
const
override
;
TopoSorter
&
topo_sorter
()
{
return
components
().
topo_sorter
;
}
...
...
src/core/include/megbrain/graph/cg.h
浏览文件 @
044695aa
...
...
@@ -17,6 +17,10 @@
#include "megbrain/graph/seq_comp_node_opt.h"
#include "megbrain/utils/event.h"
#if MGB_ENABLE_JSON
#include "megbrain/utils/json.h"
#endif
namespace
mgb
{
namespace
cg
{
...
...
@@ -171,6 +175,10 @@ class ComputingGraph : public std::enable_shared_from_this<ComputingGraph>,
virtual
const
VarReceiverInfo
&
var_receiver_in_current_comp_seq
(
const
VarNode
*
var
)
const
=
0
;
#if MGB_ENABLE_JSON
virtual
std
::
shared_ptr
<
json
::
Value
>
get_dynamic_info
()
const
=
0
;
#endif
/*!
* \brief find var node by its ID
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录