Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
1e576e32
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看板
提交
1e576e32
编写于
6月 22, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(dnn/aarch64-arm_common): add mat_idx warppespective for aarch64/arm_common/naive
GitOrigin-RevId: 9eb0cdda5c3c4f4a766c67f51b9888960c26876e
上级
714cb232
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
243 addition
and
100 deletion
+243
-100
dnn/src/aarch64/warp_perspective/opr_impl.cpp
dnn/src/aarch64/warp_perspective/opr_impl.cpp
+2
-2
dnn/src/aarch64/warp_perspective/warp_perspective_cv.cpp
dnn/src/aarch64/warp_perspective/warp_perspective_cv.cpp
+32
-12
dnn/src/aarch64/warp_perspective/warp_perspective_cv.h
dnn/src/aarch64/warp_perspective/warp_perspective_cv.h
+2
-1
dnn/src/arm_common/warp_perspective/opr_impl.cpp
dnn/src/arm_common/warp_perspective/opr_impl.cpp
+2
-3
dnn/src/arm_common/warp_perspective/warp_perspective_cv.cpp
dnn/src/arm_common/warp_perspective/warp_perspective_cv.cpp
+30
-9
dnn/src/arm_common/warp_perspective/warp_perspective_cv.h
dnn/src/arm_common/warp_perspective/warp_perspective_cv.h
+2
-1
dnn/src/common/warp_perspective.cpp
dnn/src/common/warp_perspective.cpp
+0
-4
dnn/src/naive/warp_perspective/opr_impl.cpp
dnn/src/naive/warp_perspective/opr_impl.cpp
+2
-3
dnn/src/naive/warp_perspective/warp_perspective_cv.cpp
dnn/src/naive/warp_perspective/warp_perspective_cv.cpp
+32
-10
dnn/src/naive/warp_perspective/warp_perspective_cv.h
dnn/src/naive/warp_perspective/warp_perspective_cv.h
+2
-1
dnn/src/x86/warp_perspective/opr_impl.cpp
dnn/src/x86/warp_perspective/opr_impl.cpp
+2
-2
dnn/src/x86/warp_perspective/warp_perspective_cv.cpp
dnn/src/x86/warp_perspective/warp_perspective_cv.cpp
+31
-13
dnn/src/x86/warp_perspective/warp_perspective_cv.h
dnn/src/x86/warp_perspective/warp_perspective_cv.h
+4
-3
dnn/test/aarch64/warp_perspective.cpp
dnn/test/aarch64/warp_perspective.cpp
+29
-9
dnn/test/arm_common/warp_perspective.cpp
dnn/test/arm_common/warp_perspective.cpp
+58
-18
dnn/test/common/warp_perspective.cpp
dnn/test/common/warp_perspective.cpp
+10
-7
dnn/test/common/warp_perspective.h
dnn/test/common/warp_perspective.h
+3
-2
未找到文件。
dnn/src/aarch64/warp_perspective/opr_impl.cpp
浏览文件 @
1e576e32
...
...
@@ -28,8 +28,8 @@ void WarpPerspectiveImpl::exec(_megdnn_tensor_in src,
check_exec
(
src
.
layout
,
mat
.
layout
,
mat_idx
.
layout
,
dst
.
layout
,
workspace
.
size
);
if
(
warp
::
is_cv_available
(
src
.
layout
,
mat
.
layout
,
dst
.
layout
,
param
().
imode
,
param
().
format
)
&&
!
mat_idx
.
layout
.
ndim
)
{
warp_perspective_cv_exec
(
src
,
mat
,
dst
,
param
().
border_val
,
param
().
format
))
{
warp_perspective_cv_exec
(
src
,
mat
,
mat_idx
,
dst
,
param
().
border_val
,
param
().
bmode
,
param
().
imode
,
handle
());
}
else
{
//! Use arm_common implementation
...
...
dnn/src/aarch64/warp_perspective/warp_perspective_cv.cpp
浏览文件 @
1e576e32
...
...
@@ -190,9 +190,9 @@ void warp_perspective_cv(const Mat<T>& src, Mat<T>& dst, const float* trans,
}
}
// anonymous namespace
void
megdnn
::
aarch64
::
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
BorderMode
bmode
,
InterpolationMode
imod
e
,
Handle
*
handle
)
{
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_valu
e
,
BorderMode
bmode
,
InterpolationMode
imode
,
Handle
*
handle
)
{
size_t
ch
=
dst
.
layout
[
3
];
size_t
width
=
dst
.
layout
[
2
];
size_t
height
=
dst
.
layout
[
1
];
...
...
@@ -208,13 +208,26 @@ void megdnn::aarch64::warp_perspective_cv_exec(
"unsupported src channel: %zu, avaiable channel size: 1/2/3"
,
ch
);
const
float
*
trans_ptr
=
trans
.
ptr
<
dt_float32
>
();
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Float32
)
{
const
int
*
midx_ptr
=
nullptr
;
if
(
mat_idx
.
raw_ptr
)
{
megdnn_assert
(
mat_idx
.
layout
.
ndim
==
1
);
midx_ptr
=
mat_idx
.
ptr
<
int
>
();
}
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Float32
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<float> src_mat = TensorND2Mat<float>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<float> src_mat = TensorND2Mat<float>(src, src_id); \
Mat<float> dst_mat = TensorND2Mat<float>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<float MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
@@ -230,11 +243,19 @@ void megdnn::aarch64::warp_perspective_cv_exec(
#undef cb
}
else
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Uint8
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, src_id); \
Mat<uchar> dst_mat = TensorND2Mat<uchar>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<uchar MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
@@ -250,8 +271,7 @@ void megdnn::aarch64::warp_perspective_cv_exec(
#undef cb
}
else
{
megdnn_throw
(
megdnn_mangle
(
"Unsupported datatype of Warp
Affin
e optr."
));
megdnn_mangle
(
"Unsupported datatype of Warp
Perspectiv
e optr."
));
}
}
// vim: syntax=cpp.doxygen
dnn/src/aarch64/warp_perspective/warp_perspective_cv.h
浏览文件 @
1e576e32
...
...
@@ -21,7 +21,8 @@ namespace aarch64 {
* \brief Used if the format is NHWC, transfer from megcv
*/
void
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_value
,
param
::
WarpPerspective
::
BorderMode
border_mode
,
param
::
WarpPerspective
::
InterpolationMode
imode
,
Handle
*
handle
);
...
...
dnn/src/arm_common/warp_perspective/opr_impl.cpp
浏览文件 @
1e576e32
...
...
@@ -28,10 +28,9 @@ void WarpPerspectiveImpl::exec(_megdnn_tensor_in src, _megdnn_tensor_in mat,
check_exec_allow_nhwc_mat_idx
(
src
.
layout
,
mat
.
layout
,
mat_idx
.
layout
,
dst
.
layout
,
workspace
.
size
);
if
(
warp
::
is_cv_available
(
src
.
layout
,
mat
.
layout
,
dst
.
layout
,
param
().
imode
,
param
().
format
)
&&
!
mat_idx
.
layout
.
ndim
)
{
param
().
format
))
{
MIDOUT_BEGIN
(
megdnn_arm_warpperspective
,
void
)
{
warp_perspective_cv_exec
(
src
,
mat
,
dst
,
param
().
border_val
,
warp_perspective_cv_exec
(
src
,
mat
,
mat_idx
,
dst
,
param
().
border_val
,
param
().
bmode
,
param
().
imode
,
handle
());
}
MIDOUT_END
();
...
...
dnn/src/arm_common/warp_perspective/warp_perspective_cv.cpp
浏览文件 @
1e576e32
...
...
@@ -149,9 +149,9 @@ void warp_perspective_cv(const Mat<T>& src, Mat<T>& dst, const float* trans,
}
// anonymous namespace
void
megdnn
::
arm_common
::
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
BorderMode
bmode
,
InterpolationMode
imod
e
,
Handle
*
handle
)
{
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_valu
e
,
BorderMode
bmode
,
InterpolationMode
imode
,
Handle
*
handle
)
{
size_t
ch
=
dst
.
layout
[
3
];
size_t
width
=
dst
.
layout
[
2
];
size_t
height
=
dst
.
layout
[
1
];
...
...
@@ -167,13 +167,26 @@ void megdnn::arm_common::warp_perspective_cv_exec(
"unsupported src channel: %zu, avaiable channel size: 1/2/3"
,
ch
);
const
float
*
trans_ptr
=
trans
.
ptr
<
dt_float32
>
();
const
int
*
midx_ptr
=
nullptr
;
if
(
mat_idx
.
raw_ptr
)
{
megdnn_assert
(
mat_idx
.
layout
.
ndim
==
1
);
midx_ptr
=
mat_idx
.
ptr
<
int
>
();
}
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Float32
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<float> src_mat = TensorND2Mat<float>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<float> src_mat = TensorND2Mat<float>(src, src_id); \
Mat<float> dst_mat = TensorND2Mat<float>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<float MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
@@ -189,11 +202,19 @@ void megdnn::arm_common::warp_perspective_cv_exec(
#undef cb
}
else
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Uint8
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, src_id); \
Mat<uchar> dst_mat = TensorND2Mat<uchar>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<uchar MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
dnn/src/arm_common/warp_perspective/warp_perspective_cv.h
浏览文件 @
1e576e32
...
...
@@ -21,7 +21,8 @@ namespace arm_common {
* \brief Used if the format is NHWC, transfer from megcv
*/
void
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_value
,
param
::
WarpPerspective
::
BorderMode
border_mode
,
param
::
WarpPerspective
::
InterpolationMode
imode
,
Handle
*
handle
);
...
...
dnn/src/common/warp_perspective.cpp
浏览文件 @
1e576e32
...
...
@@ -236,10 +236,6 @@ void WarpPerspectiveForward::check_exec(const TensorLayout &src,
size_t
workspace_in_bytes
)
{
check_exec_allow_nhwc_mat_idx
(
src
,
mat
,
mat_idx
,
dst
,
workspace_in_bytes
);
if
(
param
().
format
==
Param
::
Format
::
NHWC
)
{
megdnn_assert
(
!
mat_idx
.
ndim
,
"mat_idx not supported for current format"
);
}
}
void
WarpPerspectiveForward
::
check_exec_allow_nhwc_mat_idx
(
...
...
dnn/src/naive/warp_perspective/opr_impl.cpp
浏览文件 @
1e576e32
...
...
@@ -320,10 +320,9 @@ void WarpPerspectiveForwardImpl::exec(_megdnn_tensor_in src,
.
c_str
());
}
if
(
warp
::
is_cv_available
(
src
.
layout
,
mat
.
layout
,
dst
.
layout
,
param
().
imode
,
param
().
format
)
&&
!
mat_idx
.
layout
.
ndim
)
{
param
().
format
))
{
MIDOUT_BEGIN
(
megdnn_naive_warpperspective
,
void
)
{
warp_perspective_cv_exec
(
src
,
mat
,
dst
,
param
().
border_val
,
warp_perspective_cv_exec
(
src
,
mat
,
mat_idx
,
dst
,
param
().
border_val
,
param
().
bmode
,
param
().
imode
,
handle
());
}
MIDOUT_END
();
...
...
dnn/src/naive/warp_perspective/warp_perspective_cv.cpp
浏览文件 @
1e576e32
...
...
@@ -151,9 +151,9 @@ void warp_perspective_cv(const Mat<T>& src, Mat<T>& dst, const float* trans,
}
// anonymous namespace
void
megdnn
::
naive
::
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
BorderMode
bmode
,
InterpolationMode
imod
e
,
Handle
*
handle
)
{
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_valu
e
,
BorderMode
bmode
,
InterpolationMode
imode
,
Handle
*
handle
)
{
size_t
ch
=
dst
.
layout
[
3
];
size_t
width
=
dst
.
layout
[
2
];
size_t
height
=
dst
.
layout
[
1
];
...
...
@@ -169,13 +169,26 @@ void megdnn::naive::warp_perspective_cv_exec(
"unsupported src channel: %zu, avaiable channel size: 1/2/3"
,
ch
);
const
float
*
trans_ptr
=
trans
.
ptr
<
dt_float32
>
();
const
int
*
midx_ptr
=
nullptr
;
if
(
mat_idx
.
raw_ptr
)
{
megdnn_assert
(
mat_idx
.
layout
.
ndim
==
1
);
midx_ptr
=
mat_idx
.
ptr
<
int
>
();
}
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Float32
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<float> src_mat = TensorND2Mat<float>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<float> src_mat = TensorND2Mat<float>(src, src_id); \
Mat<float> dst_mat = TensorND2Mat<float>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<float MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
@@ -191,11 +204,19 @@ void megdnn::naive::warp_perspective_cv_exec(
#undef cb
}
else
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Uint8
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, src_id); \
Mat<uchar> dst_mat = TensorND2Mat<uchar>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<uchar MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
@@ -210,7 +231,8 @@ void megdnn::naive::warp_perspective_cv_exec(
DISPATCH_IMODE
(
imode
,
bmode
,
ch
,
cb
)
#undef cb
}
else
{
megdnn_throw
(
megdnn_mangle
(
"Unsupported datatype of WarpAffine optr."
));
megdnn_throw
(
megdnn_mangle
(
"Unsupported datatype of WarpPerspective optr."
));
}
}
...
...
dnn/src/naive/warp_perspective/warp_perspective_cv.h
浏览文件 @
1e576e32
...
...
@@ -21,7 +21,8 @@ namespace naive {
* \brief Used if the format is NHWC, transfer from megcv
*/
void
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_value
,
param
::
WarpPerspective
::
BorderMode
border_mode
,
param
::
WarpPerspective
::
InterpolationMode
imode
,
Handle
*
handle
);
...
...
dnn/src/x86/warp_perspective/opr_impl.cpp
浏览文件 @
1e576e32
...
...
@@ -27,8 +27,8 @@ void WarpPerspectiveImpl::exec(_megdnn_tensor_in src, _megdnn_tensor_in mat,
dst
.
layout
,
workspace
.
size
);
if
(
warp
::
is_cv_available
(
src
.
layout
,
mat
.
layout
,
dst
.
layout
,
param
().
imode
,
param
().
format
)
&&
!
mat_idx
.
layout
.
ndim
&&
is_supported
(
SIMDType
::
SSE4_2
))
{
warp_perspective_cv_exec
(
src
,
mat
,
dst
,
param
().
border_val
,
is_supported
(
SIMDType
::
SSE4_2
))
{
warp_perspective_cv_exec
(
src
,
mat
,
mat_idx
,
dst
,
param
().
border_val
,
param
().
bmode
,
param
().
imode
,
handle
());
}
else
{
//! Use fallback implementation
...
...
dnn/src/x86/warp_perspective/warp_perspective_cv.cpp
浏览文件 @
1e576e32
...
...
@@ -59,7 +59,6 @@
* ---------------------------------------------------------------------------
*/
#include "src/x86/warp_perspective/warp_perspective_cv.h"
#include "src/common/cv/common.h"
#include "src/common/cv/helper.h"
...
...
@@ -154,12 +153,10 @@ void warp_perspective_cv(const Mat<T>& src, Mat<T>& dst, const float* trans,
}
}
// anonymous namespace
void
megdnn
::
x86
::
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
BorderMode
bmode
,
InterpolationMode
imode
,
Handle
*
handle
)
{
void
megdnn
::
x86
::
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_value
,
BorderMode
bmode
,
InterpolationMode
imode
,
Handle
*
handle
)
{
size_t
ch
=
dst
.
layout
[
3
];
size_t
width
=
dst
.
layout
[
2
];
size_t
height
=
dst
.
layout
[
1
];
...
...
@@ -175,13 +172,26 @@ void megdnn::x86::warp_perspective_cv_exec(_megdnn_tensor_in src,
"unsupported src channel: %zu, avaiable channel size: 1/2/3"
,
ch
);
const
float
*
trans_ptr
=
trans
.
ptr
<
dt_float32
>
();
const
int
*
midx_ptr
=
nullptr
;
if
(
mat_idx
.
raw_ptr
)
{
megdnn_assert
(
mat_idx
.
layout
.
ndim
==
1
);
midx_ptr
=
mat_idx
.
ptr
<
int
>
();
}
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Float32
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<float> src_mat = TensorND2Mat<float>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<float> src_mat = TensorND2Mat<float>(src, src_id); \
Mat<float> dst_mat = TensorND2Mat<float>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<float MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
@@ -197,11 +207,19 @@ void megdnn::x86::warp_perspective_cv_exec(_megdnn_tensor_in src,
#undef cb
}
else
if
(
dst
.
layout
.
dtype
.
enumv
()
==
DTypeEnum
::
Uint8
)
{
#define cb(_imode, _bmode, _ch) \
auto task = [src, trans_ptr,
dst, border_value, parallelism_batch](
\
size_t index, size_t) {
\
auto task = [src, trans_ptr,
midx_ptr, dst, border_value,
\
parallelism_batch](size_t index, size_t) {
\
size_t batch_id = index / parallelism_batch; \
size_t task_id = index % parallelism_batch; \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, batch_id); \
size_t src_id = batch_id; \
if (midx_ptr) { \
src_id = midx_ptr[batch_id]; \
megdnn_assert( \
src_id < src.layout.shape[0], \
"mat_idx out of bound: mat_idx[%zu]=%zu src_batch=%zu", \
batch_id, src_id, src.layout.shape[0]); \
} \
Mat<uchar> src_mat = TensorND2Mat<uchar>(src, src_id); \
Mat<uchar> dst_mat = TensorND2Mat<uchar>(dst, batch_id); \
const float* task_trans_ptr = trans_ptr + batch_id * 3 * 3; \
warp_perspective_cv<uchar MEGDNN_COMMA _imode MEGDNN_COMMA _bmode \
...
...
dnn/src/x86/warp_perspective/warp_perspective_cv.h
浏览文件 @
1e576e32
...
...
@@ -21,12 +21,13 @@ namespace x86 {
* \brief Used if the format is NHWC, transfer from megcv
*/
void
warp_perspective_cv_exec
(
_megdnn_tensor_in
src
,
_megdnn_tensor_in
trans
,
_megdnn_tensor_in
dst
,
float
border_value
,
_megdnn_tensor_in
mat_idx
,
_megdnn_tensor_in
dst
,
float
border_value
,
param
::
WarpPerspective
::
BorderMode
border_mode
,
param
::
WarpPerspective
::
InterpolationMode
imode
,
Handle
*
handle
);
}
// x86
}
// megdnn
}
// x86
}
// megdnn
// vim: syntax=cpp.doxygen
dnn/test/aarch64/warp_perspective.cpp
浏览文件 @
1e576e32
...
...
@@ -25,7 +25,7 @@ namespace test {
TEST_F
(
AARCH64
,
WARP_PERSPECTIVE_CV
)
{
//! Just for the format NHWC
Checker
<
WarpPerspective
>
checker
(
handle
());
Checker
<
WarpPerspective
,
WarpPerspectiveMatIdxProxy
>
checker
(
handle
());
param
::
WarpPerspective
param
;
class
ResizeMatRNG
:
public
RNG
{
void
gen
(
const
TensorND
&
tensor_
)
override
{
...
...
@@ -82,7 +82,10 @@ TEST_F(AARCH64, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
mode
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
,
56
,
128
,
3
}});
UniformIntRNG
rng
(
0
,
1
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
({{
2
,
5
,
5
,
1
},
{
4
,
3
,
3
},
{
4
},
{
4
,
5
,
5
,
1
}});
}
// resize nan case
UniformFloatRNG
rng_zero
(
0
,
0
);
...
...
@@ -91,7 +94,11 @@ TEST_F(AARCH64, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
BMode
::
CONSTANT
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
,
2
,
12
,
3
}});
UniformIntRNG
rng
(
0
,
999
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
(
{{
1000
,
2
,
10
,
3
},
{
2000
,
3
,
3
},
{
2000
},
{
2000
,
2
,
12
,
3
}});
}
// add linear test
...
...
@@ -101,7 +108,10 @@ TEST_F(AARCH64, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
mode
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
,
56
,
128
,
3
}});
UniformIntRNG
rng
(
0
,
9
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
20
,
3
,
3
},
{
20
},
{
20
,
56
,
128
,
3
}});
}
// resize nan case
checker
.
set_rng
(
1
,
&
rng_zero
);
...
...
@@ -109,24 +119,34 @@ TEST_F(AARCH64, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
BMode
::
CONSTANT
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
,
2
,
12
,
3
}});
UniformIntRNG
rng
(
0
,
999
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
(
{{
1000
,
2
,
10
,
3
},
{
2000
,
3
,
3
},
{
2000
},
{
2000
,
2
,
12
,
3
}});
}
auto
args
=
warp_perspective
::
get_cv_args
();
for
(
auto
&&
arg
:
args
)
{
ConstValue
rng
(
0.
f
);
checker
.
set_param
(
arg
.
param
)
.
set_rng
(
2
,
&
rng
)
.
set_dtype
(
0
,
dtype
::
Uint8
())
.
set_dtype
(
1
,
dtype
::
Float32
())
.
set_dtype
(
2
,
dtype
::
Uint8
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
dst
});
.
set_dtype
(
2
,
dtype
::
Int32
())
.
set_dtype
(
3
,
dtype
::
Uint8
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
mat_idx
,
arg
.
dst
});
}
for
(
auto
&&
arg
:
args
)
{
ConstValue
rng
(
0.
f
);
checker
.
set_param
(
arg
.
param
)
.
set_rng
(
2
,
&
rng
)
.
set_dtype
(
0
,
dtype
::
Float32
())
.
set_dtype
(
1
,
dtype
::
Float32
())
.
set_dtype
(
2
,
dtype
::
Float32
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
dst
});
.
set_dtype
(
2
,
dtype
::
Int32
())
.
set_dtype
(
3
,
dtype
::
Float32
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
mat_idx
,
arg
.
dst
});
}
}
...
...
dnn/test/arm_common/warp_perspective.cpp
浏览文件 @
1e576e32
...
...
@@ -25,7 +25,7 @@ namespace test {
TEST_F
(
ARM_COMMON
,
WARP_PERSPECTIVE_CV
)
{
//! Just for the format NHWC
Checker
<
WarpPerspective
>
checker
(
handle
());
Checker
<
WarpPerspective
,
WarpPerspectiveMatIdxProxy
>
checker
(
handle
());
param
::
WarpPerspective
param
;
class
ResizeMatRNG
:
public
RNG
{
void
gen
(
const
TensorND
&
tensor_
)
override
{
...
...
@@ -82,7 +82,10 @@ TEST_F(ARM_COMMON, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
mode
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
,
56
,
128
,
3
}});
UniformIntRNG
rng
(
0
,
9
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
20
,
3
,
3
},
{
20
},
{
20
,
56
,
128
,
3
}});
}
// resize nan case
UniformFloatRNG
rng_zero
(
0
,
0
);
...
...
@@ -91,7 +94,11 @@ TEST_F(ARM_COMMON, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
BMode
::
CONSTANT
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
,
2
,
12
,
3
}});
UniformIntRNG
rng
(
0
,
999
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
(
{{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
},
{
1000
,
2
,
12
,
3
}});
}
// add linear test
...
...
@@ -101,7 +108,10 @@ TEST_F(ARM_COMMON, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
mode
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
,
56
,
128
,
3
}});
UniformIntRNG
rng
(
0
,
9
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
20
,
3
,
3
},
{
20
},
{
20
,
56
,
128
,
3
}});
}
// resize nan case
checker
.
set_rng
(
1
,
&
rng_zero
);
...
...
@@ -109,30 +119,40 @@ TEST_F(ARM_COMMON, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
BMode
::
CONSTANT
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
,
2
,
12
,
3
}});
UniformIntRNG
rng
(
0
,
999
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
(
{{
1000
,
2
,
10
,
3
},
{
2000
,
3
,
3
},
{
2000
},
{
2000
,
2
,
12
,
3
}});
}
auto
args
=
warp_perspective
::
get_cv_args
();
for
(
auto
&&
arg
:
args
)
{
ConstValue
rng
(
0.
f
);
checker
.
set_param
(
arg
.
param
)
.
set_rng
(
2
,
&
rng
)
.
set_dtype
(
0
,
dtype
::
Uint8
())
.
set_dtype
(
1
,
dtype
::
Float32
())
.
set_dtype
(
2
,
dtype
::
Uint8
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
dst
});
.
set_dtype
(
2
,
dtype
::
Int32
())
.
set_dtype
(
3
,
dtype
::
Uint8
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
mat_idx
,
arg
.
dst
});
}
for
(
auto
&&
arg
:
args
)
{
ConstValue
rng
(
0.
f
);
checker
.
set_param
(
arg
.
param
)
.
set_rng
(
2
,
&
rng
)
.
set_dtype
(
0
,
dtype
::
Float32
())
.
set_dtype
(
1
,
dtype
::
Float32
())
.
set_dtype
(
2
,
dtype
::
Float32
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
dst
});
.
set_dtype
(
2
,
dtype
::
Int32
())
.
set_dtype
(
3
,
dtype
::
Float32
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
mat_idx
,
arg
.
dst
});
}
}
TEST_F
(
ARM_COMMON_MULTI_THREADS
,
WARP_PERSPECTIVE_CV
)
{
//! Just for the format NHWC
Checker
<
WarpPerspective
>
checker
(
handle
());
Checker
<
WarpPerspective
,
WarpPerspectiveMatIdxProxy
>
checker
(
handle
());
param
::
WarpPerspective
param
;
class
ResizeMatRNG
:
public
RNG
{
void
gen
(
const
TensorND
&
tensor_
)
override
{
...
...
@@ -189,7 +209,10 @@ TEST_F(ARM_COMMON_MULTI_THREADS, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
mode
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
,
56
,
128
,
3
}});
UniformIntRNG
rng
(
0
,
9
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
},
{
10
,
56
,
128
,
3
}});
}
// resize nan case
UniformFloatRNG
rng_zero
(
0
,
0
);
...
...
@@ -198,7 +221,11 @@ TEST_F(ARM_COMMON_MULTI_THREADS, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
BMode
::
CONSTANT
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
,
2
,
12
,
3
}});
UniformIntRNG
rng
(
0
,
999
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
(
{{
1000
,
2
,
10
,
3
},
{
2000
,
3
,
3
},
{
2000
},
{
2000
,
2
,
12
,
3
}});
}
// add linear test
...
...
@@ -208,7 +235,10 @@ TEST_F(ARM_COMMON_MULTI_THREADS, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
mode
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
,
56
,
128
,
3
}});
UniformIntRNG
rng
(
0
,
9
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
({{
10
,
128
,
108
,
3
},
{
10
,
3
,
3
},
{
10
},
{
10
,
56
,
128
,
3
}});
}
// resize nan case
checker
.
set_rng
(
1
,
&
rng_zero
);
...
...
@@ -216,24 +246,34 @@ TEST_F(ARM_COMMON_MULTI_THREADS, WARP_PERSPECTIVE_CV) {
param
.
bmode
=
BMode
::
CONSTANT
;
param
.
border_val
=
1.737
;
checker
.
set_param
(
param
);
checker
.
exec
({{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
,
2
,
12
,
3
}});
UniformIntRNG
rng
(
0
,
999
);
checker
.
set_rng
(
2
,
&
rng
);
checker
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
exec
(
{{
1000
,
2
,
10
,
3
},
{
1000
,
3
,
3
},
{
1000
},
{
1000
,
2
,
12
,
3
}});
}
auto
args
=
warp_perspective
::
get_cv_args
();
for
(
auto
&&
arg
:
args
)
{
ConstValue
rng
(
0.
f
);
checker
.
set_param
(
arg
.
param
)
.
set_rng
(
2
,
&
rng
)
.
set_dtype
(
0
,
dtype
::
Uint8
())
.
set_dtype
(
1
,
dtype
::
Float32
())
.
set_dtype
(
2
,
dtype
::
Uint8
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
dst
});
.
set_dtype
(
2
,
dtype
::
Int32
())
.
set_dtype
(
3
,
dtype
::
Uint8
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
mat_idx
,
arg
.
dst
});
}
for
(
auto
&&
arg
:
args
)
{
ConstValue
rng
(
0.
f
);
checker
.
set_param
(
arg
.
param
)
.
set_rng
(
2
,
&
rng
)
.
set_dtype
(
0
,
dtype
::
Float32
())
.
set_dtype
(
1
,
dtype
::
Float32
())
.
set_dtype
(
2
,
dtype
::
Float32
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
dst
});
.
set_dtype
(
2
,
dtype
::
Int32
())
.
set_dtype
(
3
,
dtype
::
Float32
())
.
execs
({
arg
.
src
,
arg
.
trans
,
arg
.
mat_idx
,
arg
.
dst
});
}
}
...
...
dnn/test/common/warp_perspective.cpp
浏览文件 @
1e576e32
...
...
@@ -56,24 +56,24 @@ std::vector<TestArg> warp_perspective::get_cv_args() {
cur_param
.
imode
=
imode
;
args
.
emplace_back
(
cur_param
,
TensorShape
{
1
,
i
,
i
,
ic
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
},
TensorShape
{
1
,
i
,
i
,
ic
});
args
.
emplace_back
(
cur_param
,
TensorShape
{
1
,
i
,
i
*
2
,
ic
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
},
TensorShape
{
1
,
i
,
i
*
2
,
ic
});
args
.
emplace_back
(
cur_param
,
TensorShape
{
1
,
i
*
3
,
i
,
ic
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
},
TensorShape
{
1
,
i
*
3
,
i
,
ic
});
cur_param
.
border_val
=
0.78
f
;
args
.
emplace_back
(
cur_param
,
TensorShape
{
1
,
i
,
i
,
ic
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
},
TensorShape
{
1
,
8
,
8
,
ic
});
args
.
emplace_back
(
cur_param
,
TensorShape
{
1
,
i
,
i
*
2
,
ic
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
},
TensorShape
{
1
,
8
,
8
,
ic
});
args
.
emplace_back
(
cur_param
,
TensorShape
{
1
,
i
*
3
,
i
,
ic
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
,
3
,
3
},
TensorShape
{
1
},
TensorShape
{
1
,
8
,
8
,
ic
});
}
}
...
...
@@ -101,7 +101,10 @@ void warp_perspective::run_mat_idx_test(Handle* handle) {
// test NHWC
param
.
format
=
WarpPerspective
::
Param
::
Format
::
NHWC
;
checker
.
set_param
(
param
);
checker
.
set_param
(
param
)
.
set_rng
(
2
,
&
mat_idx_rng
)
.
set_epsilon
(
1e-1
)
.
set_dtype
(
2
,
dtype
::
Int32
());
checker
.
execs
({{
N_SRC
,
10
,
11
,
3
},
{
2
,
3
,
3
},
{
2
},
{
2
,
11
,
12
,
3
}});
}
...
...
dnn/test/common/warp_perspective.h
浏览文件 @
1e576e32
...
...
@@ -57,10 +57,11 @@ struct TestArg {
param
::
WarpPerspective
param
;
TensorShape
src
;
TensorShape
trans
;
TensorShape
mat_idx
;
TensorShape
dst
;
TestArg
(
param
::
WarpPerspective
param_
,
TensorShape
src_
,
TensorShape
trans_
,
TestArg
(
param
::
WarpPerspective
param_
,
TensorShape
src_
,
TensorShape
trans_
,
TensorShape
mat_idx_
,
TensorShape
dst_
)
:
param
(
param_
),
src
(
src_
),
trans
(
trans_
),
dst
(
dst_
)
{}
:
param
(
param_
),
src
(
src_
),
trans
(
trans_
),
mat_idx
(
mat_idx_
),
dst
(
dst_
)
{}
};
//! Test args for the WarpPerspective with format NHWC
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录