Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
cd60d268
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看板
体验新版 GitCode,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
提交
cd60d268
编写于
8月 02, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
perf(ops): specialize Broadcast
GitOrigin-RevId: 0cba3e6e938903f6118e0f60bfa01bc8946ee3e5
上级
3fd3e000
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
85 addition
and
25 deletion
+85
-25
imperative/src/impl/ops/broadcast.cpp
imperative/src/impl/ops/broadcast.cpp
+38
-0
imperative/src/impl/ops/reduce.cpp
imperative/src/impl/ops/reduce.cpp
+47
-0
imperative/src/impl/ops/specializations.cpp
imperative/src/impl/ops/specializations.cpp
+0
-25
未找到文件。
imperative/src/impl/ops/broadcast.cpp
浏览文件 @
cd60d268
...
...
@@ -12,6 +12,8 @@
#include "megbrain/imperative/ops/autogen.h"
#include "megbrain/opr/tensor_manip.h"
#include "megbrain/graph/helper.h"
#include "../op_trait.h"
namespace
mgb
{
...
...
@@ -83,10 +85,46 @@ std::tuple<SmallVector<LogicalTensorDesc>, bool> infer_output_attrs_fallible(
return
{{{
TensorLayout
(
out_shape
,
src
.
layout
.
dtype
),
src
.
comp_node
}},
true
};
}
std
::
tuple
<
SmallVector
<
MemoryDesc
>
,
SmallVector
<
MemoryDesc
>>
infer_output_mem_desc
(
const
OpDef
&
def
,
const
SmallVector
<
TensorPtr
>&
inputs_tensors
,
const
SmallVector
<
MemoryDesc
>&
inputs_mems
)
{
auto
&
input
=
inputs_tensors
[
0
];
TensorShape
target_shape
;
cg
::
copy_tensor_value_to_shape
(
target_shape
,
inputs_tensors
[
1
]
->
get_value
().
proxy_to_default_cpu
());
// TODO: memory forward
// if (input->shape().eq_shape(target_shape)) {
// return {{{input->layout(), 0, input->comp_node(), StorageIdentifier::make(&inputs_mems[0])}}, {}};
// }
return
{{{{
target_shape
,
input
->
dtype
()},
0
,
input
->
comp_node
(),
StorageIdentifier
::
make
(
0
)}},
{}};
}
void
execute
(
const
OpDef
&
def
,
SmallVector
<
TensorPtr
>
inputs
,
SmallVector
<
TensorPtr
>
outputs
,
SmallVector
<
TensorPtr
>
workspace
)
{
if
(
outputs
[
0
]
->
layout
().
is_empty
())
{
return
;
}
if
(
inputs
[
0
]
->
shape
().
eq_shape
(
outputs
[
0
]
->
shape
()))
{
mgb_assert
(
inputs
[
0
]
->
layout
().
eq_layout
(
outputs
[
0
]
->
layout
()));
// TODO: memory forward
// mgb_assert(inputs[0]->offset() == outputs[0]->offset());
// mgb_assert(inputs[0]->blob() == outputs[0]->blob());
outputs
[
0
]
->
dev_tensor
().
copy_from_fixlayout
(
inputs
[
0
]
->
dev_tensor
());
}
else
{
TensorLayout
input_layout
=
inputs
[
0
]
->
layout
().
broadcast
(
outputs
[
0
]
->
shape
());
outputs
[
0
]
->
dev_tensor
().
copy_from_fixlayout
(
inputs
[
0
]
->
dev_tensor
().
sub
(
SubTensorSpec
::
make_from_layout
(
input_layout
)));
}
}
OP_TRAIT_REG
(
Broadcast
,
Broadcast
,
opr
::
Broadcast
)
.
make_from_op_node
(
make_from_op_node
)
.
apply_on_var_node
(
apply_on_var_node
)
.
infer_output_attrs_fallible
(
infer_output_attrs_fallible
)
.
infer_output_mem_desc
(
infer_output_mem_desc
)
.
execute
(
execute
)
.
fallback
();
}
// broadcast
...
...
imperative/src/impl/ops/reduce.cpp
0 → 100644
浏览文件 @
cd60d268
/**
* \file imperative/src/impl/ops/reduce.cpp
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
*
* Copyright (c) 2014-2021 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.
*/
#include "megbrain/imperative/ops/autogen.h"
#include "megbrain/opr/basic_arith.h"
#include "../op_trait.h"
#include "../dnn_op_helper.h"
namespace
mgb
{
namespace
imperative
{
namespace
{
namespace
reduce
{
auto
apply_on_var_node
(
const
OpDef
&
def
,
const
VarNodeArray
&
inputs
)
{
auto
&&
reduce
=
static_cast
<
const
Reduce
&>
(
def
);
OperatorNodeConfig
config
{
reduce
.
make_name
()};
if
(
inputs
.
size
()
>
1
)
{
return
opr
::
Reduce
::
make
(
inputs
[
0
],
reduce
.
param
(),
inputs
[
1
],
config
);
}
else
{
return
opr
::
Reduce
::
make
(
inputs
[
0
],
reduce
.
param
(),
(
cg
::
VarNode
*
)
nullptr
,
config
);
}
}
std
::
shared_ptr
<
OpDef
>
make_from_op_node
(
cg
::
OperatorNodeBase
*
node_
)
{
auto
*
node
=
&
node_
->
cast_final_safe
<
opr
::
Reduce
>
();
return
Reduce
::
make
(
node
->
param
());
}
OP_TRAIT_REG
(
Reduce
,
Reduce
,
opr
::
Reduce
)
.
make_from_op_node
(
make_from_op_node
)
.
apply_on_var_node
(
apply_on_var_node
)
.
fallback
();
}
// namespace reduce
}
// namespace
}
// namespace imperative
}
// namespace mgb
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
imperative/src/impl/ops/specializations.cpp
浏览文件 @
cd60d268
...
...
@@ -116,31 +116,6 @@ OP_TRAIT_REG(TopK, TopK).apply_on_var_node(apply_on_var_node).fallback();
}
// namespace top_k
}
// namespace
namespace
{
namespace
reduce
{
auto
apply_on_var_node
(
const
OpDef
&
def
,
const
VarNodeArray
&
inputs
)
{
auto
&&
reduce
=
static_cast
<
const
Reduce
&>
(
def
);
OperatorNodeConfig
config
{
reduce
.
make_name
()};
if
(
inputs
.
size
()
>
1
)
{
return
opr
::
Reduce
::
make
(
inputs
[
0
],
reduce
.
param
(),
inputs
[
1
],
config
);
}
else
{
return
opr
::
Reduce
::
make
(
inputs
[
0
],
reduce
.
param
(),
(
cg
::
VarNode
*
)
nullptr
,
config
);
}
}
std
::
shared_ptr
<
OpDef
>
make_from_op_node
(
cg
::
OperatorNodeBase
*
node_
)
{
auto
*
node
=
&
node_
->
cast_final_safe
<
opr
::
Reduce
>
();
return
Reduce
::
make
(
node
->
param
());
}
OP_TRAIT_REG
(
Reduce
,
Reduce
,
opr
::
Reduce
)
.
make_from_op_node
(
make_from_op_node
)
.
apply_on_var_node
(
apply_on_var_node
)
.
fallback
();
}
// namespace reduce
}
// namespace
namespace
{
namespace
adaptive_pooling
{
auto
apply_on_var_node
(
const
OpDef
&
def
,
const
VarNodeArray
&
inputs
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录