Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
f15275d1
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看板
提交
f15275d1
编写于
10月 16, 2018
作者:
Y
yangfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
imp add op kernel
上级
25ce72b7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
101 addition
and
11 deletion
+101
-11
src/operators/kernel/cl/cl_kernel/channel_add_kernel.cl
src/operators/kernel/cl/cl_kernel/channel_add_kernel.cl
+29
-0
src/operators/kernel/cl/cl_kernel/elementwise_add_kernel.cl
src/operators/kernel/cl/cl_kernel/elementwise_add_kernel.cl
+12
-4
src/operators/kernel/cl/cl_kernel/feed_kernel.cl
src/operators/kernel/cl/cl_kernel/feed_kernel.cl
+2
-2
src/operators/kernel/cl/elementwise_add_kernel.cpp
src/operators/kernel/cl/elementwise_add_kernel.cpp
+57
-3
src/operators/kernel/cl/feed_kernel.cpp
src/operators/kernel/cl/feed_kernel.cpp
+1
-2
未找到文件。
src/operators/kernel/cl/cl_kernel/channel_add_kernel.cl
0 → 100644
浏览文件 @
f15275d1
/*
Copyright
(
c
)
2018
PaddlePaddle
Authors.
All
Rights
Reserved.
Licensed
under
the
Apache
License,
Version
2.0
(
the
"License"
)
;
you
may
not
use
this
file
except
in
compliance
with
the
License.
You
may
obtain
a
copy
of
the
License
at
http://www.apache.org/licenses/LICENSE-2.0
Unless
required
by
applicable
law
or
agreed
to
in
writing,
software
distributed
under
the
License
is
distributed
on
an
"AS IS"
BASIS,
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
channel_add
(
__global
image2d_t
input,
__global
image2d_t
bias,__write_only
image2d_t
outputImage,int
w
)
{
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
| CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
int2
coords
;
coords.x
=
x
;
coords.y
=
y
;
int2
coords_bias
;
coords_bias.x
=
x/w
;
coords_bias.y
=
1
;
half4
in
=
read_imageh
(
input,
sampler,
coords
)
;
half4
biase
=
read_imageh
(
bias,
sampler,
coords_bias
)
;
half4
output
=
in
+
biase
;
write_imageh
(
outputImage,coords,output
)
;
}
src/operators/kernel/cl/cl_kernel/elementwise_add_kernel.cl
浏览文件 @
f15275d1
...
...
@@ -11,8 +11,16 @@ distributed under the License is distributed on an "AS IS" BASIS,
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.
*/
__kernel
void
elementwise_add
(
__global
float*
in,
__global
float*
out
)
{
int
num
=
get_global_id
(
0
)
;
out[num]
=
in[num]
*
0.1
+
102
;
#
pragma
OPENCL
EXTENSION
cl_khr_fp16
:
enable
__kernel
void
elementwise_add
(
__global
image2d_t
input,
__global
image2d_t
bias,__write_only
image2d_t
outputImage
)
{
int
x
=
get_global_id
(
0
)
;
int
y
=
get_global_id
(
1
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
| CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
int2
coords
;
coords.x
=
x
;
coords.y
=
y
;
half4
in
=
read_imageh
(
input,
sampler,
coords
)
;
half4
biase
=
read_imageh
(
bias,
sampler,
coords
)
;
half4
output
=
in
+
biase
;
write_imageh
(
outputImage,coords,output
)
;
}
src/operators/kernel/cl/cl_kernel/feed_kernel.cl
浏览文件 @
f15275d1
#
pragma
OPENCL
EXTENSION
cl_khr_fp16
:
enable
__kernel
void
feed
(
__global
float
*in,
__write_only
image2d_t
outputImage,int
h,int
w
)
{
int
j
=
get_global_id
(
0
)
;
int
i
=
get_global_id
(
1
)
;
int
i
=
get_global_id
(
0
)
;
int
j
=
get_global_id
(
1
)
;
half4
pixel
;
pixel.x
=
convert_half
(
in[
(
i
*
w
+
j
)
]
)
;
pixel.y
=
convert_half
(
in[h
*
w
+
(
i
*
w
+
j
)
]
)
;
...
...
src/operators/kernel/cl/elementwise_add_kernel.cpp
浏览文件 @
f15275d1
...
...
@@ -22,14 +22,68 @@ namespace operators {
template
<
>
bool
ElementwiseAddKernel
<
GPU_CL
,
float
>::
Init
(
ElementwiseAddParam
<
GPU_CL
>
*
param
)
{
// this->cl_helper_.AddKernel("elementwise_add",
// "elementwise_add_kernel.cl");
CLImage
*
bias
=
(
CLImage
*
)
param
->
InputY
();
bias
->
InitCLImage
(
cl_helper_
.
CLContext
());
if
(
bias
->
dims
().
size
()
==
4
){
this
->
cl_helper_
.
AddKernel
(
"elementwise_add"
,
"elementwise_add_kernel.cl"
);
}
else
if
(
param
->
InputY
()
->
dims
().
size
()
==
1
){
DLOG
<<
"-----init add-----"
;
this
->
cl_helper_
.
AddKernel
(
"channel_add"
,
"channel_add_kernel.cl"
);
}
else
{
DLOG
<<
"error:bias dims is error"
;
}
return
true
;
}
template
<
>
void
ElementwiseAddKernel
<
GPU_CL
,
float
>::
Compute
(
const
ElementwiseAddParam
<
GPU_CL
>
&
param
)
{}
const
ElementwiseAddParam
<
GPU_CL
>
&
param
)
{
auto
input
=
param
.
InputX
();
auto
bias
=
param
.
InputY
();
auto
output
=
param
.
Out
();
cl_int
status
;
auto
kernel
=
this
->
cl_helper_
.
KernelAt
(
0
);
if
(
bias
->
dims
().
size
()
==
4
){
cl_mem
input_image
=
input
->
GetCLImage
();
cl_mem
bias_image
=
bias
->
GetCLImage
();
cl_mem
output_image
=
output
->
GetCLImage
();
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
(
void
*
)
&
input_image
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
(
void
*
)
&
bias_image
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
cl_mem
),
(
void
*
)
&
output_image
);
CL_CHECK_ERRORS
(
status
);
int
width
=
input
->
ImageWidth
();
int
height
=
input
->
ImageHeight
();
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
}
else
if
(
bias
->
dims
().
size
()
==
1
){
cl_mem
input_image
=
input
->
GetCLImage
();
cl_mem
bias_image
=
bias
->
GetCLImage
();
cl_mem
output_image
=
output
->
GetCLImage
();
int
tensor_w
=
input
->
dims
()[
4
];
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
(
void
*
)
&
input_image
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
(
void
*
)
&
bias_image
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
2
,
sizeof
(
cl_mem
),
(
void
*
)
&
output_image
);
CL_CHECK_ERRORS
(
status
);
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_int
),
(
void
*
)
&
tensor_w
);
CL_CHECK_ERRORS
(
status
);
int
width
=
input
->
ImageWidth
();
int
height
=
input
->
ImageHeight
();
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
}
else
{
DLOG
<<
"error:bias dims is error"
;
}
}
template
class
ElementwiseAddKernel
<
GPU_CL
,
float
>;
...
...
src/operators/kernel/cl/feed_kernel.cpp
浏览文件 @
f15275d1
...
...
@@ -49,7 +49,7 @@ void FeedKernel<GPU_CL, float>::Compute(const FeedParam<GPU_CL> ¶m) {
status
=
clSetKernelArg
(
kernel
,
3
,
sizeof
(
cl_int
),
(
void
*
)
&
height
);
CL_CHECK_ERRORS
(
status
);
size_t
global_work_size
[
2
]
=
{
height
,
width
};
size_t
global_work_size
[
2
]
=
{
width
,
height
};
status
=
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
status
);
...
...
@@ -61,7 +61,6 @@ void FeedKernel<GPU_CL, float>::Compute(const FeedParam<GPU_CL> ¶m) {
size_t
region
[
3
]
=
{
height
,
width
,
1
};
clEnqueueReadImage
(
commandQueue
,
cl_image
,
CL_TRUE
,
origin
,
region
,
0
,
0
,
out
,
0
,
NULL
,
NULL
);
}
template
class
FeedKernel
<
GPU_CL
,
float
>;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录