Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
as350144
Mace
提交
ac492a1b
Mace
项目概览
as350144
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
2
Star
1
Fork
1
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac492a1b
编写于
10月 24, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tuning 1x1 opencl kernel for MI6
上级
129608cc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
46 deletion
+81
-46
mace/kernels/opencl/cl/conv_2d_1x1.cl
mace/kernels/opencl/cl/conv_2d_1x1.cl
+58
-32
mace/kernels/opencl/conv_2d_opencl_1x1.cc
mace/kernels/opencl/conv_2d_opencl_1x1.cc
+23
-14
未找到文件。
mace/kernels/opencl/cl/conv_2d_1x1.cl
浏览文件 @
ac492a1b
/*
/*
*
Split
work
item
along
output
channels
and
pixels
*
Split
work
item
along
output
channels
and
pixels
*/
*/
void
kernel
conv_2d_1x1_n
aive
(
global
const
float
*input,
/*
n,
c,
h,
w
*/
void
kernel
conv_2d_1x1_n
chw
(
global
const
float
*input,
/*
n,
c,
h,
w
*/
global
const
float
*filter,
/*
o,
i,
kh,
kw
*/
global
const
float
*filter,
/*
o,
i,
kh,
kw
*/
global
float
*output,
/*
n,
c,
h,
w
*/
global
float
*output,
/*
n,
c,
h,
w
*/
private
const
int
in_offset,
private
const
int
in_offset,
private
const
int
out_offset,
private
const
int
out_offset,
private
const
int
pixel_num,
private
const
int
pixel_num,
private
const
int
in_chan_num,
private
const
int
in_chan_num,
private
const
int
out_chan_num
)
{
private
const
int
out_chan_num
)
{
int
out_chan_blk
=
get_global_id
(
0
)
;
int
out_chan_blk
=
get_global_id
(
0
)
;
int
out_pixel_blk
=
get_global_id
(
1
)
;
int
out_pixel_blk
=
get_global_id
(
1
)
;
const
int
out_chan_begin
=
out_chan_blk
<<
2
;
const
int
out_chan_begin
=
out_chan_blk
*
4
;
const
int
out_chan_end
=
min
(
out_chan_begin
+
4
,
out_chan_num
)
;
const
int
out_chan_end
=
min
(
out_chan_begin
+
4
,
out_chan_num
)
;
const
int
out_pixel_begin
=
out_pixel_blk
<<
3
;
const
int
out_pixel_begin
=
out_pixel_blk
*
4
;
const
int
out_pixel_end
=
min
(
out_pixel_begin
+
8
,
pixel_num
)
;
const
int
out_pixel_end
=
min
(
out_pixel_begin
+
4
,
pixel_num
)
;
const
float
*input_base
=
input
+
in_offset
+
out_pixel_begin
;
const
float
*input_base
=
input
+
in_offset
+
out_pixel_begin
;
float
*output_base
=
output
+
out_offset
+
out_pixel_begin
;
float
*output_base
=
output
+
out_offset
+
out_pixel_begin
;
int
pixels
=
out_pixel_end
-
out_pixel_begin
;
for
(
int
in_chan
=
0
; in_chan < in_chan_num; ++in_chan) {
int
pixels
=
out_pixel_end
-
out_pixel_begin
;
const
float
*input_ptr
=
input_base
+
in_chan
*
pixel_num
;
int
in_chan
=
0
;
if
(
pixels
==
8
)
{
if
(
pixels
==
4
)
{
/*
TODO
fix
'
#
pragma
unroll
'
build
error
*/
for
(
; in_chan + 3 < in_chan_num; in_chan += 4) {
for
(
int
out_chan
=
out_chan_begin
; out_chan < out_chan_end; ++out_chan) {
const
float
*input_ptr
=
input_base
+
in_chan
*
pixel_num
;
float
weights
=
filter[out_chan
*
in_chan_num
+
in_chan]
;
int
out_chan
=
out_chan_begin
;
for
(
; out_chan + 3 < out_chan_end; out_chan += 4) {
const
float*
filter_ptr
=
filter
+
out_chan
*
in_chan_num
+
in_chan
;
float
*output_ptr
=
output_base
+
out_chan
*
pixel_num
;
float
*output_ptr
=
output_base
+
out_chan
*
pixel_num
;
for
(
int
p
=
0
; p < 2; ++p) {
float4
in0
=
vload4
(
0
,
input_ptr
)
;
float4
in
=
vload4
(
p,
input_ptr
)
;
float4
in1
=
vload4
(
0
,
input_ptr
+
pixel_num
)
;
float4
out
=
vload4
(
p,
output_ptr
)
;
float4
in2
=
vload4
(
0
,
input_ptr
+
2
*
pixel_num
)
;
out
+=
in
*
weights
;
float4
in3
=
vload4
(
0
,
input_ptr
+
3
*
pixel_num
)
;
vstore4
(
out,
p,
output_ptr
)
;
for
(
int
oc
=
0
; oc < 4; ++oc) {
float4
weights
=
vload4
(
0
,
filter_ptr
+
oc
*
in_chan_num
)
;
float4
out
=
vload4
(
0
,
output_ptr
+
oc
*
pixel_num
)
;
out
+=
in0
*
weights.x
;
out
+=
in1
*
weights.y
;
out
+=
in2
*
weights.z
;
out
+=
in3
*
weights.w
;
vstore4
(
out,
0
,
output_ptr
+
oc
*
pixel_num
)
;
}
}
}
}
}
else
{
for
(
; out_chan < out_chan_end; ++out_chan) {
for
(
int
out_chan
=
out_chan_begin
; out_chan < out_chan_end; ++out_chan) {
const
float*
filter_ptr
=
filter
+
out_chan
*
in_chan_num
+
in_chan
;
float
weights
=
filter[out_chan
*
in_chan_num
+
in_chan]
;
float
*output_ptr
=
output_base
+
out_chan
*
pixel_num
;
float
*output_ptr
=
output_base
+
out_chan
*
pixel_num
;
float4
weights
=
vload4
(
0
,
filter_ptr
)
;
float4
in0
=
vload4
(
0
,
input_ptr
)
;
float4
in1
=
vload4
(
0
,
input_ptr
+
pixel_num
)
;
float4
in2
=
vload4
(
0
,
input_ptr
+
2
*
pixel_num
)
;
float4
in3
=
vload4
(
0
,
input_ptr
+
3
*
pixel_num
)
;
float4
out
=
vload4
(
0
,
output_ptr
)
;
out
+=
in0
*
weights.x
;
out
+=
in1
*
weights.y
;
out
+=
in2
*
weights.z
;
out
+=
in3
*
weights.w
;
vstore4
(
out,
0
,
output_ptr
)
;
}
}
}
for
(
int
p
=
0
; p < pixels; ++p) {
for
(
; in_chan < in_chan_num; ++in_chan) {
float
in
=
input_ptr[p]
;
const
float
*input_ptr
=
input_base
+
in_chan
*
pixel_num
;
float
out
=
output_ptr[p]
;
for
(
int
out_chan
=
out_chan_begin
; out_chan < out_chan_end; ++out_chan) {
out
+=
in
*
weights
;
float
weights
=
filter[out_chan
*
in_chan_num
+
in_chan]
;
output_ptr[p]
=
out
;
float
*output_ptr
=
output_base
+
out_chan
*
pixel_num
;
}
for
(
int
p
=
0
; p < pixels; ++p) {
float
in
=
input_ptr[p]
;
float
out
=
output_ptr[p]
;
out
+=
in
*
weights
;
output_ptr[p]
=
out
;
}
}
}
}
}
}
...
...
mace/kernels/opencl/conv_2d_opencl_1x1.cc
浏览文件 @
ac492a1b
...
@@ -50,44 +50,53 @@ void AssignBias(Tensor *output, const Tensor *bias) {
...
@@ -50,44 +50,53 @@ void AssignBias(Tensor *output, const Tensor *bias) {
}
}
}
}
extern
void
Conv2dOpenclK1x1S1
(
const
Tensor
*
input
,
const
Tensor
*
filter
,
void
Conv1x1NCHW
(
const
Tensor
*
input
,
const
Tensor
*
bias
,
Tensor
*
output
)
{
const
Tensor
*
filter
,
Tensor
*
output
)
{
const
index_t
batch
=
output
->
shape
()[
0
];
const
index_t
batch
=
output
->
shape
()[
0
];
const
index_t
channels
=
output
->
shape
()[
1
];
const
index_t
channels
=
output
->
shape
()[
1
];
const
index_t
height
=
output
->
shape
()[
2
];
const
index_t
height
=
output
->
shape
()[
2
];
const
index_t
width
=
output
->
shape
()[
3
];
const
index_t
width
=
output
->
shape
()[
3
];
const
index_t
input_batch
=
input
->
shape
()[
0
];
const
index_t
input_channels
=
input
->
shape
()[
1
];
const
index_t
input_channels
=
input
->
shape
()[
1
];
const
index_t
input_height
=
input
->
shape
()[
2
];
const
index_t
input_width
=
input
->
shape
()[
3
];
MACE_CHECK
(
input_batch
==
batch
&&
input_height
==
height
&&
input_width
==
width
);
AssignBias
(
output
,
bias
);
auto
runtime
=
OpenCLRuntime
::
Get
();
auto
runtime
=
OpenCLRuntime
::
Get
();
auto
program
=
runtime
->
program
();
auto
program
=
runtime
->
program
();
auto
conv_2d
=
cl
::
KernelFunctor
<
cl
::
Buffer
,
cl
::
Buffer
,
cl
::
Buffer
,
auto
conv_2d
=
cl
::
KernelFunctor
<
cl
::
Buffer
,
cl
::
Buffer
,
cl
::
Buffer
,
int
,
int
,
int
,
int
,
int
>
(
program
,
"conv_2d_1x1_n
aive
"
);
int
,
int
,
int
,
int
,
int
>
(
program
,
"conv_2d_1x1_n
chw
"
);
const
index_t
total_pixels
=
height
*
width
;
const
index_t
total_pixels
=
height
*
width
;
for
(
int
b
=
0
;
b
<
batch
;
++
b
)
{
for
(
int
b
=
0
;
b
<
batch
;
++
b
)
{
int
input_offset
=
b
*
input_channels
*
total_pixels
;
int
input_offset
=
b
*
input_channels
*
total_pixels
;
int
output_offset
=
b
*
channels
*
total_pixels
;
int
output_offset
=
b
*
channels
*
total_pixels
;
int
chan_blk_num
=
(
channels
+
3
)
>>
2
;
// each 4 output channels
int
chan_blk_num
=
(
channels
+
3
)
>>
2
;
// each 4 output channels
int
pixel_blk_num
=
(
total_pixels
+
7
)
>>
3
;
// each 8
pixels
int
pixel_blk_num
=
(
total_pixels
+
3
)
>>
2
;
// each 4
pixels
cl_int
error
;
cl_int
error
;
conv_2d
(
cl
::
EnqueueArgs
(
runtime
->
command_queue
(),
conv_2d
(
cl
::
EnqueueArgs
(
runtime
->
command_queue
(),
cl
::
NDRange
(
chan_blk_num
,
pixel_blk_num
),
cl
::
NDRange
(
chan_blk_num
,
pixel_blk_num
),
cl
::
NDRange
(
1
,
64
)),
cl
::
NDRange
(
1
,
256
)),
*
(
static_cast
<
cl
::
Buffer
*>
(
input
->
buffer
())),
*
(
static_cast
<
cl
::
Buffer
*>
(
input
->
buffer
())),
*
(
static_cast
<
cl
::
Buffer
*>
(
filter
->
buffer
())),
*
(
static_cast
<
cl
::
Buffer
*>
(
filter
->
buffer
())),
*
(
static_cast
<
cl
::
Buffer
*>
(
output
->
buffer
())),
*
(
static_cast
<
cl
::
Buffer
*>
(
output
->
buffer
())),
input_offset
,
output_offset
,
total_pixels
,
input_channels
,
channels
,
error
);
input_offset
,
output_offset
,
total_pixels
,
input_channels
,
channels
,
error
);
MACE_CHECK
(
error
==
CL_SUCCESS
);
MACE_CHECK
(
error
==
CL_SUCCESS
);
}
}
}
extern
void
Conv2dOpenclK1x1S1
(
const
Tensor
*
input
,
const
Tensor
*
filter
,
const
Tensor
*
bias
,
Tensor
*
output
)
{
const
index_t
batch
=
output
->
shape
()[
0
];
const
index_t
height
=
output
->
shape
()[
2
];
const
index_t
width
=
output
->
shape
()[
3
];
const
index_t
input_batch
=
input
->
shape
()[
0
];
const
index_t
input_height
=
input
->
shape
()[
2
];
const
index_t
input_width
=
input
->
shape
()[
3
];
MACE_CHECK
(
input_batch
==
batch
&&
input_height
==
height
&&
input_width
==
width
);
AssignBias
(
output
,
bias
);
Conv1x1NCHW
(
input
,
filter
,
output
);
};
};
}
// namespace kernels
}
// namespace kernels
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录