Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
09d2b7c3
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看板
提交
09d2b7c3
编写于
6月 09, 2020
作者:
M
Megvii Engine Team
提交者:
Xu Xinran
6月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(core): make the semantics of instance id clear and correct
GitOrigin-RevId: 2232195c50e02482c8737ff70ab9d1c709bda6ee
上级
2b4b4d66
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
74 addition
and
21 deletion
+74
-21
src/core/impl/graph/operator_node.cpp
src/core/impl/graph/operator_node.cpp
+2
-2
src/core/impl/graph/seq_sublinear_memory.cpp
src/core/impl/graph/seq_sublinear_memory.cpp
+7
-4
src/core/include/megbrain/graph/operator_node.h
src/core/include/megbrain/graph/operator_node.h
+24
-11
src/core/test/graph/misc.cpp
src/core/test/graph/misc.cpp
+37
-0
src/gopt/impl/misc.cpp
src/gopt/impl/misc.cpp
+1
-1
src/gopt/test/misc.cpp
src/gopt/test/misc.cpp
+1
-1
src/jit/impl/internal_graph.cpp
src/jit/impl/internal_graph.cpp
+2
-2
未找到文件。
src/core/impl/graph/operator_node.cpp
浏览文件 @
09d2b7c3
...
...
@@ -485,14 +485,14 @@ OperatorNodeConfig& OperatorNodeConfig::comp_node_arr(
size_t
OperatorNodeConfig
::
hash
()
const
{
return
hash_pair_combine
(
hash_pair_combine
(
m
gb
::
hash
(
m_instance_id
)
,
mgb
::
hash
(
m_comp_node
)),
hash_pair_combine
(
m
_instance_id_hashed
,
mgb
::
hash
(
m_comp_node
)),
mgb
::
hash
(
m_output_dtype
.
handle
()));
}
bool
OperatorNodeConfig
::
is_same_st
(
const
Hashable
&
rhs_
)
const
{
auto
&&
rhs
=
static_cast
<
const
OperatorNodeConfig
&>
(
rhs_
);
return
m_comp_node
==
rhs
.
m_comp_node
&&
m_instance_id
==
rhs
.
m_instance_i
d
&&
m_instance_id
_hashed
==
rhs
.
m_instance_id_hashe
d
&&
m_output_dtype
==
rhs
.
m_output_dtype
;
}
...
...
src/core/impl/graph/seq_sublinear_memory.cpp
浏览文件 @
09d2b7c3
...
...
@@ -1225,14 +1225,17 @@ bool SeqModifierForSublinearMemory::replace_vars(const VarNodeArray& inputs) {
OperatorNodeBase
*
SeqModifierForSublinearMemory
::
copy_opr_from_new_inputs
(
OperatorNodeBase
*
opr
,
bool
recomp
)
{
auto
config
=
opr
->
config
();
//
set
operator instance id to bybass the shallow copy's cache if
//
update
operator instance id to bybass the shallow copy's cache if
// it's a dup-opr-copying due to discarding.
// Don't set instance id(nullptr) if it's a recomp-opr-copying, because:
// Don't update instance id by `this` pointer if it's a recomp-opr-copying
// because:
// 0) recomp-opr would be copied iff its input vars is changed
// 1) some pair of recomp-opr and dup-opr have the same inputs, params
// and config, we use instance id to differentiate them.
config
.
name
(
opr
->
name
()
+
(
recomp
?
":recomp"
:
":dup"
))
.
instance_id
(
recomp
?
nullptr
:
this
);
config
.
name
(
opr
->
name
()
+
(
recomp
?
":recomp"
:
":dup"
));
if
(
!
recomp
)
{
config
.
update_instance_id
(
this
);
}
// Note: if all outputs of op were placed on the same comp_node, since its
// stream maybe changed during seq_comp_node_opt, output's comp_node has
...
...
src/core/include/megbrain/graph/operator_node.h
浏览文件 @
09d2b7c3
...
...
@@ -70,24 +70,36 @@ class OperatorNodeConfig final: public Hashable {
}
/*!
* \brief
set instance id
* \brief
update instance ID
*
* Instance
id is used to differentiate multiple instances of the sam
e
*
operator (with same inputs, params and config), so the deduplication
* system can be bypassed.
* Instance
ID is a hashed value used to differentiate multipl
e
*
instances of the same operator (with same inputs, params and
*
config), so the deduplication
system can be bypassed.
*
*
Currently only used for sublinear memory optimization
.
*
This method always updates underlying instance_id
.
*/
OperatorNodeConfig
&
instance_id
(
const
void
*
id
)
{
m_instance_id
=
id
;
template
<
typename
T
>
OperatorNodeConfig
&
update_instance_id
(
const
T
&
p
)
{
static_assert
(
std
::
is_pointer
<
T
>::
value
,
"update_instance_id can only accept a pointer"
);
m_instance_id_hashed
=
hash_pair_combine
(
m_instance_id_hashed
,
mgb
::
hash
(
p
));
return
*
this
;
}
/*!
* \brief
get current instance ID
* \brief
reset instance ID to the initial value
*/
const
void
*
instance_id
()
const
{
return
m_instance_id
;
OperatorNodeConfig
&
reset_instance_id
()
{
m_instance_id_hashed
=
sm_initial_instance_id
;
return
*
this
;
}
/*!
* \brief get current hashed instance ID
*/
size_t
instance_id
()
const
{
return
m_instance_id_hashed
;
}
/*!
...
...
@@ -133,9 +145,10 @@ class OperatorNodeConfig final: public Hashable {
bool
is_same_st
(
const
Hashable
&
rhs
)
const
override
;
private:
static
constexpr
size_t
sm_initial_instance_id
=
1333331
;
Maybe
<
std
::
string
>
m_name
;
CompNodeArray
m_comp_node
;
const
void
*
m_instance_id
=
nullptr
;
size_t
m_instance_id_hashed
=
sm_initial_instance_id
;
DType
m_output_dtype
;
};
...
...
src/core/test/graph/misc.cpp
浏览文件 @
09d2b7c3
...
...
@@ -1777,4 +1777,41 @@ TEST(TestGraph, In2OutOpStreamPropagate) {
}
}
TEST
(
TestGraph
,
OperatorNodeConfigInstanceID
)
{
OperatorNodeConfig
config0
,
config1
;
void
*
p0
=
&
config0
,
*
p1
=
&
config1
;
{
// set and reset
ASSERT_EQ
(
config0
.
instance_id
(),
config1
.
instance_id
());
config0
.
update_instance_id
(
p0
);
ASSERT_NE
(
config0
.
instance_id
(),
config1
.
instance_id
());
config0
.
reset_instance_id
();
ASSERT_EQ
(
config0
.
instance_id
(),
config1
.
instance_id
());
}
{
// set to the same pointer
config0
.
reset_instance_id
();
config0
.
update_instance_id
(
p1
);
config1
.
reset_instance_id
();
config1
.
update_instance_id
(
p1
);
ASSERT_EQ
(
config0
.
instance_id
(),
config1
.
instance_id
());
}
{
// check update semantics
config0
.
reset_instance_id
();
config0
.
update_instance_id
(
p0
);
config1
.
reset_instance_id
();
config1
.
update_instance_id
(
p1
);
ASSERT_NE
(
config0
.
instance_id
(),
config1
.
instance_id
());
config0
.
update_instance_id
(
p1
);
ASSERT_NE
(
config0
.
instance_id
(),
config1
.
instance_id
());
}
{
// set in different order
config0
.
reset_instance_id
();
config0
.
update_instance_id
(
p1
);
config0
.
update_instance_id
(
p0
);
config1
.
reset_instance_id
();
config1
.
update_instance_id
(
p0
);
config1
.
update_instance_id
(
p1
);
ASSERT_NE
(
config0
.
instance_id
(),
config1
.
instance_id
());
}
}
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
src/gopt/impl/misc.cpp
浏览文件 @
09d2b7c3
...
...
@@ -361,7 +361,7 @@ void RecompTypeCvtPass::apply(OptState& opt) const {
size_t
prev_step
=
iter
->
second
;
if
(
step
-
prev_step
>
m_threshold
)
{
OperatorNodeConfig
config
=
opr
->
config
();
config
.
instance_id
(
opr
);
config
.
update_
instance_id
(
opr
);
opt
.
call_with_opr
(
typecvt
,
[
&
]{
auto
new_typecvt
=
opr
::
TypeCvt
::
make
(
...
...
src/gopt/test/misc.cpp
浏览文件 @
09d2b7c3
...
...
@@ -261,7 +261,7 @@ TEST_PASS(RecompTypeCvtPass, Basic) {
}
auto
for_pass
=
f
+
x_fp32
;
OperatorNodeConfig
config
=
x_fp32
.
node
()
->
owner_opr
()
->
config
();
config
.
instance_id
(
for_pass
.
node
()
->
owner_opr
());
config
.
update_
instance_id
(
for_pass
.
node
()
->
owner_opr
());
auto
expected
=
f
+
opr
::
TypeCvt
::
make
(
sin_x
,
dtype
::
Float32
(),
config
);
...
...
src/jit/impl/internal_graph.cpp
浏览文件 @
09d2b7c3
...
...
@@ -92,8 +92,8 @@ VarNode* InternalGraphGenerator::replace_graph_by_placeholder() {
auto
igraph_copy_opr_shallow
=
[
cpu_default
](
OperatorNodeBase
*
opr
,
const
VarNodeArray
&
inputs
)
{
OperatorNodeConfig
config
=
opr
->
config
();
// re
move
instance_id.
config
.
instance_id
(
nullptr
);
// re
set
instance_id.
config
.
reset_instance_id
(
);
if
(
auto
imm
=
gopt
::
try_cast_as_op
<
opr
::
ImmutableTensor
>
(
opr
))
{
HostTensorND
hval
{
cpu_default
};
hval
.
copy_from
(
imm
->
value
()).
sync
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录