Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
d782edf8
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看板
提交
d782edf8
编写于
7月 11, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(mgb): decouple node insertion from ComputingGraphImpl
GitOrigin-RevId: 59b45fcb17be8ca9b94c1cb4eabf7ed949967f08
上级
d42cf4cd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
48 addition
and
14 deletion
+48
-14
src/core/impl/graph/bases.cpp
src/core/impl/graph/bases.cpp
+1
-3
src/core/impl/graph/cg_impl.cpp
src/core/impl/graph/cg_impl.cpp
+8
-0
src/core/impl/graph/cg_impl.h
src/core/impl/graph/cg_impl.h
+5
-1
src/core/impl/graph/operator_node.cpp
src/core/impl/graph/operator_node.cpp
+2
-5
src/core/include/megbrain/graph/cg.h
src/core/include/megbrain/graph/cg.h
+22
-0
src/core/include/megbrain/utils/mempool.h
src/core/include/megbrain/utils/mempool.h
+10
-5
未找到文件。
src/core/impl/graph/bases.cpp
浏览文件 @
d782edf8
...
...
@@ -18,11 +18,9 @@ GraphNodeBase::GraphNodeBase(ComputingGraph *owner_graph):
m_owner_graph
{
owner_graph
}
{
mgb_assert
(
owner_graph
,
"owner graph not given"
);
auto
id
=
static_cast
<
ComputingGraphImpl
*>
(
owner_graph
)
->
next_node_id
();
m_id
=
id
;
m_id
=
owner_graph
->
next_node_id
();
}
AsyncExecutable
::~
AsyncExecutable
()
noexcept
=
default
;
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
src/core/impl/graph/cg_impl.cpp
浏览文件 @
d782edf8
...
...
@@ -267,6 +267,14 @@ void ComputingGraphImpl::cleanup() {
m_opr_refkeeper
.
clear
();
}
void
*
ComputingGraphImpl
::
alloc_varnode_storage
()
{
return
m_var_node_pool
.
alloc_raw
();
};
void
ComputingGraphImpl
::
free_varnode_storage
(
void
*
ptr
)
{
m_var_node_pool
.
free_raw
(
ptr
);
};
OperatorNodeBase
*
ComputingGraphImpl
::
insert_opr
(
std
::
unique_ptr
<
OperatorNodeBase
>
opr_uniqp
)
{
auto
opr
=
opr_uniqp
.
get
();
...
...
src/core/impl/graph/cg_impl.h
浏览文件 @
d782edf8
...
...
@@ -142,6 +142,10 @@ public:
OperatorNodeBase
*
insert_opr
(
std
::
unique_ptr
<
OperatorNodeBase
>
opr
)
override
;
void
*
alloc_varnode_storage
()
override
;
void
free_varnode_storage
(
void
*
ptr
)
override
;
const
VarReceiverInfo
&
var_receiver_in_current_comp_seq
(
const
VarNode
*
var
)
const
override
;
...
...
@@ -161,7 +165,7 @@ public:
TopoSorter
&
topo_sorter
()
{
return
components
().
topo_sorter
;
}
size_t
next_node_id
()
{
return
(
*
m_node_id_counter
)
++
;
}
size_t
next_node_id
()
override
{
return
(
*
m_node_id_counter
)
++
;
}
VarNodeMemManager
&
var_node_mem_manager
()
{
return
components
().
var_node_mem_manager
;
...
...
src/core/impl/graph/operator_node.cpp
浏览文件 @
d782edf8
...
...
@@ -93,10 +93,8 @@ OperatorNodeBase::OperatorNodeBase(ComputingGraph *owner,
}
OperatorNodeBase
::~
OperatorNodeBase
()
noexcept
{
auto
&&
pool
=
ComputingGraphImpl
::
cast
(
owner_graph
())
->
var_node_pool
();
for
(
auto
i
:
m_output
)
{
pool
.
fre
e
(
i
);
owner_graph
()
->
free_varnod
e
(
i
);
}
}
...
...
@@ -264,8 +262,7 @@ VarNode* OperatorNodeBase::add_output(const Maybe<std::string> &name) {
mgb_assert
(
!
m_inserted_in_graph
&&
!
m_node_prop
.
valid
(),
"add output on opr after it has been inserted into graph"
);
auto
ptr
=
ComputingGraphImpl
::
cast
(
owner_graph
())
->
var_node_pool
().
alloc
(
auto
ptr
=
owner_graph
()
->
alloc_varnode
(
name
.
valid
()
?
this
->
name
()
+
":"
+
name
.
val
()
:
name
,
this
);
m_output
.
push_back
(
ptr
);
return
ptr
;
...
...
src/core/include/megbrain/graph/cg.h
浏览文件 @
d782edf8
...
...
@@ -174,6 +174,8 @@ class ComputingGraph : public std::enable_shared_from_this<ComputingGraph>,
return
m_id
;
}
virtual
size_t
next_node_id
()
=
0
;
static
std
::
shared_ptr
<
ComputingGraph
>
make
();
//! assert that refcnt for ptr is one and destories the ptr
...
...
@@ -235,6 +237,26 @@ class ComputingGraph : public std::enable_shared_from_this<ComputingGraph>,
virtual
OperatorNodeBase
*
insert_opr
(
std
::
unique_ptr
<
OperatorNodeBase
>
opr
)
=
0
;
/*!
* \brief used by OperatorNodeBase to allocate its outputs
*/
template
<
typename
...
Args
>
VarNode
*
alloc_varnode
(
Args
&&
...
args
)
{
return
new
(
alloc_varnode_storage
())
VarNode
(
std
::
forward
<
Args
>
(
args
)...);
}
inline
void
free_varnode
(
VarNode
*
var
)
{
var
->~
VarNode
();
free_varnode_storage
(
var
);
}
protected:
/*!
* \brief provided by impl to support alloc_varnode
*/
virtual
void
*
alloc_varnode_storage
()
=
0
;
virtual
void
free_varnode_storage
(
void
*
ptr
)
=
0
;
public:
/*!
* \brief get current computing sequence
*/
...
...
src/core/include/megbrain/utils/mempool.h
浏览文件 @
d782edf8
...
...
@@ -86,12 +86,17 @@ namespace mgb {
};
using
UniquePtr
=
std
::
unique_ptr
<
T
,
Deleter
>
;
void
*
alloc_raw
()
{
return
m_storage
.
alloc
(
Const
<>::
ELEM_SIZE
);
}
void
free_raw
(
void
*
ptr
)
{
m_storage
.
free
(
ptr
);
}
template
<
typename
...
Args
>
T
*
alloc
(
Args
&&
...
args
)
{
auto
ptr
=
static_cast
<
T
*>
(
m_storage
.
alloc
(
Const
<>::
ELEM_SIZE
));
new
(
ptr
)
T
(
std
::
forward
<
Args
>
(
args
)...);
return
ptr
;
return
new
(
alloc_raw
())
T
(
std
::
forward
<
Args
>
(
args
)...);
}
template
<
typename
...
Args
>
...
...
@@ -102,7 +107,7 @@ namespace mgb {
void
free
(
T
*
ptr
)
{
ptr
->~
T
();
m_storage
.
free
(
ptr
);
free_raw
(
ptr
);
}
//! reorder free list for cache friendly in future alloc
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录