Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
50f73877
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
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看板
提交
50f73877
编写于
9月 14, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(opr): let Copy and Identity support empty IO
GitOrigin-RevId: 4e49d8eae8ba1055c3b639d02b3e0949f82fd235
上级
74cbc10d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
56 addition
and
2 deletion
+56
-2
imperative/python/test/unit/functional/test_tensor.py
imperative/python/test/unit/functional/test_tensor.py
+29
-0
imperative/src/impl/opr_utility.cpp
imperative/src/impl/opr_utility.cpp
+1
-0
src/opr/impl/io.cpp
src/opr/impl/io.cpp
+3
-1
src/opr/impl/utility.cpp
src/opr/impl/utility.cpp
+8
-1
src/opr/include/megbrain/opr/utility.h
src/opr/include/megbrain/opr/utility.h
+1
-0
src/opr/test/io.cpp
src/opr/test/io.cpp
+14
-0
未找到文件。
imperative/python/test/unit/functional/test_tensor.py
浏览文件 @
50f73877
...
...
@@ -711,6 +711,35 @@ def test_copy_d2d(is_varnode):
copy_test
(
"gpu0:0"
,
"gpu0:1"
,
network
=
network
)
@
pytest
.
mark
.
require_ngpu
(
2
)
@
pytest
.
mark
.
parametrize
(
"shape, device_src, device_dst"
,
[
((
0
,),
"cpu0"
,
"cpu0"
),
((
10
,
0
),
"cpu0"
,
"cpu1"
),
((
2
,
0
,
3
),
"cpu0"
,
"gpu0"
),
((
1
,
0
,
1
,
0
),
"gpu0"
,
"cpu0"
),
((
2
,
3
,
4
,
5
,
0
),
"gpu0"
,
"gpu1"
),
],
)
@
pytest
.
mark
.
parametrize
(
"is_symbolic"
,
[
None
,
True
,
False
])
def
test_copy_empty
(
shape
,
device_src
,
device_dst
,
is_symbolic
):
inp
=
tensor
(
np
.
random
.
randn
(
*
shape
).
astype
(
"float32"
),
device
=
device_src
)
def
func
(
inp
):
return
F
.
copy
(
inp
,
device_dst
)
if
is_symbolic
is
not
None
:
func
=
trace
(
symbolic
=
is_symbolic
)(
func
)
for
_
in
range
(
3
):
out
=
func
(
inp
)
assert
out
.
numpy
().
shape
==
shape
assert
out
.
device
==
device_dst
if
is_symbolic
is
None
:
break
@
pytest
.
mark
.
parametrize
(
"shape, repeats, axis"
,
[
...
...
imperative/src/impl/opr_utility.cpp
浏览文件 @
50f73877
...
...
@@ -170,6 +170,7 @@ void OutputCallback::init_output_static_infer_desc() {}
cg
::
OperatorNodeBase
::
NodeProp
*
OutputCallback
::
do_make_node_prop
()
const
{
NodeProp
*
prop
=
Super
::
do_make_node_prop
();
prop
->
add_flag
(
NodeProp
::
Flag
::
NO_AUTOMATIC_DUP
);
prop
->
add_flag
(
NodeProp
::
Flag
::
CROSS_COMP_NODE_MEMORY
);
SmallVector
<
NodeProp
::
DepType
>
dep_types
(
input
().
size
(),
NodeProp
::
DepType
::
DEV_COMP_ORDER
);
using
IT
=
cg
::
static_infer
::
InferType
;
...
...
src/opr/impl/io.cpp
浏览文件 @
50f73877
...
...
@@ -708,7 +708,7 @@ Copy::Copy(VarNode *inp, const OperatorNodeConfig &config):
Super
{
inp
->
owner_graph
(),
config
,
"copy"
,
{
inp
}}
{
add_input
({
inp
});
add_output
(
None
);
add_output
(
None
)
->
add_flag
(
VarNode
::
Flag
::
ALLOW_EMPTY_SHAPE
)
;
}
SymbolVar
Copy
::
make
(
SymbolVar
inp
,
const
OperatorNodeConfig
&
config
)
{
...
...
@@ -767,6 +767,8 @@ Copy::NodeProp* Copy::do_make_node_prop() const {
using
F
=
NodeProp
::
Flag
;
rst
->
add_flag
(
F
::
CROSS_COMP_NODE_MEMORY
);
rst
->
add_flag
(
F
::
NO_AUTOMATIC_DUP
);
rst
->
add_dep_type_existing_var
(
input
(
0
),
NodeProp
::
DepType
::
VALUE_ALLOW_EMPTY
);
return
rst
;
}
...
...
src/opr/impl/utility.cpp
浏览文件 @
50f73877
...
...
@@ -423,7 +423,7 @@ Identity::Identity(VarNode* input, const OperatorNodeConfig &config):
Super
(
input
->
owner_graph
(),
config
,
"identity"
,
{
input
})
{
add_input
({
input
});
add_output
(
None
);
add_output
(
None
)
->
add_flag
(
VarNode
::
Flag
::
ALLOW_EMPTY_SHAPE
)
;
set_ignore_side_effect
();
}
...
...
@@ -437,6 +437,13 @@ SymbolVar Identity::make(
return
input
.
insert_single_output_opr
<
Identity
>
(
input
.
node
(),
config
);
}
Identity
::
NodeProp
*
Identity
::
do_make_node_prop
()
const
{
auto
ret
=
Super
::
do_make_node_prop
();
ret
->
add_dep_type_existing_var
(
input
(
0
),
NodeProp
::
DepType
::
VALUE_ALLOW_EMPTY
);
return
ret
;
}
#if MGB_ENABLE_GRAD
MGB_IMPL_OPR_GRAD
(
Identity
)
{
return
out_grad
.
at
(
0
);
...
...
src/opr/include/megbrain/opr/utility.h
浏览文件 @
50f73877
...
...
@@ -277,6 +277,7 @@ MGB_DEFINE_OPR_CLASS(MarkNoBroadcastElemwise, intl::ForwardInputToOutput) // {
* its gradient can be correctly computed.
*/
MGB_DEFINE_OPR_CLASS
(
Identity
,
intl
::
ForwardInputToOutput
)
// {
NodeProp
*
do_make_node_prop
()
const
override
;
public
:
using
Param
=
megdnn
::
param
::
Empty
;
Identity
(
VarNode
*
input
,
const
OperatorNodeConfig
&
config
);
...
...
src/opr/test/io.cpp
浏览文件 @
50f73877
...
...
@@ -406,6 +406,20 @@ TEST(TestOprIO, D2DNonContig) {
MGB_ASSERT_TENSOR_EQ
(
host_y
,
except_y
);
}
TEST
(
TestOprIO
,
D2DCopyEmpty
)
{
auto
cns
=
load_multiple_xpus
(
2
);
HostTensorGenerator
<>
gen
;
auto
host_x
=
gen
({
2
,
0
,
3
,
0
,
4
},
cns
[
0
]);
auto
graph
=
ComputingGraph
::
make
();
auto
x
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_x
).
rename
(
"x"
),
y
=
(
opr
::
Copy
::
make
(
x
,
{
cns
[
1
]})).
rename
(
"y"
);
HostTensorND
host_y
;
auto
func
=
graph
->
compile
({
make_callback_copy
(
y
,
host_y
)});
func
->
execute
();
ASSERT_TRUE
(
host_y
.
layout
().
is_empty
());
ASSERT_EQ
(
host_y
.
layout
(),
host_x
->
layout
());
}
TEST
(
TestOprIO
,
MultipleDeviceTensorHolder
)
{
auto
cns
=
load_multiple_xpus
(
2
);
HostTensorGenerator
<>
gen0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录