Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
7fbea0e2
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看板
提交
7fbea0e2
编写于
10月 15, 2018
作者:
Y
yangfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add some function
上级
49bce554
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
214 addition
and
184 deletion
+214
-184
src/framework/cl/cl_image.cpp
src/framework/cl/cl_image.cpp
+99
-102
src/framework/cl/cl_image.h
src/framework/cl/cl_image.h
+28
-10
src/framework/cl/cl_scope.h
src/framework/cl/cl_scope.h
+2
-1
src/framework/executor.cpp
src/framework/executor.cpp
+1
-1
src/framework/operator.cpp
src/framework/operator.cpp
+25
-13
src/operators/feed_op.h
src/operators/feed_op.h
+2
-2
src/operators/kernel/cl/cl_kernel/cl_common.h
src/operators/kernel/cl/cl_kernel/cl_common.h
+3
-3
src/operators/kernel/cl/depthwise_conv_kernel.cpp
src/operators/kernel/cl/depthwise_conv_kernel.cpp
+5
-4
src/operators/kernel/cl/feed_kernel.cpp
src/operators/kernel/cl/feed_kernel.cpp
+36
-35
src/operators/kernel/feed_kernel.h
src/operators/kernel/feed_kernel.h
+10
-10
src/operators/op_param.h
src/operators/op_param.h
+3
-3
未找到文件。
src/framework/cl/cl_image.cpp
浏览文件 @
7fbea0e2
...
...
@@ -14,20 +14,20 @@ limitations under the License. */
#include "cl_image.h"
namespace
paddle_mobile
{
namespace
framework
{
void
CLImageToTensor
(
CLImage
*
cl_image
,
Tensor
*
tensor
,
cl_command_queue
commandQueue
){
namespace
framework
{
void
CLImageToTensor
(
CLImage
*
cl_image
,
Tensor
*
tensor
,
cl_command_queue
commandQueue
)
{
DDim
ddim
=
cl_image
->
dims
();
size_t
N
,
C
,
H
,
W
;
if
(
ddim
.
size
()
==
4
)
{
size_t
N
,
C
,
H
,
W
;
if
(
ddim
.
size
()
==
4
)
{
N
=
ddim
[
0
];
if
(
N
<
0
)
{
if
(
N
<
0
)
{
N
=
1
;
}
C
=
ddim
[
1
];
H
=
ddim
[
2
];
W
=
ddim
[
3
];
}
else
if
(
ddim
.
size
()
==
1
)
{
}
else
if
(
ddim
.
size
()
==
1
)
{
N
=
1
;
C
=
ddim
[
0
];
H
=
1
;
...
...
@@ -41,15 +41,16 @@ namespace paddle_mobile {
half
imageData
[
width
*
height
*
4
];
cl_int
err
;
cl_mem
image
=
cl_image
->
GetCLImage
();
size_t
origin
[
3
]
=
{
0
,
0
,
0
};
size_t
region
[
3
]
=
{
width
,
height
,
1
};
err
=
clEnqueueReadImage
(
commandQueue
,
image
,
CL_TRUE
,
origin
,
region
,
0
,
0
,
imageData
,
0
,
NULL
,
NULL
);
size_t
origin
[
3
]
=
{
0
,
0
,
0
};
size_t
region
[
3
]
=
{
width
,
height
,
1
};
err
=
clEnqueueReadImage
(
commandQueue
,
image
,
CL_TRUE
,
origin
,
region
,
0
,
0
,
imageData
,
0
,
NULL
,
NULL
);
size_t
i0
=
0
;
for
(
int
n
=
0
;
n
<
N
;
n
++
)
{
for
(
int
c
=
0
;
c
<
C
;
c
++
)
{
size_t
i1
=
i0
;
for
(
int
h
=
0
;
h
<
H
;
h
++
)
{
size_t
i2
=
(
i1
<<
2
)
+
c
%
4
;
size_t
i2
=
(
i1
<<
2
)
+
c
%
4
;
for
(
int
w
=
0
;
w
<
W
;
w
++
)
{
*
p
=
half2float
(
imageData
[
i2
]);
i2
+=
4
;
...
...
@@ -61,25 +62,23 @@ namespace paddle_mobile {
i0
+=
width
*
H
;
}
if
(
err
!=
CL_SUCCESS
)
{
// TODO: error handling
}
}
void
TensorToCLImage
(
const
Tensor
*
tensor
,
CLImage
*
cl_image
,
cl_command_queue
commandQueue
){
}
void
TensorToCLImage
(
const
Tensor
*
tensor
,
CLImage
*
cl_image
,
cl_command_queue
commandQueue
)
{
DDim
ddim
=
cl_image
->
dims
();
size_t
N
,
C
,
H
,
W
;
if
(
ddim
.
size
()
==
4
)
{
size_t
N
,
C
,
H
,
W
;
if
(
ddim
.
size
()
==
4
)
{
N
=
ddim
[
0
];
if
(
N
<
0
)
{
if
(
N
<
0
)
{
N
=
1
;
}
C
=
ddim
[
1
];
H
=
ddim
[
2
];
W
=
ddim
[
3
];
}
else
if
(
ddim
.
size
()
==
1
)
{
}
else
if
(
ddim
.
size
()
==
1
)
{
N
=
1
;
C
=
ddim
[
0
];
H
=
1
;
...
...
@@ -92,10 +91,11 @@ namespace paddle_mobile {
const
float
*
p
=
tensor
->
data
<
float
>
();
half
imageData
[
width
*
height
*
4
];
cl_mem
image
=
cl_image
->
GetCLImage
();
size_t
origin
[
3
]
=
{
0
,
0
,
0
};
size_t
region
[
3
]
=
{
width
,
height
,
1
};
size_t
origin
[
3
]
=
{
0
,
0
,
0
};
size_t
region
[
3
]
=
{
width
,
height
,
1
};
cl_int
err
;
err
=
clEnqueueReadImage
(
commandQueue
,
image
,
CL_TRUE
,
origin
,
region
,
0
,
0
,
imageData
,
0
,
NULL
,
NULL
);
err
=
clEnqueueReadImage
(
commandQueue
,
image
,
CL_TRUE
,
origin
,
region
,
0
,
0
,
imageData
,
0
,
NULL
,
NULL
);
if
(
err
!=
CL_SUCCESS
)
{
// TODO: error handling
}
...
...
@@ -104,7 +104,7 @@ namespace paddle_mobile {
for
(
int
c
=
0
;
c
<
C
;
c
++
)
{
size_t
i1
=
i0
;
for
(
int
h
=
0
;
h
<
H
;
h
++
)
{
size_t
i2
=
(
i1
<<
2
)
+
c
%
4
;
size_t
i2
=
(
i1
<<
2
)
+
c
%
4
;
for
(
int
w
=
0
;
w
<
W
;
w
++
)
{
imageData
[
i2
]
=
float2half
(
*
p
);
i2
+=
4
;
...
...
@@ -115,9 +115,6 @@ namespace paddle_mobile {
}
i0
+=
width
*
H
;
}
}
}
}
}
// namespace framework
}
// namespace paddle_mobile
src/framework/cl/cl_image.h
浏览文件 @
7fbea0e2
...
...
@@ -30,6 +30,20 @@ class CLImage {
void
Init
(
cl_context
context
,
float
*
tensorInput
,
DDim
ddim
)
{
tensor_dims_
=
ddim
;
if
(
tensorInput
)
{
tensor_input_
=
tensorInput
;
}
else
{
int
numel
=
1
;
for
(
int
i
=
0
;
i
<
ddim
.
size
();
i
++
)
{
numel
*=
ddim
[
i
];
}
tensor_input_
=
static_cast
<
float
*>
(
paddle_mobile
::
memory
::
Alloc
(
sizeof
(
float
)
*
numel
));
for
(
int
i
=
0
;
i
<
numel
;
i
++
)
{
tensor_input_
[
i
]
=
0
;
}
}
cl_image_format
cf
=
{.
image_channel_order
=
CL_RGBA
,
.
image_channel_data_type
=
CL_HALF_FLOAT
};
// NCHW -> [W * (C+3)/4, H * N]
...
...
@@ -65,9 +79,9 @@ class CLImage {
std
::
unique_ptr
<
half_t
[]
>
imageData
{};
int
count
=
0
;
if
(
tensorInput
!=
nullptr
)
{
imageData
.
reset
(
new
half_t
[
width
*
height
*
4
]);
float
*
p
=
tensorInput
;
if
(
tensor_input_
!=
nullptr
)
{
float
*
p
=
tensor_input_
;
size_t
i0
=
0
;
for
(
int
n
=
0
;
n
<
N
;
n
++
)
{
for
(
int
c
=
0
;
c
<
C
;
c
++
)
{
...
...
@@ -75,11 +89,13 @@ class CLImage {
for
(
int
h
=
0
;
h
<
H
;
h
++
)
{
size_t
i2
=
(
i1
<<
2
)
+
c
%
4
;
for
(
int
w
=
0
;
w
<
W
;
w
++
)
{
if
(
i2
>=
width
*
height
*
4
)
{
printf
(
"%d > %d ----> %d, %d, %d, %d --- %d, %d, %d
\n
"
,
i2
,
width
*
height
*
4
,
n
,
c
,
h
,
w
,
i0
,
i1
,
i2
);
}
assert
(
i2
<
width
*
height
*
4
);
// if (i2 >= width * height * 4) {
// printf("%d > %d ----> %d, %d, %d, %d --- %d, %d,
// %d\n", i2,
// width * height * 4, n, c, h, w, i0, i1,
// i2);
// }
// assert(i2 < width * height * 4);
imageData
[
i2
]
=
float2half
(
*
p
);
i2
+=
4
;
...
...
@@ -153,9 +169,11 @@ class CLImage {
cl_context
context_
;
};
void
TensorToCLImage
(
Tensor
*
tensor
,
CLImage
*
image
);
void
TensorToCLImage
(
Tensor
*
tensor
,
CLImage
*
image
,
cl_command_queue
commandQueue
);
void
CLImageToTensor
(
CLImage
*
image
,
Tensor
*
tensor
);
void
CLImageToTensor
(
CLImage
*
image
,
Tensor
*
tensor
,
cl_command_queue
commandQueue
);
}
// namespace framework
}
// namespace paddle_mobile
src/framework/cl/cl_scope.h
浏览文件 @
7fbea0e2
...
...
@@ -56,7 +56,8 @@ class CLScope {
auto
program
=
CLEngine
::
Instance
()
->
CreateProgramWith
(
context_
.
get
(),
"./cl_kernel/"
+
file_name
);
status_
=
clBuildProgram
(
program
.
get
(),
0
,
0
,
"-cl-fast-relaxed-math"
,
0
,
0
);
status_
=
clBuildProgram
(
program
.
get
(),
0
,
0
,
"-cl-fast-relaxed-math"
,
0
,
0
);
CL_CHECK_ERRORS
(
status_
);
programs_
[
file_name
]
=
std
::
move
(
program
);
...
...
src/framework/executor.cpp
浏览文件 @
7fbea0e2
...
...
@@ -931,7 +931,7 @@ void Executor<GPU_CL, Precision::FP32>::InitMemory() {
cl_image
->
Init
(
context
,
tensorInput
,
ddim
);
delete
origin_data
;
paddle_mobile
::
memory
::
Free
(
tensorInput
);
//
paddle_mobile::memory::Free(tensorInput);
}
else
{
if
(
var_desc
->
Type
()
==
framework
::
VARTYPE_TYPE_LOD_TENSOR
)
{
auto
cl_image
=
var
->
template
GetMutable
<
framework
::
CLImage
>();
...
...
src/framework/operator.cpp
浏览文件 @
7fbea0e2
...
...
@@ -73,12 +73,15 @@ void OperatorBase<Dtype>::Run() {
}
else
{
CLImage
*
cl_image
=
vari
->
template
GetMutable
<
framework
::
CLImage
>();
// cl_command_queue commandQueue =
// scope_->GetCLScpoe()->CommandQueue(); Tensor *tmp ;
// scope_->GetCLScpoe()->CommandQueue(); Tensor
// *tmp ;
// CLImageToTensor(cl_image,tmp,commandQueue);
// tmp->Resize(cl_image->dims());
const
float
*
input
=
cl_image
->
data
<
float
>
();
if
(
cl_image
)
{
// DLOG<<type_<<" input- "<<key<<"="<<*tmp;
DLOG
<<
type_
<<
" input- "
<<
key
<<
"="
<<
cl_image
->
dims
();
// if(input)
// DLOG<<type_<<" input- "<<key<<"="<<*input;
}
}
...
...
@@ -95,15 +98,24 @@ void OperatorBase<Dtype>::Run() {
auto
vari
=
scope_
->
FindVar
(
var_vec_out
[
i
]);
if
(
vari
->
IsInitialized
())
{
#ifdef PADDLE_MOBILE_CL
if
(
type_
==
"fetch"
)
{
Tensor
*
tensor
=
vari
->
template
GetMutable
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
tensor
->
dims
();
}
else
{
CLImage
*
cl_image
=
vari
->
template
GetMutable
<
framework
::
CLImage
>();
// cl_command_queue commandQueue =
// scope_->GetCLScpoe()->CommandQueue(); Tensor *tmp ;
// CLImageToTensor(cl_image,tmp,commandQueue);
// tmp->Resize(cl_image->dims());
if
(
cl_image
)
{
// DLOG<<type_<<" output- "<<key<<"="<<*tmp
;
const
float
*
output
=
cl_image
->
data
<
float
>
()
;
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
cl_image
->
dims
();
// if(output)
// DLOG<<type_<<" output- "<<key<<"="<<*output;
}
}
#else
Tensor
*
tensor
=
vari
->
template
GetMutable
<
framework
::
LoDTensor
>();
if
(
tensor
)
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
*
tensor
;
...
...
src/operators/feed_op.h
浏览文件 @
7fbea0e2
src/operators/kernel/cl/cl_kernel/cl_common.h
浏览文件 @
7fbea0e2
...
...
@@ -18,9 +18,10 @@ limitations under the License. */
inline
hafl4
activation
(
half4
in
#ifdef PRELU
,
half4
prelu_alpha
,
half4
prelu_alpha
#endif
)
{
)
{
half4
output
;
#ifdef PRELU
output
=
select
(
prelu_alpha
*
in
,
in
,
in
>=
(
half4
)
0
.
0
);
...
...
@@ -31,4 +32,3 @@ inline hafl4 activation(half4 in
#endif
return
output
;
}
src/operators/kernel/cl/depthwise_conv_kernel.cpp
浏览文件 @
7fbea0e2
...
...
@@ -36,7 +36,8 @@ bool DepthwiseConvKernel<GPU_CL, float>::Init(ConvParam<GPU_CL> *param) {
}
template
<
>
void
DepthwiseConvKernel
<
GPU_CL
,
float
>::
Compute
(
const
ConvParam
<
GPU_CL
>
&
param
)
{
void
DepthwiseConvKernel
<
GPU_CL
,
float
>::
Compute
(
const
ConvParam
<
GPU_CL
>
&
param
)
{
auto
kernel
=
this
->
cl_helper_
.
KernelAt
(
0
);
auto
default_work_size
=
this
->
cl_helper_
.
DefaultWorkSize
(
*
param
.
Output
());
int
c_block
=
default_work_size
[
0
];
...
...
src/operators/kernel/cl/feed_kernel.cpp
浏览文件 @
7fbea0e2
...
...
@@ -12,42 +12,43 @@ 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. */
#include "common/log.h"
#include "operators/kernel/feed_kernel.h"
#include "common/log.h"
namespace
paddle_mobile
{
namespace
operators
{
namespace
operators
{
template
<
>
bool
FeedKernel
<
GPU_CL
,
float
>::
Init
(
FeedParam
<
GPU_CL
>
*
param
)
{
DLOG
<<
"Init feed"
;
template
<
>
bool
FeedKernel
<
GPU_CL
,
float
>::
Init
(
FeedParam
<
GPU_CL
>
*
param
)
{
DLOG
<<
"Init feed"
;
this
->
cl_helper_
.
AddKernel
(
"feed"
,
"feed_kernel.cl"
);
return
true
;
}
template
<
>
void
FeedKernel
<
GPU_CL
,
float
>::
Compute
(
const
FeedParam
<
GPU_CL
>
&
param
)
{
}
DLOG
<<
"feed_kernel"
;
template
<
>
void
FeedKernel
<
GPU_CL
,
float
>::
Compute
(
const
FeedParam
<
GPU_CL
>
&
param
)
{
auto
kernel
=
this
->
cl_helper_
.
KernelAt
(
0
);
cl_int
status
;
auto
output
=
param
.
Out
();
auto
input
=
param
.
InputX
();
const
float
*
input_data
=
input
->
data
<
float
>
();
const
Tensor
*
input
=
param
.
InputX
();
const
float
*
input_data
=
nullptr
;
input_data
=
input
->
data
<
float
>
();
cl_mem
cl_image
=
output
->
GetCLImage
();
int
height
=
output
->
dims
()[
2
];
int
width
=
output
->
dims
()[
3
];
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
input_data
);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
cl_image
);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
width
);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
height
);
DLOG
<<
output
->
dims
();
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
input_data
);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
cl_image
);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
width
);
status
=
clSetKernelArg
(
kernel
,
0
,
sizeof
(
cl_mem
),
&
height
);
size_t
global_work_size
[
2
]
=
{
height
,
width
};
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
}
size_t
global_work_size
[
2
]
=
{
height
,
width
};
clEnqueueNDRangeKernel
(
this
->
cl_helper_
.
CLCommandQueue
(),
kernel
,
2
,
NULL
,
global_work_size
,
NULL
,
0
,
NULL
,
NULL
);
}
template
class
FeedKernel
<
GPU_CL
,
float
>;
template
class
FeedKernel
<
GPU_CL
,
float
>;
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
src/operators/kernel/feed_kernel.h
浏览文件 @
7fbea0e2
...
...
@@ -18,15 +18,15 @@ limitations under the License. */
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
FeedKernel
:
public
framework
::
OpKernelBase
<
DeviceType
,
FeedParam
<
DeviceType
>>
{
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
FeedKernel
:
public
framework
::
OpKernelBase
<
DeviceType
,
FeedParam
<
DeviceType
>>
{
public:
void
Compute
(
const
FeedParam
<
DeviceType
>
&
param
);
bool
Init
(
FeedParam
<
DeviceType
>
*
param
);
};
};
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
src/operators/op_param.h
浏览文件 @
7fbea0e2
...
...
@@ -936,14 +936,14 @@ class FetchParam : public OpParam {
FetchParam
(
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
AttributeMap
&
attrs
,
const
Scope
&
scope
)
{
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
out_
=
OutFrom
<
GType
>
(
outputs
,
scope
);
out_
=
OutFrom
<
LoDTensor
>
(
outputs
,
scope
);
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
RType
*
Out
()
const
{
return
out_
;
}
Tensor
*
Out
()
const
{
return
out_
;
}
private:
RType
*
input_x_
;
RType
*
out_
;
Tensor
*
out_
;
};
#ifdef TRANSPOSE_OP
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录