Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
edba9dce
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
edba9dce
编写于
10月 15, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update conv cl code
上级
f3fe2493
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
197 addition
and
58 deletion
+197
-58
src/framework/cl/cl_engine.h
src/framework/cl/cl_engine.h
+2
-2
src/framework/cl/cl_image.h
src/framework/cl/cl_image.h
+15
-18
src/operators/kernel/cl/cl_kernel/conv_kernel.cl
src/operators/kernel/cl/cl_kernel/conv_kernel.cl
+130
-1
src/operators/kernel/cl/conv_kernel.cpp
src/operators/kernel/cl/conv_kernel.cpp
+45
-37
tools/android-debug-script/push2android.sh
tools/android-debug-script/push2android.sh
+5
-0
未找到文件。
src/framework/cl/cl_engine.h
浏览文件 @
edba9dce
...
...
@@ -40,8 +40,8 @@ class CLEngine {
return
std
::
move
(
context_ptr
);
}
std
::
unique_ptr
<
_cl_command_queue
,
CLCommQueueDeleter
>
CreateClCommandQueue
(
cl_context
context
)
{
std
::
unique_ptr
<
_cl_command_queue
,
CLCommQueueDeleter
>
CreateClCommandQueue
(
cl_context
context
)
{
cl_int
status
;
cl_command_queue
queue
=
clCreateCommandQueue
(
context
,
devices_
[
0
],
0
,
&
status
);
...
...
src/framework/cl/cl_image.h
浏览文件 @
edba9dce
...
...
@@ -193,10 +193,8 @@ class CLImage {
DLOG
<<
" image width: "
<<
width
;
DLOG
<<
" image height: "
<<
height
;
cl_image_format
cf
=
{
.
image_channel_order
=
CL_RGBA
,
.
image_channel_data_type
=
CL_HALF_FLOAT
};
cl_image_format
cf
=
{.
image_channel_order
=
CL_RGBA
,
.
image_channel_data_type
=
CL_HALF_FLOAT
};
cl_image_desc
cid
=
{
.
image_type
=
CL_MEM_OBJECT_IMAGE2D
,
.
image_width
=
width
,
...
...
@@ -211,8 +209,7 @@ class CLImage {
};
cid
.
buffer
=
nullptr
;
cl_image_
=
clCreateImage
(
context
,
CL_MEM_READ_WRITE
|
(
imageData
?
CL_MEM_COPY_HOST_PTR
:
0
),
context
,
CL_MEM_READ_WRITE
|
(
imageData
?
CL_MEM_COPY_HOST_PTR
:
0
),
&
cf
,
// const cl_image_format *image_format
&
cid
,
// const cl_image_desc *image_desc
reinterpret_cast
<
void
*>
(
imageData
.
get
()),
// void *host_ptr
...
...
src/operators/kernel/cl/cl_kernel/conv_kernel.cl
浏览文件 @
edba9dce
...
...
@@ -12,10 +12,139 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See
the
License
for
the
specific
language
governing
permissions
and
limitations
under
the
License.
*/
#
pragma
OPENCL
EXTENSION
cl_khr_fp16
:
enable
__kernel
void
conv_3x3
()
{
__kernel
void
conv_3x3
(
__private
const
int
global_size_dim0,
__private
const
int
global_size_dim1,
__private
const
int
global_size_dim2,
__read_only
image2d_t
input_image,
__read_only
image2d_t
filter,
#
ifdef
BIASE
__read_only
image2d_t
bias,
#
endif
#
ifdef
BATCH_NORM
__read_only
image2d_t
new_scale,
__read_only
image2d_t
new_biase,
#
endif
__write_only
image2d_t
output_image,
__private
const
int
stride,
__private
const
int
offset,
__private
const
int
input_c,
__private
const
int
dilation,
__private
const
int
input_width,/*
of
one
block
*/
__private
const
int
input_height,/*
of
one
block
*/
__private
const
int
output_width,
__private
const
int
output_height
)
{
const
int
out_c
=
get_global_id
(
0
)
;
const
int
out_w
=
get_global_id
(
1
)
;
const
int
out_nh
=
get_global_id
(
2
)
;
int2
stride_xy
;
stride_xy.x
=
stride
;
stride_xy.y
=
stride
;
int2
ouput_pos_in_one_block
;
ouput_pos_in_one_block.x
=
out_w
;
ouput_pos_in_one_block.y
=
out_nh
;
int2
in_pos_in_one_block
;
in_pos_in_one_block.x
=
ouput_pos_in_one_block.x
*
stride
+
offset
;
in_pos_in_one_block.y
=
ouput_pos_in_one_block.y
*
stride
+
offset
;
#
ifdef
BIASE
half4
output
=
read_imageh
(
bias,
sampler,
int2
(
out_c,
0
))
;
#
else
half4
output
=
0.0
;
#
endif
half4
input[9]
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
for
(
int
i
=
0
; i < input_c; ++i) {
int2
pos_in
=
(
int2
)(
i
*
input_width
+
in_pos_in_one_block.x,
in_pos_in_one_block.y
)
;
input[0]
=
select
(
read_imageh
(
input_image,
sampler,
(
int2
)(
pos_in.x
-
dilation,
pos_in.y
-
dilation
))
,
(
half4
)(
0.0
)
,
(
ushort4
)(
in_pos_in_one_block.x
-
dilation
<
0
|
| in_pos_in_one_block.y - dilation < 0 || in_pos_in_one_block.x - dilation >= input_width || in_pos_in_one_block.y - dilation >= input_height));
input[1] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x, pos_in.y - dilation)),
(half4)(0.0),
(ushort4)(in_pos_in_one_block.x < 0 || in_pos_in_one_block.y - dilation < 0 || in_pos_in_one_block.x >= input_width || in_pos_in_one_block.y - dilation >= input_height));
input[2] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x + dilation, pos_in.y - dilation)),
(half4)(0.0),
(ushort4)(in_pos_in_one_block.x + dilation < 0 || in_pos_in_one_block.y - dilation < 0 || in_pos_in_one_block.x + dilation >= input_width || in_pos_in_one_block.y - dilation >= input_height));
input[3] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x - dilation, pos_in.y)),
(half4)(0.0),
(ushort4)(in_pos_in_one_block.x - dilation < 0 || in_pos_in_one_block.y < 0 || in_pos_in_one_block.x - dilation >= input_width || in_pos_in_one_block.y >= input_height));
input[4] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x, pos_in.y)),
(half4)(0.0),
(ushort4)(in_pos_in_one_block.x < 0 || in_pos_in_one_block.y < 0 || in_pos_in_one_block.x >= input_width || in_pos_in_one_block.y >= input_height));
input[5] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x + dilation, pos_in.y)),
(half4)(0.0),
(ushort4)(in_pos_in_one_block.x + dilation < 0 || in_pos_in_one_block.y < 0 || in_pos_in_one_block.x + dilation >= input_width || in_pos_in_one_block.y >= input_height));
input[6] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x - dilation, pos_in.y + dilation)),
(half4)(0.0),
(ushort4)(in_pos_in_one_block.x - dilation < 0 || in_pos_in_one_block.y + dilation < 0 || in_pos_in_one_block.x - dilation >= input_width || in_pos_in_one_block.y + dilation >= input_height));
input[7] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x, pos_in.y + dilation)),
(half4)(0.0),
(ushort4)(in_pos_in_one_block.x < 0 || in_pos_in_one_block.y + dilation < 0 || in_pos_in_one_block.x >= input_width || in_pos_in_one_block.y + dilation >= input_height));
input[8] = select(read_imageh(input_image, sampler,
(int2)(pos_in.x + dilation, pos_in.y + dilation)),
(half4)(0.0),
(ushort4)(pos_in.x + dilation < 0 || in_pos_in_one_block.y + dilation < 0 || pos_in.x + dilation >= input_width |
|
in_pos_in_one_block.y
+
dilation
>=
input_height
))
;
for
(
int
j
=
0
; j < 9; ++j) {
int2
fuck
;
fuck.x
=
i
*
3
+
j
%
3
;
fuck.y
=
out_c
*
4
*
3
+
0
*
out_c
*
3
+
j
/
3
;
half4
weight_x
=
read_imageh
(
filter,
sampler,
fuck
)
;
output.x
+=
dot
(
input[j],
weight_x
)
;
fuck.y
=
out_c
*
4
*
3
+
1
*
out_c
*
3
+
j
/
3
;
half4
weight_y
=
read_imageh
(
filter,
sampler,
fuck
)
;
output.y
+=
dot
(
input[j],
weight_y
)
;
fuck.y
=
out_c
*
4
*
3
+
2
*
out_c
*
3
+
j
/
3
;
half4
weight_z
=
read_imageh
(
filter,
sampler,
fuck
)
;
output.z
+=
dot
(
input[j],
weight_z
)
;
fuck.y
=
out_c
*
4
*
3
+
3
*
out_c
*
3
+
j
/
3
;
half4
weight_w
=
read_imageh
(
filter,
sampler,
fuck
)
;
output.w
+=
dot
(
input[j],
weight_w
)
;
}
}
#
ifdef
BATCH_NORM
output
=
output
*
read_imageh
(
new_scale,
sampler,
int2
(
out_c,
0
))
+
read_imageh
(
new_biase,
sampler,
int2
(
out_c,
0
))
#
endif
#
ifdef
RELU
output
=
activation
(
output
)
;
#
endif
write_imageh
(
output_image,
(
int2
)(
out_c
*
global_size_dim1
+
out_w,
out_nh
)
,
output
)
;
}
src/operators/kernel/cl/conv_kernel.cpp
浏览文件 @
edba9dce
...
...
@@ -78,7 +78,7 @@ void ConvKernel<GPU_CL, float>::Compute(const ConvParam<GPU_CL> ¶m) {
DLOG
<<
" get Filter "
;
auto
output
=
param
.
Output
();
auto
output
=
param
.
Output
()
->
GetCLImage
()
;
DLOG
<<
" get Output "
;
...
...
@@ -89,45 +89,54 @@ void ConvKernel<GPU_CL, float>::Compute(const ConvParam<GPU_CL> ¶m) {
int
input_width
=
param
.
Input
()
->
WidthOfOneBlock
();
int
input_height
=
param
.
Input
()
->
HeightOfOneBlock
();
int
output_width
=
param
.
Output
()
->
WidthOfOneBlock
();
int
output_height
=
param
.
Output
()
->
HeightOfOneBlock
();
cl_int
status
;
DLOG
<<
" begin set kernel arg "
;
// status = clSetKernelArg(kernel, 0, sizeof(int), &c_block);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 1, sizeof(int), &w);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 2, sizeof(int), &nh);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 3, sizeof(cl_mem), &input);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 4, sizeof(cl_mem), &filter);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 5, sizeof(cl_mem), &output);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 6, sizeof(int), &stride);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 7, sizeof(int), &offset);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 8, sizeof(int), &input_c);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 9, sizeof(int), &dilation);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 10, sizeof(int), &input_width);
// CL_CHECK_ERRORS(status);
//
// status = clSetKernelArg(kernel, 11, sizeof(int), &input_height);
// CL_CHECK_ERRORS(status);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
int
),
&
c_block
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
int
),
&
w
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
int
),
&
nh
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_mem
),
&
input
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
4
,
sizeof
(
cl_mem
),
&
filter
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
5
,
sizeof
(
cl_mem
),
&
output
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
6
,
sizeof
(
int
),
&
stride
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
7
,
sizeof
(
int
),
&
offset
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
8
,
sizeof
(
int
),
&
input_c
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
9
,
sizeof
(
int
),
&
dilation
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
10
,
sizeof
(
int
),
&
input_width
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
11
,
sizeof
(
int
),
&
input_height
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
12
,
sizeof
(
int
),
&
output_width
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
13
,
sizeof
(
int
),
&
output_height
);
CL_CHECK_ERRORS
(
status
);
DLOG
<<
" end set kernel arg "
;
...
...
@@ -138,7 +147,6 @@ void ConvKernel<GPU_CL, float>::Compute(const ConvParam<GPU_CL> ¶m) {
default_work_size
.
data
(),
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
DLOG
<<
" end enqueue "
;
}
template
class
ConvKernel
<
GPU_CL
,
float
>;
...
...
tools/android-debug-script/push2android.sh
浏览文件 @
edba9dce
#!/usr/bin/env sh
push_fn
()
{
cp
../../src/operators/kernel/cl/cl_kernel/
*
../../build/release/arm-v7a/build/cl_kernel/
MODELS_PATH
=
"../../test/models/*"
MODELS_SRC
=
"../../test/models"
IMAGE_PATH
=
"../../test/images/*"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录