Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
47dcdf3e
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看板
提交
47dcdf3e
编写于
6月 09, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mgb/core): fix dtype and resize modifiers for tensor
GitOrigin-RevId: a9d95a4cd80bdd3b2fea5f89fcf9712347930bcc
上级
29f7cdb8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
89 addition
and
8 deletion
+89
-8
dnn/src/naive/convolution/convolution.cpp
dnn/src/naive/convolution/convolution.cpp
+2
-2
src/core/impl/tensor.cpp
src/core/impl/tensor.cpp
+2
-2
src/gopt/impl/tensor_reformat.cpp
src/gopt/impl/tensor_reformat.cpp
+6
-4
src/gopt/test/inference.cpp
src/gopt/test/inference.cpp
+79
-0
未找到文件。
dnn/src/naive/convolution/convolution.cpp
浏览文件 @
47dcdf3e
...
...
@@ -270,8 +270,8 @@ ConvolutionForwardImpl:: get_all_algorithms(const TensorLayout &,
}
ConvolutionForward
::
Algorithm
*
ConvolutionForwardImpl
::
get_algorithm_heuristic
(
const
TensorLayout
&
/* src */
,
const
TensorLayout
&
/*
diff
*/
,
const
TensorLayout
&
/*
grad
*/
,
size_t
/* workspace_limit_in_bytes */
,
const
TensorLayout
&
/* src */
,
const
TensorLayout
&
/*
filter
*/
,
const
TensorLayout
&
/*
dst
*/
,
size_t
/* workspace_limit_in_bytes */
,
const
AlgoAttribute
&
positive_attr
,
const
AlgoAttribute
&
negative_attr
)
{
auto
algo
=
...
...
src/core/impl/tensor.cpp
浏览文件 @
47dcdf3e
...
...
@@ -443,7 +443,7 @@ TensorND<TensorStorage>::name
DEF
(
resize
,
&
)(
const
TensorShape
&
shape
)
{
mgb_assert
(
m_layout
.
dtype
.
valid
());
m_layout
=
TensorLayout
(
shape
,
m_layout
.
dty
pe
);
m_layout
.
init_contiguous_stride
(
sha
pe
);
m_storage
.
ensure_size
(
m_layout
.
span
().
dist_byte
());
return
static_cast
<
ChainReturnType
&>
(
*
this
);
}
...
...
@@ -479,7 +479,7 @@ DEF(storage, &)(const TensorStorage &storage) {
DEF
(
dtype
,
&
)(
DType
dtype
)
{
if
(
m_layout
.
dtype
!=
dtype
)
{
m_layout
.
dtype
=
dtype
;
m_layout
.
modify_dtype_inplace
(
dtype
)
;
m_layout
.
ndim
=
0
;
}
return
static_cast
<
ChainReturnType
&>
(
*
this
);
...
...
src/gopt/impl/tensor_reformat.cpp
浏览文件 @
47dcdf3e
...
...
@@ -3833,8 +3833,9 @@ void PaddingChannelPass::apply(OptState& opt) const {
inp
->
dtype
().
enumv
()
==
DTypeEnum
::
QuantizedS32
);
TensorShape
shape
{
inp
->
shape
()[
0
],
pad_channels
,
inp
->
shape
()[
2
],
inp
->
shape
()[
3
]};
std
::
shared_ptr
<
HostTensorND
>
host_val
=
std
::
make_shared
<
HostTensorND
>
(
inp
->
comp_node
(),
shape
,
inp
->
dtype
());
std
::
shared_ptr
<
HostTensorND
>
host_val
=
std
::
make_shared
<
HostTensorND
>
(
inp
->
comp_node
(),
inp
->
dtype
());
host_val
->
resize
(
shape
);
auto
ptr
=
host_val
->
raw_ptr
();
size_t
size_bytes
=
TensorLayout
{
shape
,
inp
->
dtype
()}.
span
().
dist_byte
();
...
...
@@ -3853,8 +3854,9 @@ void PaddingChannelPass::apply(OptState& opt) const {
inp
->
dtype
().
enumv
()
==
DTypeEnum
::
QuantizedS32
);
TensorShape
shape
{
pad_channels
,
inp
->
shape
()[
1
],
inp
->
shape
()[
2
],
inp
->
shape
()[
3
]};
std
::
shared_ptr
<
HostTensorND
>
host_val
=
std
::
make_shared
<
HostTensorND
>
(
inp
->
comp_node
(),
shape
,
inp
->
dtype
());
std
::
shared_ptr
<
HostTensorND
>
host_val
=
std
::
make_shared
<
HostTensorND
>
(
inp
->
comp_node
(),
inp
->
dtype
());
host_val
->
resize
(
shape
);
auto
ptr
=
host_val
->
raw_ptr
();
size_t
size_bytes
=
TensorLayout
{
shape
,
inp
->
dtype
()}.
span
().
dist_byte
();
...
...
src/gopt/test/inference.cpp
浏览文件 @
47dcdf3e
...
...
@@ -1208,6 +1208,85 @@ TEST(TestGoptInference, ConvertFormatNHWCD4) {
MGB_ASSERT_TENSOR_NEAR
(
host_y
,
host_y_opt
,
1e-3
);
}
#if MGB_OPENCL
#include "megcore_opencl.h"
#define REQUIRE_OPENCL() \
do { \
if (!CompNode::get_device_count(CompNode::DeviceType::OPENCL)) { \
return; \
} \
} while (0)
TEST
(
TestGoptInference
,
ConvertFormatNHWCD4OpenCL
)
{
REQUIRE_OPENCL
();
HostTensorGenerator
<>
gen
;
auto
cn
=
CompNode
::
load
(
"openclx"
);
auto
graph
=
ComputingGraph
::
make
();
graph
->
options
().
graph_opt_level
=
0
;
auto
mkvar
=
[
&
](
const
char
*
name
,
const
TensorShape
&
shp
)
{
return
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
gen
(
shp
,
cn
)).
rename
(
name
);
};
auto
mkcvar
=
[
&
](
const
char
*
name
,
const
TensorShape
&
shp
)
{
return
opr
::
SharedDeviceTensor
::
make
(
*
graph
,
*
gen
(
shp
,
cn
))
.
rename
(
name
);
};
auto
host_x
=
gen
({
8
,
8
,
8
,
8
},
cn
);
auto
x
=
opr
::
Host2DeviceCopy
::
make
(
*
graph
,
host_x
);
opr
::
Convolution
::
Param
param
;
param
.
pad_h
=
param
.
pad_w
=
0
;
auto
w1
=
mkcvar
(
"w1"
,
{
4
,
8
,
3
,
3
}),
conv
=
opr
::
Convolution
::
make
(
x
,
w1
,
param
);
auto
shape_of
=
opr
::
GetVarShape
::
make
(
conv
);
auto
subtensor
=
opr
::
Subtensor
::
make
(
shape_of
,
{
opr
::
Subtensor
::
AxisIndexer
::
make_interval
(
0
,
x
.
make_scalar
(
2
),
None
,
x
.
make_scalar
(
1
))});
opr
::
Resize
::
Param
param_resize
;
param_resize
.
format
=
opr
::
Resize
::
Param
::
Format
::
NCHW
;
auto
resize
=
opr
::
ResizeForward
::
make
(
conv
,
subtensor
*
2
,
param_resize
);
auto
mat
=
mkcvar
(
"mat"
,
{
8
,
3
,
3
}),
warp
=
opr
::
WarpPerspectiveForward
::
make
(
resize
,
mat
,
nullptr
,
cg
::
var_from_tensor_shape
(
x
,
{
4
,
4
}));
auto
b
=
mkvar
(
"b"
,
{
1
,
4
,
1
,
1
}),
elem
=
opr
::
Elemwise
::
make
({
warp
+
b
},
opr
::
Elemwise
::
Param
::
Mode
::
RELU
);
param
.
pad_h
=
param
.
pad_w
=
1
;
auto
w2
=
mkcvar
(
"w2"
,
{
4
,
4
,
3
,
3
}),
y
=
opr
::
Convolution
::
make
(
elem
,
w2
,
param
),
z
=
opr
::
AxisAddRemove
::
make
(
y
,
{
opr
::
AxisAddRemove
::
AxisDesc
::
make_add
(
0
)});
SymbolVar
y_opt
,
z_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_nhwcd4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
unpack_vector
(
gopt
::
optimize_for_inference
({
z
},
options
),
z_opt
);
ASSERT_EQ
(
opr
::
Convolution
::
Param
::
Format
::
NHWCD4
,
find_opr
<
opr
::
Convolution
>
(
y_opt
).
param
().
format
);
ASSERT_EQ
(
TensorFormat
::
Type
::
DEFAULT
,
find_opr
<
opr
::
AxisAddRemove
>
(
z_opt
).
input
(
0
)
->
format
().
type
());
ASSERT_EQ
(
4
,
find_opr
<
opr
::
AxisAddRemove
>
(
z_opt
).
input
(
0
)
->
shape
().
ndim
);
HostTensorND
host_y_opt
,
host_y
;
auto
func
=
graph
->
compile
({
make_callback_copy
(
y
,
host_y
),
make_callback_copy
(
y_opt
,
host_y_opt
)});
func
->
execute
();
MGB_ASSERT_TENSOR_NEAR
(
host_y
,
host_y_opt
,
1e-3
);
*
host_x
=
*
gen
({
8
,
8
,
16
,
16
},
cn
);
func
->
execute
();
MGB_ASSERT_TENSOR_NEAR
(
host_y
,
host_y_opt
,
1e-3
);
}
#undef REQUIRE_OPENCL
#endif
TEST
(
TestGoptInference
,
ConvertFormatNHWCD4Elemwise
)
{
// hwcd4 is only supported in naive handle
NaiveMegDNNHandleScope
naive_megdnn_handle
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录