Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
c436fd15
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看板
提交
c436fd15
编写于
10月 12, 2018
作者:
D
dolphin8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reshape & relu & softmax
上级
a01da691
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
147 addition
and
2 deletion
+147
-2
src/operators/kernel/cl/cl_kernel/relu.cl
src/operators/kernel/cl/cl_kernel/relu.cl
+25
-0
src/operators/kernel/cl/cl_kernel/reshape.cl
src/operators/kernel/cl/cl_kernel/reshape.cl
+49
-0
src/operators/kernel/cl/cl_kernel/softmax.cl
src/operators/kernel/cl/cl_kernel/softmax.cl
+41
-0
src/operators/kernel/cl/relu_kernel.cpp
src/operators/kernel/cl/relu_kernel.cpp
+14
-1
src/operators/kernel/cl/softmax_kernel.cpp
src/operators/kernel/cl/softmax_kernel.cpp
+18
-1
未找到文件。
src/operators/kernel/cl/cl_kernel/relu.cl
0 → 100644
浏览文件 @
c436fd15
/*
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.
*/
__kernel
void
relu
(
__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
r
=
read_imageh
(
input,
sampler,
int2
(
x,
y
))
;
r
=
max
(
half4
(
0
,
0
,
0
,
0
)
,
r
)
;
write_imageh
(
output,
int2
(
x,
y
)
,
r
)
;
}
\ No newline at end of file
src/operators/kernel/cl/cl_kernel/reshape.cl
0 → 100644
浏览文件 @
c436fd15
/*
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.
*/
__kernel
void
reshape
(
__read_only
image2d_t
input,
__write_only
image2d_t
output,
__private
const
int
d0,
__private
const
int
d1,
__private
const
int
d2,
__private
const
int
d3,
__private
const
int
x0,
__private
const
int
x1,
__private
const
int
x2,
__private
const
int
x3
)
{
const
int
x
=
get_global_id
(
0
)
;
const
int
y
=
get_global_id
(
1
)
;
int
obx
=
x
/
x3
;
int
oby
=
y
/
x2
;
int
ox
=
x
%
x3
;
int
oy
=
y
%
x2
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
half4
r
;
for
(
int
i
=
0
; i < 4; i++) {
int
t
=
obx
*
4
+
i
;
if
(
t
>
x1
)
break
;
int
oindex
=
oby
*
x1
*
x2
*
x3
+
t
*
x2
*
x3
+
ox
*
x3
+
oy
;
int
i0,
i1,
i2,
i3
;
int
i3
=
oindex
%
d3
; oindex /= d3;
int
i2
=
oindex
%
d2
; oindex /= d2;
int
i1
=
oindex
%
d1
; oindex /= d1;
int
i0
=
oindex
;
int
ix
=
(
i1
/
4
)
*
d3
+
i3
;
int
iy
=
i0
*
d2
+
i2
;
r[i]
=
read_imageh
(
input,
sampler,
int2
(
ix,
iy
))
[i1%4]
;
}
write_imageh
(
output,
int2
(
x,
y
)
,
r
)
;
}
\ No newline at end of file
src/operators/kernel/cl/cl_kernel/softmax.cl
0 → 100644
浏览文件 @
c436fd15
/*
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.
*/
__kernel
void
softmax
(
__read_only
image2d_t
input,
__write_only
image2d_t
output,
__private
const
int
d0,
__private
const
int
d1,
__private
const
int
d2,
__private
const
int
d3
)
{
const
int
z
=
get_global_id
(
0
)
;
const
int
x
=
get_global_id
(
1
)
;
const
int
y
=
get_global_id
(
2
)
;
const
sampler_t
sampler
=
CLK_NORMALIZED_COORDS_TRUE
|
CLK_ADDRESS_CLAMP |
CLK_FILTER_NEAREST
;
half4
maxv
=
read_imageh
(
input,
sampler,
int2
(
z
*
d3,
y
))
;
half4
buf[d3]
=
{piece}
;
for
(
int
i
=
1
; i < d3; i++) {
buf[i]
=
read_imageh
(
input,
sampler,
int2
(
z
*
d3
+
i,
y
))
;
maxv
=
max
(
maxv,
buf[i]
)
;
}
float4
sum
=
0
;
for
(
int
i
=
0
; i < d3; i++) {
buf[i]
=
exp
(
buf[i]
-
maxv
)
;
sum
+=
buf[i]
;
}
half4
r
=
buf[x]
/
sum
;
write_imageh
(
output,
int2
(
z
*
d3
+
x,
y
)
,
r
)
;
}
src/operators/kernel/cl/relu_kernel.cpp
浏览文件 @
c436fd15
...
@@ -11,6 +11,7 @@ distributed under the License is distributed on an "AS IS" BASIS,
...
@@ -11,6 +11,7 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#ifdef RELU_OP
#include "operators/kernel/relu_kernel.h"
#include "operators/kernel/relu_kernel.h"
...
@@ -19,13 +20,25 @@ namespace operators {
...
@@ -19,13 +20,25 @@ namespace operators {
template
<
>
template
<
>
bool
ReluKernel
<
GPU_CL
,
float
>::
Init
(
ReluParam
<
GPU_CL
>
*
param
)
{
bool
ReluKernel
<
GPU_CL
,
float
>::
Init
(
ReluParam
<
GPU_CL
>
*
param
)
{
this
->
cl_helper_
.
AddKernel
(
"relu"
,
"relu.cl"
);
return
true
;
return
true
;
}
}
template
<
>
template
<
>
void
ReluKernel
<
GPU_CL
,
float
>::
Compute
(
const
ReluParam
<
GPU_CL
>
&
param
)
{}
void
ReluKernel
<
GPU_CL
,
float
>::
Compute
(
const
ReluParam
<
GPU_CL
>
&
param
)
{
auto
kernel
=
this
->
cl_helper_
.
KernelAt
(
0
);
const
auto
*
input
=
param
.
InputX
();
auto
*
output
=
parma
.
Out
();
auto
default_work_size
=
this
->
cl_helper_
.
DefaultWorkSize
(
*
output
);
clSetKernelArg
((
kernel
,
0
,
sizeof
(
cl_mem
),
&
input
.
getCLImage
());
clSetKernelArg
((
kernel
,
1
,
sizeof
(
cl_mem
),
&
output
.
getCLImage
());
int
work_size
[
2
]
=
{
input
.
ImageWidth
(),
input
.
ImageHeight
()
};
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
3
,
NULL
,
work_size
,
NULL
,
0
,
NULL
,
NULL
);
}
template
class
ReluKernel
<
GPU_CL
,
float
>;
template
class
ReluKernel
<
GPU_CL
,
float
>;
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
}
// namespace paddle_mobile
#endif
\ No newline at end of file
src/operators/kernel/cl/softmax_kernel.cpp
浏览文件 @
c436fd15
...
@@ -21,11 +21,28 @@ namespace operators {
...
@@ -21,11 +21,28 @@ namespace operators {
template
<
>
template
<
>
bool
SoftmaxKernel
<
GPU_CL
,
float
>::
Init
(
SoftmaxParam
<
GPU_CL
>
*
param
)
{
bool
SoftmaxKernel
<
GPU_CL
,
float
>::
Init
(
SoftmaxParam
<
GPU_CL
>
*
param
)
{
this
->
cl_helper_
.
AddKernel
(
"softmax"
,
"softmax.cl"
);
return
true
;
return
true
;
}
}
template
<
>
template
<
>
void
SoftmaxKernel
<
GPU_CL
,
float
>::
Compute
(
const
SoftmaxParam
<
GPU_CL
>
&
param
)
{}
void
SoftmaxKernel
<
GPU_CL
,
float
>::
Compute
(
const
SoftmaxParam
<
GPU_CL
>
&
param
)
{
auto
kernel
=
this
->
cl_helper_
.
KernelAt
(
0
);
auto
default_work_size
=
this
->
cl_helper_
.
DefaultWorkSize
(
*
(
param
.
Out
()));
auto
&
input
=
param
.
InputX
();
auto
&
output
=
param
.
Out
();
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
input
.
getCLImage
());
clSetKernelArg
(
kernel
,
1
,
sizeof
(
cl_mem
),
&
output
.
getCLImage
());
const
auto
&
inputDim
=
input
.
dims
();
int
dims
[
4
]
=
{
inputDim
[
0
],
inputDim
[
1
],
inputDim
[
2
],
inputDim
[
3
]};
clSetKernelArg
(
kernel
,
2
,
sizeof
(
int
),
dims
);
clSetKernelArg
(
kernel
,
3
,
sizeof
(
int
),
dims
+
1
);
clSetKernelArg
(
kernel
,
4
,
sizeof
(
int
),
dims
+
2
);
clSetKernelArg
(
kernel
,
5
,
sizeof
(
int
),
dims
+
3
);
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
3
,
NULL
,
default_work_size
.
data
(),
NULL
,
0
,
NULL
,
NULL
);
}
template
class
SoftmaxKernel
<
GPU_CL
,
float
>;
template
class
SoftmaxKernel
<
GPU_CL
,
float
>;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录