Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
386e6b42
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看板
提交
386e6b42
编写于
10月 17, 2018
作者:
D
dolphin8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
relu
上级
4fe6fef6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
7 deletion
+63
-7
src/operators/kernel/cl/cl_kernel/relu.cl
src/operators/kernel/cl/cl_kernel/relu.cl
+29
-1
src/operators/kernel/cl/relu_kernel.cpp
src/operators/kernel/cl/relu_kernel.cpp
+14
-4
src/operators/op_param.h
src/operators/op_param.h
+20
-2
未找到文件。
src/operators/kernel/cl/cl_kernel/relu.cl
浏览文件 @
386e6b42
...
...
@@ -24,6 +24,34 @@ __kernel void relu(__read_only image2d_t input,
CLK_FILTER_NEAREST
;
half4
in
=
read_imageh
(
input,
sampler,
(
int2
)(
x,
y
))
;
in
=
max
((
half4
)(
0.0f,0.0f,0.0f,0.0f
)
,
in
)
;
in
=
max
((
half4
)(
0.0f,
0.0f,
0.0f,
0.0f
)
,
in
)
;
write_imageh
(
output,
(
int2
)(
x,
y
)
,
in
)
;
}
__kernel
void
relu_p0
(
__read_only
image2d_t
input,
__write_only
image2d_t
output
)
{
const
int
x
=
get_global_id
(
0
)
;
const
int
y
=
get_global_id
(
1
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
half4
in
=
read_imageh
(
input,
sampler,
(
int2
)(
x,
y
))
;
in
=
max
((
half4
)(
0.0f,
0.0f,
0.0f,
0.0f
)
,
in
)
;
write_imageh
(
output,
(
int2
)(
x,
y
)
,
in
)
;
}
__kernel
void
relu_p1
(
__read_only
image2d_t
input,
__write_only
image2d_t
output
)
{
const
int
x
=
get_global_id
(
0
)
;
const
int
y
=
get_global_id
(
1
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
half4
in
=
read_imageh
(
input,
sampler,
(
int2
)(
x,
y
))
;
write_imageh
(
output,
(
int2
)(
x,
y
)
,
in
)
;
}
\ No newline at end of file
src/operators/kernel/cl/relu_kernel.cpp
浏览文件 @
386e6b42
...
...
@@ -21,21 +21,31 @@ namespace operators {
template
<
>
bool
ReluKernel
<
GPU_CL
,
float
>::
Init
(
ReluParam
<
GPU_CL
>*
param
)
{
this
->
cl_helper_
.
AddKernel
(
"relu"
,
"relu.cl"
);
this
->
cl_helper_
.
AddKernel
(
"relu_p0"
,
"relu.cl"
);
this
->
cl_helper_
.
AddKernel
(
"relu_p1"
,
"relu.cl"
);
const
auto
dim
=
const_cast
<
framework
::
CLImage
*>
(
param
->
InputX
())
->
ImageDims
();
param
->
getMidImage
().
InitEmptyImage
(
this
->
cl_helper_
.
CLContext
(),
dim
);
return
true
;
}
template
<
>
void
ReluKernel
<
GPU_CL
,
float
>::
Compute
(
const
ReluParam
<
GPU_CL
>&
param
)
{
auto
kernel
=
this
->
cl_helper_
.
KernelAt
(
0
);
auto
kernel_p0
=
this
->
cl_helper_
.
KernelAt
(
1
);
auto
kernel_p1
=
this
->
cl_helper_
.
KernelAt
(
2
);
const
auto
*
input
=
param
.
InputX
();
auto
*
output
=
param
.
Out
();
auto
default_work_size
=
this
->
cl_helper_
.
DefaultWorkSize
(
*
output
);
auto
inputImage
=
input
->
GetCLImage
();
auto
outputImage
=
output
->
GetCLImage
();
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
inputImage
);
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
&
outputImage
);
auto
tImage
=
const_cast
<
ReluParam
<
GPU_CL
>&>
(
param
).
getMidImage
().
GetCLImage
();
clSetKernelArg
(
kernel_p0
,
0
,
sizeof
(
cl_mem
),
&
inputImage
);
clSetKernelArg
(
kernel_p0
,
0
,
sizeof
(
cl_mem
),
&
tImage
);
clSetKernelArg
(
kernel_p1
,
0
,
sizeof
(
cl_mem
),
&
tImage
);
clSetKernelArg
(
kernel_p1
,
1
,
sizeof
(
cl_mem
),
&
outputImage
);
const
size_t
work_size
[
2
]
=
{
input
->
ImageWidth
(),
input
->
ImageHeight
()};
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
3
,
NULL
,
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel_p0
,
3
,
NULL
,
work_size
,
NULL
,
0
,
NULL
,
NULL
);
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel_p1
,
3
,
NULL
,
work_size
,
NULL
,
0
,
NULL
,
NULL
);
}
...
...
src/operators/op_param.h
浏览文件 @
386e6b42
...
...
@@ -1229,12 +1229,12 @@ class ResizeParam : public OpParam {
* @b op 层实例化好这个 param 传递给 kernel 层使用
* */
template
<
typename
Dtype
>
class
ReluParam
:
public
OpParam
{
class
ReluParam
Base
:
public
OpParam
{
typedef
typename
DtypeTensorTrait
<
Dtype
>::
gtype
GType
;
typedef
typename
DtypeTensorTrait
<
Dtype
>::
rtype
RType
;
public:
ReluParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
ReluParam
Base
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
...
...
@@ -1248,6 +1248,24 @@ class ReluParam : public OpParam {
RType
*
input_x_
;
RType
*
out_
;
};
template
<
typename
Dtype
>
class
ReluParam
:
public
ReluParamBase
<
Dtype
>
{
public:
using
ReluParamBase
<
Dtype
>::
ReluParamBase
;
};
template
<
>
class
ReluParam
<
GPU_CL
>
:
public
ReluParamBase
<
GPU_CL
>
{
public:
using
ReluParamBase
<
GPU_CL
>::
ReluParamBase
;
framework
::
CLImage
&
getMidImage
()
{
return
midImage
;
}
private:
framework
::
CLImage
midImage
;
};
#endif
#ifdef PRELU_OP
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录