Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
526c446d
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
未验证
提交
526c446d
编写于
7月 30, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
7月 30, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix nearest_interp, concat by channel, leaky_relu. (#1775)
上级
a63d9e9d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
143 addition
and
44 deletion
+143
-44
src/operators/concat_op.cpp
src/operators/concat_op.cpp
+2
-4
src/operators/kernel/cl/cl_kernel/concat_kernel.cl
src/operators/kernel/cl/cl_kernel/concat_kernel.cl
+116
-28
src/operators/kernel/cl/cl_kernel/leakyrelu_kernel.cl
src/operators/kernel/cl/cl_kernel/leakyrelu_kernel.cl
+3
-3
src/operators/kernel/cl/cl_kernel/nearest_interp_kernel.cl
src/operators/kernel/cl/cl_kernel/nearest_interp_kernel.cl
+10
-6
src/operators/kernel/cl/nearest_interp_kernel.cpp
src/operators/kernel/cl/nearest_interp_kernel.cpp
+11
-2
src/operators/op_param.h
src/operators/op_param.h
+1
-1
未找到文件。
src/operators/concat_op.cpp
浏览文件 @
526c446d
...
...
@@ -32,10 +32,6 @@ void ConcatOp<Dtype, T>::InferShape() const {
inputs_dims
.
push_back
(
inputs
[
i
]
->
dims
());
}
auto
axis
=
static_cast
<
size_t
>
(
this
->
param_
.
Axis
())
-
(
this
->
param_
.
original_output_dims_size_
-
this
->
param_
.
Out
()
->
dims
().
size
());
if
(
n
==
1
)
{
DLOG
<<
"Warning: concat op have only one input, "
"may waste memory"
;
...
...
@@ -43,6 +39,8 @@ void ConcatOp<Dtype, T>::InferShape() const {
/// add all dim[axis] and check other dims if equal.
auto
out_dims
=
inputs_dims
[
0
];
auto
axis
=
static_cast
<
size_t
>
(
this
->
param_
.
Axis
())
-
(
this
->
param_
.
original_output_dims_size_
-
out_dims
.
size
());
int
in_zero_dims_size
=
out_dims
.
size
();
for
(
size_t
i
=
1
;
i
<
n
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
in_zero_dims_size
;
j
++
)
{
...
...
src/operators/kernel/cl/cl_kernel/concat_kernel.cl
浏览文件 @
526c446d
...
...
@@ -22,20 +22,61 @@ __kernel void concatByCWith2Inputs(__read_only image2d_t input_image_0,
__write_only
image2d_t
output_image,
__private
const
int
out_C,
__private
const
int
out_W
)
{
//
const
int
in_c
=
get_global_id
(
0
)
;
//
const
int
in_w
=
get_global_id
(
1
)
;
//
const
int
in_nh
=
get_global_id
(
2
)
;
//
//
int2
input_pos
;
//
input_pos.x
=
in_c
*
out_W
+
in_w
;
//
input_pos.y
=
in_nh
;
//
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
// CLK_ADDRESS_CLAMP |
//
CLK_FILTER_NEAREST
;
//
half4
input
;
//
input
=
read_imageh
(
input_image,
sampler,input_pos
)
;
//
//
write_imageh
(
output_image,
input_pos,
input
)
;
const
int
out_c
=
get_global_id
(
0
)
;
const
int
out_w
=
get_global_id
(
1
)
;
const
int
out_nh
=
get_global_id
(
2
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
int2
output_pos
;
output_pos.x
=
out_c
*
out_W
+
out_w
;
output_pos.y
=
out_nh
;
half4
output_data
;
for
(
int
i
=
0
; i < 4; i++) {
int
c
=
out_c
*
4
+
i
;
if
(
c
>=
out_C
)
{
break
;
}
int
c_in
;
half4
input_data
;
if
(
c
<
C_0
)
{
c_in
=
c
;
int2
input_pos
;
input_pos.x
=
(
c_in
/
4
)
*
out_W
+
out_w
;
input_pos.y
=
out_nh
;
input_data
=
read_imageh
(
input_image_0,
sampler,
input_pos
)
;
}
else
{
c_in
=
c
-
C_0
;
int2
input_pos
;
input_pos.x
=
(
c_in
/
4
)
*
out_W
+
out_w
;
input_pos.y
=
out_nh
;
input_data
=
read_imageh
(
input_image_1,
sampler,
input_pos
)
;
}
int
value_offset
=
c_in
%
4
;
float
value
;
if
(
value_offset
==
0
)
{
value
=
input_data.x
;
}
else
if
(
value_offset
==
1
)
{
value
=
input_data.y
;
}
else
if
(
value_offset
==
2
)
{
value
=
input_data.z
;
}
else
if
(
value_offset
==
3
)
{
value
=
input_data.w
;
}
if
(
i
==
0
)
{
output_data.x
=
value
;
}
else
if
(
i
==
1
)
{
output_data.y
=
value
;
}
else
if
(
i
==
2
)
{
output_data.z
=
value
;
}
else
if
(
i
==
3
)
{
output_data.w
=
value
;
}
}
write_imageh
(
output_image,
output_pos,
output_data
)
;
}
__kernel
void
concatByCWith3Inputs
(
__read_only
image2d_t
input_image_0,
...
...
@@ -47,20 +88,67 @@ __kernel void concatByCWith3Inputs(__read_only image2d_t input_image_0,
__write_only
image2d_t
output_image,
__private
const
int
out_C,
__private
const
int
out_W
)
{
//
const
int
in_c
=
get_global_id
(
0
)
;
//
const
int
in_w
=
get_global_id
(
1
)
;
//
const
int
in_nh
=
get_global_id
(
2
)
;
//
//
int2
input_pos
;
//
input_pos.x
=
in_c
*
out_W
+
in_w
;
//
input_pos.y
=
in_nh
;
//
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
// CLK_ADDRESS_CLAMP |
//
CLK_FILTER_NEAREST
;
//
half4
input
;
//
input
=
read_imageh
(
input_image,
sampler,input_pos
)
;
//
//
write_imageh
(
output_image,
input_pos,
input
)
;
const
int
out_c
=
get_global_id
(
0
)
;
const
int
out_w
=
get_global_id
(
1
)
;
const
int
out_nh
=
get_global_id
(
2
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
int2
output_pos
;
output_pos.x
=
out_c
*
out_W
+
out_w
;
output_pos.y
=
out_nh
;
half4
output_data
;
for
(
int
i
=
0
; i < 4; i++) {
int
c
=
out_c
*
4
+
i
;
if
(
c
>=
out_C
)
{
break
;
}
int
c_in
;
half4
input_data
;
if
(
c
<
C_0
)
{
c_in
=
c
;
int2
input_pos
;
input_pos.x
=
(
c_in
/
4
)
*
out_W
+
out_w
;
input_pos.y
=
out_nh
;
input_data
=
read_imageh
(
input_image_0,
sampler,
input_pos
)
;
}
else
if
(
c
<
C_0
+
C_1
)
{
c_in
=
c
-
C_0
;
int2
input_pos
;
input_pos.x
=
(
c_in
/
4
)
*
out_W
+
out_w
;
input_pos.y
=
out_nh
;
input_data
=
read_imageh
(
input_image_1,
sampler,
input_pos
)
;
}
else
{
c_in
=
c
-
C_0
-
C_1
;
int2
input_pos
;
input_pos.x
=
(
c_in
/
4
)
*
out_W
+
out_w
;
input_pos.y
=
out_nh
;
input_data
=
read_imageh
(
input_image_2,
sampler,
input_pos
)
;
}
int
value_offset
=
c_in
%
4
;
float
value
;
if
(
value_offset
==
0
)
{
value
=
input_data.x
;
}
else
if
(
value_offset
==
1
)
{
value
=
input_data.y
;
}
else
if
(
value_offset
==
2
)
{
value
=
input_data.z
;
}
else
if
(
value_offset
==
3
)
{
value
=
input_data.w
;
}
if
(
i
==
0
)
{
output_data.x
=
value
;
}
else
if
(
i
==
1
)
{
output_data.y
=
value
;
}
else
if
(
i
==
2
)
{
output_data.z
=
value
;
}
else
if
(
i
==
3
)
{
output_data.w
=
value
;
}
}
write_imageh
(
output_image,
output_pos,
output_data
)
;
}
__kernel
void
concatByH
(
__read_only
image2d_t
input_image,
...
...
src/operators/kernel/cl/cl_kernel/leakyrelu_kernel.cl
浏览文件 @
526c446d
...
...
@@ -30,9 +30,9 @@ __kernel void leakyrelu(__read_only image2d_t input,
half4
output_data
;
output_data.x
=
max
((
float
)(
in.x
)
,
(
float
)(
alpha
*
(
in.x
)))
;
output_data.y
=
max
((
float
)(
in.
x
)
,
(
float
)(
alpha
*
(
in.y
)))
;
output_data.z
=
max
((
float
)(
in.
x
)
,
(
float
)(
alpha
*
(
in.z
)))
;
output_data.w
=
max
((
float
)(
in.
x
)
,
(
float
)(
alpha
*
(
in.w
)))
;
output_data.y
=
max
((
float
)(
in.
y
)
,
(
float
)(
alpha
*
(
in.y
)))
;
output_data.z
=
max
((
float
)(
in.
z
)
,
(
float
)(
alpha
*
(
in.z
)))
;
output_data.w
=
max
((
float
)(
in.
w
)
,
(
float
)(
alpha
*
(
in.w
)))
;
write_imageh
(
output,
(
int2
)(
input_pos.x,
input_pos.y
)
,
output_data
)
;
}
src/operators/kernel/cl/cl_kernel/nearest_interp_kernel.cl
浏览文件 @
526c446d
...
...
@@ -15,19 +15,23 @@ limitations under the License. */
#
pragma
OPENCL
EXTENSION
cl_khr_fp16
:
enable
__kernel
void
nearest_interp
(
__read_only
image2d_t
input,
__write_only
image2d_t
output,
__private
const
float
scale_h,
__private
const
float
scale_w,
__private
const
int
dims_w
)
{
__private
const
int
in_dims_h,
__private
const
int
out_dims_h,
__private
const
int
in_dims_w,
__private
const
int
out_dims_w
)
{
const
int
c
=
get_global_id
(
0
)
;
const
int
w
=
get_global_id
(
1
)
;
const
int
nh
=
get_global_id
(
2
)
;
int2
output_pos
;
output_pos.x
=
c
*
dims_w
+
w
;
output_pos.x
=
c
*
out_
dims_w
+
w
;
output_pos.y
=
nh
;
int
out_n
=
nh
/
out_dims_h
;
int
out_h
=
nh
%
out_dims_h
;
int2
input_pos
;
input_pos.x
=
c
*
in_dims_w
+
w
/
scale_w
;
input_pos.y
=
out_n
*
in_dims_h
+
out_h
/
scale_h
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
//
uint
x
=
(
uint
)(
output_pos.x
/
scale_w
)
;
//
uint
y
=
(
uint
)(
output_pos.y
/
scale_h
)
;
//
half4
input_data
=
read_imageh
(
input,
sampler,
(
int2
)(
x,
y
))
;
//
write_imageh
(
output,
(
int2
)(
output_pos.x
,
output_pos.y
)
,
input_data
)
;
half4
input_data
=
read_imageh
(
input,
sampler,
(
int2
)(
input_pos.x,
input_pos.y
))
;
write_imageh
(
output,
(
int2
)(
output_pos.x
,
output_pos.y
)
,
input_data
)
;
}
src/operators/kernel/cl/nearest_interp_kernel.cpp
浏览文件 @
526c446d
...
...
@@ -38,7 +38,10 @@ void NearestInterpolationKernel<GPU_CL, float>::Compute(
cl_mem
output_image
=
output
->
GetCLImage
();
float
scale_h
=
output
->
dims
()[
2
]
/
input
->
dims
()[
2
];
float
scale_w
=
output
->
dims
()[
3
]
/
input
->
dims
()[
3
];
int
in_dims_w
=
output
->
dims
()[
3
];
int
in_dims_h
=
input
->
dims
()[
2
];
int
out_dims_h
=
output
->
dims
()[
2
];
int
in_dims_w
=
input
->
dims
()[
3
];
int
out_dims_w
=
output
->
dims
()[
3
];
cl_int
status
;
...
...
@@ -50,7 +53,13 @@ void NearestInterpolationKernel<GPU_CL, float>::Compute(
CL_CHECK_ERRORS
(
status
)
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
float
),
&
scale_w
);
CL_CHECK_ERRORS
(
status
)
status
=
clSetKernelArg
(
kernel
,
4
,
sizeof
(
int
),
&
in_dims_w
);
status
=
clSetKernelArg
(
kernel
,
4
,
sizeof
(
int
),
&
in_dims_h
);
CL_CHECK_ERRORS
(
status
)
status
=
clSetKernelArg
(
kernel
,
5
,
sizeof
(
int
),
&
out_dims_h
);
CL_CHECK_ERRORS
(
status
)
status
=
clSetKernelArg
(
kernel
,
6
,
sizeof
(
int
),
&
in_dims_w
);
CL_CHECK_ERRORS
(
status
)
status
=
clSetKernelArg
(
kernel
,
7
,
sizeof
(
int
),
&
out_dims_w
);
CL_CHECK_ERRORS
(
status
)
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
default_work_size
.
size
(),
NULL
,
...
...
src/operators/op_param.h
浏览文件 @
526c446d
...
...
@@ -686,7 +686,7 @@ class ConcatParam : public OpParam {
inputs_
=
InputMultiFrom
<
GType
>
(
inputs
,
*
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
*
scope
);
axis_
=
GetAttr
<
int
>
(
"axis"
,
attrs
);
original_output_dims_size_
=
out_
->
dims
().
size
();
original_output_dims_size_
=
inputs_
[
0
]
->
dims
().
size
();
}
vector
<
GType
*>
Inputs
()
const
{
return
inputs_
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录