Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
d9ed6f14
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看板
提交
d9ed6f14
编写于
10月 17, 2018
作者:
R
Ray Liu
提交者:
GitHub
10月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1114 from codeWorm2015/opencl
update cltensor
上级
47eee47b
e5fbd777
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
15 deletion
+64
-15
src/framework/cl/cl_image.cpp
src/framework/cl/cl_image.cpp
+2
-3
src/framework/cl/cl_tensor.h
src/framework/cl/cl_tensor.h
+44
-8
src/framework/executor.cpp
src/framework/executor.cpp
+3
-3
src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp
src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp
+13
-0
src/operators/kernel/cl/feed_kernel.cpp
src/operators/kernel/cl/feed_kernel.cpp
+2
-1
未找到文件。
src/framework/cl/cl_image.cpp
浏览文件 @
d9ed6f14
...
...
@@ -168,9 +168,8 @@ Print &operator<<(Print &printer, const CLImage &cl_image) {
i0
+=
width
*
H
;
}
if
(
err
!=
CL_SUCCESS
)
{
CL_CHECK_ERRORS
(
err
);
}
CL_CHECK_ERRORS
(
err
);
for
(
int
i
=
0
;
i
<
cl_image
.
numel
();
i
+=
stride
)
{
printer
<<
data
[
i
]
<<
" "
;
}
...
...
src/framework/cl/cl_tensor.h
浏览文件 @
d9ed6f14
...
...
@@ -28,7 +28,19 @@ namespace framework {
class
CLTensor
:
TensorBase
{
public:
explicit
CLTensor
(
cl_context
context
)
:
context_
(
context
)
{}
CLTensor
(
cl_context
context
,
cl_command_queue
command_queue
)
:
context_
(
context
),
command_queue_
(
command_queue
)
{}
CLTensor
()
=
default
;
/*
* if init method haven't set context and command_queue, need set
* */
void
SetContextAndCommandQueue
(
cl_context
context
,
cl_command_queue
command_queue
)
{
context_
=
context
;
command_queue_
=
command_queue
;
}
/*! Resize the dimensions of the memory block. */
inline
CLTensor
&
Resize
(
const
DDim
&
dims
)
{
...
...
@@ -39,7 +51,8 @@ class CLTensor : TensorBase {
template
<
typename
T
>
inline
T
mutable_with_data
(
void
*
data
)
{
int64_t
size
=
numel
()
*
sizeof
(
float
);
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
data
,
typeid
(
T
),
context_
));
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
data
,
typeid
(
T
),
context_
,
command_queue_
));
return
reinterpret_cast
<
T
>
(
reinterpret_cast
<
void
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())));
}
...
...
@@ -51,7 +64,7 @@ class CLTensor : TensorBase {
PADDLE_MOBILE_ENFORCE
(
numel
()
>=
0
,
"the Tensor's numel must >=0."
)
int64_t
size
=
numel
()
*
SizeOfType
(
type
);
if
(
holder_
==
nullptr
||
holder_
->
size
()
<
size
+
offset_
)
{
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
,
context_
));
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
,
context_
,
command_queue_
));
offset_
=
0
;
}
return
reinterpret_cast
<
void
*>
(
...
...
@@ -85,6 +98,7 @@ class CLTensor : TensorBase {
private:
cl_context
context_
;
cl_command_queue
command_queue_
;
/*
* virtual ~Placeholder() = default;
...
...
@@ -99,20 +113,31 @@ class CLTensor : TensorBase {
* */
struct
PlaceholderImpl
:
public
Placeholder
{
PlaceholderImpl
(
size_t
size
,
void
*
input
,
std
::
type_index
type
,
cl_context
context
)
cl_context
context
,
cl_command_queue
command_queue
)
:
ptr_
(
clCreateBuffer
(
context
,
CL_MEM_READ_ONLY
|
CL_MEM_COPY_HOST_PTR
,
size
,
reinterpret_cast
<
void
*>
(
input
),
NULL
)),
size_
(
size
),
type_
(
type
)
{}
type_
(
type
),
command_queue_
(
command_queue
)
{}
PlaceholderImpl
(
size_t
size
,
std
::
type_index
type
,
cl_context
context
)
PlaceholderImpl
(
size_t
size
,
std
::
type_index
type
,
cl_context
context
,
cl_command_queue
command_queue
)
:
ptr_
(
clCreateBuffer
(
context
,
CL_MEM_READ_WRITE
,
size
,
NULL
,
NULL
)),
size_
(
size
),
type_
(
type
)
{}
type_
(
type
),
command_queue_
(
command_queue
)
{}
virtual
size_t
size
()
const
{
return
size_
;
}
virtual
void
*
ptr
()
const
{
return
static_cast
<
void
*>
(
ptr_
.
get
());
}
virtual
void
*
ptr
()
const
{
if
(
host_ptr_
)
{
delete
(
host_ptr_
);
}
char
*
host_ptr
=
new
char
[
size_
];
clEnqueueReadBuffer
(
command_queue_
,
ptr_
.
get
(),
CL_TRUE
,
0
,
size_
,
host_ptr
,
0
,
NULL
,
NULL
);
return
static_cast
<
void
*>
(
host_ptr
);
}
virtual
std
::
type_index
type
()
const
{
return
type_
;
}
...
...
@@ -124,6 +149,17 @@ class CLTensor : TensorBase {
/* the current type of memory */
std
::
type_index
type_
;
cl_command_queue
command_queue_
;
~
PlaceholderImpl
()
{
if
(
host_ptr_
)
{
delete
(
host_ptr_
);
}
}
private:
void
*
host_ptr_
;
};
};
...
...
src/framework/executor.cpp
浏览文件 @
d9ed6f14
...
...
@@ -37,7 +37,7 @@ limitations under the License. */
#include "framework/cl/cl_image.h"
#endif
int
debug_to
=
3
;
int
debug_to
=
115
;
namespace
paddle_mobile
{
namespace
framework
{
...
...
@@ -87,7 +87,7 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size,
for
(
int
i
=
0
;
i
<
blocks
.
size
();
++
i
)
{
std
::
shared_ptr
<
framework
::
BlockDesc
>
block_desc
=
blocks
[
i
];
std
::
vector
<
std
::
shared_ptr
<
framework
::
OpDesc
>>
ops
=
block_desc
->
Ops
();
for
(
int
j
=
0
;
j
<
debug_to
;
++
j
)
{
for
(
int
j
=
0
;
j
<
ops
.
size
()
;
++
j
)
{
std
::
shared_ptr
<
framework
::
OpDesc
>
op
=
ops
[
j
];
DLOG
<<
"create op: "
<<
j
<<
" "
<<
op
->
Type
();
auto
op_base
=
framework
::
OpRegistry
<
Dtype
>::
CreateOp
(
...
...
@@ -416,7 +416,7 @@ std::shared_ptr<framework::Tensor> Executor<Dtype, P>::Predict(
}
}
#else
for
(
int
i
=
0
;
i
<
debug_to
;
i
++
)
{
for
(
int
i
=
0
;
i
<
ops
.
size
()
;
i
++
)
{
#ifdef PADDLE_MOBILE_PROFILE
struct
timespec
ts
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
...
...
src/operators/kernel/cl/conv_add_bn_relu_kernel.cpp
浏览文件 @
d9ed6f14
...
...
@@ -40,6 +40,11 @@ bool ConvAddBNReluKernel<GPU_CL, float>::Init(
const
framework
::
CLImage
*
scale
=
param
->
InputScale
();
const
framework
::
CLImage
*
bias
=
param
->
InputBias
();
const
float
epsilon
=
param
->
Epsilon
();
//
// DLOG << " climage mean: " << *mean;
// DLOG << " climage variance: " << *variance;
// DLOG << " climage scale: " << *scale;
// DLOG << " climage bias: " << *bias;
auto
mean_ptr
=
mean
->
data
<
float
>
();
auto
variance_ptr
=
variance
->
data
<
float
>
();
...
...
@@ -67,12 +72,20 @@ bool ConvAddBNReluKernel<GPU_CL, float>::Init(
new_scale
->
InitCLImage
(
this
->
cl_helper_
.
CLContext
(),
cl_helper_
.
CLCommandQueue
());
DLOG
<<
" climage - y bias: "
<<
*
(
param
->
Bias
());
DLOG
<<
" climage - new scale: "
<<
*
new_scale
;
framework
::
CLImage
*
new_bias
=
new
framework
::
CLImage
();
new_bias
->
SetTensorData
(
new_bias_ptr
,
variance
->
dims
());
new_bias
->
InitCLImage
(
this
->
cl_helper_
.
CLContext
(),
cl_helper_
.
CLCommandQueue
());
DLOG
<<
" climage - new bias: "
<<
*
new_bias
;
DLOG
<<
" climage - filter: "
<<
*
(
param
->
Filter
());
param
->
SetNewScale
(
new_scale
);
param
->
SetNewBias
(
new_bias
);
...
...
src/operators/kernel/cl/feed_kernel.cpp
浏览文件 @
d9ed6f14
...
...
@@ -36,7 +36,8 @@ void FeedKernel<GPU_CL, float>::Compute(const FeedParam<GPU_CL> ¶m) {
cl_mem
cl_image
=
output
->
GetCLImage
();
int
height
=
output
->
dims
()[
2
];
int
width
=
output
->
dims
()[
3
];
CLTensor
input_cl_tensor
(
this
->
cl_helper_
.
CLContext
());
CLTensor
input_cl_tensor
(
this
->
cl_helper_
.
CLContext
(),
this
->
cl_helper_
.
CLCommandQueue
());
input_cl_tensor
.
Resize
(
input
->
dims
());
cl_mem
inputBuffer
=
input_cl_tensor
.
mutable_with_data
<
cl_mem
>
((
void
*
)
input_data
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录