Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
5030c087
Mace
项目概览
慢慢CG
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
5030c087
编写于
12月 25, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug of space to batch.
上级
20c2d127
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
60 deletion
+37
-60
mace/kernels/opencl/cl/space_to_batch.cl
mace/kernels/opencl/cl/space_to_batch.cl
+15
-51
mace/kernels/opencl/space_to_batch_opencl.cc
mace/kernels/opencl/space_to_batch_opencl.cc
+0
-1
mace/ops/batch_to_space.h
mace/ops/batch_to_space.h
+4
-4
mace/ops/space_to_batch.h
mace/ops/space_to_batch.h
+4
-4
mace/ops/space_to_batch_test.cc
mace/ops/space_to_batch_test.cc
+14
-0
未找到文件。
mace/kernels/opencl/cl/space_to_batch.cl
浏览文件 @
5030c087
...
@@ -11,43 +11,25 @@ __kernel void space_to_batch(__read_only image2d_t space_data,
...
@@ -11,43 +11,25 @@ __kernel void space_to_batch(__read_only image2d_t space_data,
__private
const
int
batch_height,
__private
const
int
batch_height,
__private
const
int
batch_width
)
{
__private
const
int
batch_width
)
{
const
int
chan_idx
=
get_global_id
(
0
)
;
const
int
chan_idx
=
get_global_id
(
0
)
;
const
int
batch_w_idx
=
mul24
(
get_global_id
(
1
)
,
4
)
;
const
int
batch_w_idx
=
get_global_id
(
1
)
;
const
int
batch_hb_idx
=
get_global_id
(
2
)
;
const
int
batch_hb_idx
=
get_global_id
(
2
)
;
const
int
batch_b_idx
=
batch_hb_idx
/
batch_height
;
const
int
batch_b_idx
=
batch_hb_idx
/
batch_height
;
const
int
batch_h_idx
=
batch_hb_idx
%
batch_height
;
const
int
batch_h_idx
=
batch_hb_idx
%
batch_height
;
const
int
block_size
=
mul24
(
block_height,
block_width
)
;
const
int
block_size
=
block_height
*
block_width
;
const
int
space_b_idx
=
batch_b_idx
/
block_size
;
const
int
space_b_idx
=
batch_b_idx
/
block_size
;
const
int
remaining_batch_idx
=
batch_b_idx
%
block_size
;
const
int
remaining_batch_idx
=
batch_b_idx
%
block_size
;
const
int
space_h_idx
=
(
remaining_batch_idx
/
block_width
)
+
const
int
space_h_idx
=
(
remaining_batch_idx
/
block_width
)
+
mul24
(
batch_h_idx,
block_height
)
-
padding_height
;
batch_h_idx
*
block_height
-
padding_height
;
int
space_w_idx
=
(
remaining_batch_idx
%
block_width
)
+
const
int
space_w_idx
=
(
remaining_batch_idx
%
block_width
)
+
mul24
(
batch_w_idx,
block_width
)
-
padding_width
;
batch_w_idx
*
block_width
-
padding_width
;
int2
space_coord
=
(
int2
)(
mul24
(
chan_idx,
space_width
)
+
space_w_idx,
int2
space_coord
=
(
int2
)(
chan_idx
*
space_width
+
space_w_idx,
mul24
(
space_b_idx,
space_height
)
+
space_h_idx
)
;
space_b_idx
*
space_height
+
space_h_idx
)
;
DATA_TYPE4
value
=
READ_IMAGET
(
space_data,
SAMPLER,
space_coord
)
;
DATA_TYPE4
value
=
READ_IMAGET
(
space_data,
SAMPLER,
space_coord
)
;
int2
batch_coord
=
(
int2
)(
mul24
(
chan_idx,
batch_width
)
+
batch_w_idx,
batch_hb_idx
)
;
int2
batch_coord
=
(
int2
)(
chan_idx
*
batch_width
+
batch_w_idx,
batch_hb_idx
)
;
WRITE_IMAGET
(
batch_data,
batch_coord,
value
)
;
space_coord.x
+=
block_width
;
value
=
READ_IMAGET
(
space_data,
SAMPLER,
space_coord
)
;
batch_coord.x
+=
1
;
WRITE_IMAGET
(
batch_data,
batch_coord,
value
)
;
space_coord.x
+=
block_width
;
value
=
READ_IMAGET
(
space_data,
SAMPLER,
space_coord
)
;
batch_coord.x
+=
1
;
WRITE_IMAGET
(
batch_data,
batch_coord,
value
)
;
space_coord.x
+=
block_width
;
value
=
READ_IMAGET
(
space_data,
SAMPLER,
space_coord
)
;
batch_coord.x
+=
1
;
WRITE_IMAGET
(
batch_data,
batch_coord,
value
)
;
WRITE_IMAGET
(
batch_data,
batch_coord,
value
)
;
}
}
...
@@ -62,42 +44,24 @@ __kernel void batch_to_space(__read_only image2d_t batch_data,
...
@@ -62,42 +44,24 @@ __kernel void batch_to_space(__read_only image2d_t batch_data,
__private
const
int
batch_height,
__private
const
int
batch_height,
__private
const
int
batch_width
)
{
__private
const
int
batch_width
)
{
const
int
chan_idx
=
get_global_id
(
0
)
;
const
int
chan_idx
=
get_global_id
(
0
)
;
const
int
batch_w_idx
=
mul24
(
get_global_id
(
1
)
,
4
)
;
const
int
batch_w_idx
=
get_global_id
(
1
)
;
const
int
batch_hb_idx
=
get_global_id
(
2
)
;
const
int
batch_hb_idx
=
get_global_id
(
2
)
;
const
int
batch_b_idx
=
batch_hb_idx
/
batch_height
;
const
int
batch_b_idx
=
batch_hb_idx
/
batch_height
;
const
int
batch_h_idx
=
batch_hb_idx
%
batch_height
;
const
int
batch_h_idx
=
batch_hb_idx
%
batch_height
;
const
int
block_size
=
mul24
(
block_height,
block_width
)
;
const
int
block_size
=
block_height
*
block_width
;
const
int
space_b_idx
=
batch_b_idx
/
block_size
;
const
int
space_b_idx
=
batch_b_idx
/
block_size
;
const
int
remaining_batch_idx
=
batch_b_idx
%
block_size
;
const
int
remaining_batch_idx
=
batch_b_idx
%
block_size
;
const
int
space_h_idx
=
(
remaining_batch_idx
/
block_width
)
+
const
int
space_h_idx
=
(
remaining_batch_idx
/
block_width
)
+
mul24
(
batch_h_idx,
block_height
)
-
padding_height
;
batch_h_idx
*
block_height
-
padding_height
;
const
int
space_w_idx
=
(
remaining_batch_idx
%
block_width
)
+
const
int
space_w_idx
=
(
remaining_batch_idx
%
block_width
)
+
mul24
(
batch_w_idx,
block_width
)
-
padding_width
;
batch_w_idx
*
block_width
-
padding_width
;
int2
batch_coord
=
(
int2
)(
mul24
(
chan_idx,
batch_width
)
+
batch_w_idx,
batch_hb_idx
)
;
int2
batch_coord
=
(
int2
)(
chan_idx
*
batch_width
+
batch_w_idx,
batch_hb_idx
)
;
DATA_TYPE4
value
=
READ_IMAGET
(
batch_data,
SAMPLER,
batch_coord
)
;
DATA_TYPE4
value
=
READ_IMAGET
(
batch_data,
SAMPLER,
batch_coord
)
;
int2
space_coord
=
(
int2
)(
mul24
(
chan_idx,
space_width
)
+
space_w_idx,
int2
space_coord
=
(
int2
)(
chan_idx
*
space_width
+
space_w_idx,
mul24
(
space_b_idx,
space_height
)
+
space_h_idx
)
;
space_b_idx
*
space_height
+
space_h_idx
)
;
WRITE_IMAGET
(
space_data,
space_coord,
value
)
;
batch_coord.x
+=
1
;
value
=
READ_IMAGET
(
batch_data,
SAMPLER,
batch_coord
)
;
space_coord.x
+=
block_width
;
WRITE_IMAGET
(
space_data,
space_coord,
value
)
;
batch_coord.x
+=
1
;
value
=
READ_IMAGET
(
batch_data,
SAMPLER,
batch_coord
)
;
space_coord.x
+=
block_width
;
WRITE_IMAGET
(
space_data,
space_coord,
value
)
;
batch_coord.x
+=
1
;
value
=
READ_IMAGET
(
batch_data,
SAMPLER,
batch_coord
)
;
space_coord.x
+=
block_width
;
WRITE_IMAGET
(
space_data,
space_coord,
value
)
;
WRITE_IMAGET
(
space_data,
space_coord,
value
)
;
}
}
mace/kernels/opencl/space_to_batch_opencl.cc
浏览文件 @
5030c087
...
@@ -54,7 +54,6 @@ void SpaceToBatchFunctor<DeviceType::OPENCL, T>::operator()(Tensor *space_tensor
...
@@ -54,7 +54,6 @@ void SpaceToBatchFunctor<DeviceType::OPENCL, T>::operator()(Tensor *space_tensor
s2b_kernel
.
setArg
(
idx
++
,
static_cast
<
int32_t
>
(
batch_tensor
->
dim
(
2
)));
s2b_kernel
.
setArg
(
idx
++
,
static_cast
<
int32_t
>
(
batch_tensor
->
dim
(
2
)));
const
uint32_t
chan_blk
=
RoundUpDiv4
<
uint32_t
>
(
batch_tensor
->
dim
(
3
));
const
uint32_t
chan_blk
=
RoundUpDiv4
<
uint32_t
>
(
batch_tensor
->
dim
(
3
));
// const uint32_t width_blk = RoundUpDiv4<uint32_t>(batch_tensor->dim(2));
const
uint32_t
gws
[
3
]
=
{
chan_blk
,
const
uint32_t
gws
[
3
]
=
{
chan_blk
,
static_cast
<
uint32_t
>
(
batch_tensor
->
dim
(
2
)),
static_cast
<
uint32_t
>
(
batch_tensor
->
dim
(
2
)),
static_cast
<
uint32_t
>
(
batch_tensor
->
dim
(
0
)
*
batch_tensor
->
dim
(
1
))};
static_cast
<
uint32_t
>
(
batch_tensor
->
dim
(
0
)
*
batch_tensor
->
dim
(
1
))};
...
...
mace/ops/batch_to_space.h
浏览文件 @
5030c087
...
@@ -23,12 +23,12 @@ class BatchToSpaceNDOp : public Operator<D, T> {
...
@@ -23,12 +23,12 @@ class BatchToSpaceNDOp : public Operator<D, T> {
true
)
{}
true
)
{}
bool
Run
(
StatsFuture
*
future
)
override
{
bool
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input
_tensor
=
this
->
Input
(
INPUT
);
const
Tensor
*
batch
_tensor
=
this
->
Input
(
INPUT
);
Tensor
*
output
=
this
->
Output
(
OUTPUT
);
Tensor
*
space_tensor
=
this
->
Output
(
OUTPUT
);
std
::
vector
<
index_t
>
output_shape
(
4
,
0
);
std
::
vector
<
index_t
>
output_shape
(
4
,
0
);
BatchToSpaceHelper
(
input_tensor
,
output
,
output_shape
);
BatchToSpaceHelper
(
batch_tensor
,
space_tensor
,
output_shape
);
functor_
(
output
,
output_shape
,
const_cast
<
Tensor
*>
(
input
_tensor
),
future
);
functor_
(
space_tensor
,
output_shape
,
const_cast
<
Tensor
*>
(
batch
_tensor
),
future
);
return
true
;
return
true
;
}
}
...
...
mace/ops/space_to_batch.h
浏览文件 @
5030c087
...
@@ -24,12 +24,12 @@ class SpaceToBatchNDOp : public Operator<D, T> {
...
@@ -24,12 +24,12 @@ class SpaceToBatchNDOp : public Operator<D, T> {
false
)
{}
false
)
{}
bool
Run
(
StatsFuture
*
future
)
override
{
bool
Run
(
StatsFuture
*
future
)
override
{
const
Tensor
*
input_tensor
=
this
->
Input
(
INPUT
);
const
Tensor
*
space_tensor
=
this
->
Input
(
INPUT
);
Tensor
*
output
=
this
->
Output
(
OUTPUT
);
Tensor
*
batch_tensor
=
this
->
Output
(
OUTPUT
);
std
::
vector
<
index_t
>
output_shape
(
4
,
0
);
std
::
vector
<
index_t
>
output_shape
(
4
,
0
);
SpaceToBatchHelper
(
input_tensor
,
output
,
output_shape
);
SpaceToBatchHelper
(
space_tensor
,
batch_tensor
,
output_shape
);
functor_
(
const_cast
<
Tensor
*>
(
input_tensor
),
output_shape
,
output
,
future
);
functor_
(
const_cast
<
Tensor
*>
(
space_tensor
),
output_shape
,
batch_tensor
,
future
);
return
true
;
return
true
;
}
}
...
...
mace/ops/space_to_batch_test.cc
浏览文件 @
5030c087
...
@@ -131,6 +131,20 @@ TEST(SpaceToBatchTest, SmallDataWithTwoPadding) {
...
@@ -131,6 +131,20 @@ TEST(SpaceToBatchTest, SmallDataWithTwoPadding) {
);
);
}
}
TEST
(
SpaceToBatchTest
,
SmallDataWithLargeImage
)
{
TestBidirectionalTransform
<
float
>
({
1
,
2
,
10
,
1
},
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
},
{
2
,
2
},
{
0
,
0
,
0
,
0
},
{
4
,
1
,
5
,
1
},
{
1
,
3
,
5
,
7
,
9
,
2
,
4
,
6
,
8
,
10
,
11
,
13
,
15
,
17
,
19
,
12
,
14
,
16
,
18
,
20
}
);
}
TEST
(
SpaceToBatchTest
,
MultiChannelData
)
{
TEST
(
SpaceToBatchTest
,
MultiChannelData
)
{
TestBidirectionalTransform
<
float
>
({
1
,
2
,
2
,
3
},
TestBidirectionalTransform
<
float
>
({
1
,
2
,
2
,
3
},
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
},
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录