Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5e100325
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看板
提交
5e100325
编写于
3月 15, 2019
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add opencl outer interface by jiaying
modify pridecttime judge
上级
a0713b7b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
80 addition
and
23 deletion
+80
-23
src/io/opencl_interface.cpp
src/io/opencl_interface.cpp
+33
-0
src/io/opencl_interface.h
src/io/opencl_interface.h
+25
-0
src/io/paddle_mobile.cpp
src/io/paddle_mobile.cpp
+22
-23
未找到文件。
src/io/opencl_interface.cpp
0 → 100644
浏览文件 @
5e100325
/* 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. */
#include "io/opencl_interface.h"
#include "framework/cl/cl_engine.h"
#include "framework/cl/cl_scope.h"
namespace
paddle_mobile
{
cl_context
getContext
()
{
return
framework
::
CLEngine
::
Instance
()
->
getContext
();
}
cl_command_queue
getClCommandQueue
()
{
return
framework
::
CLEngine
::
Instance
()
->
getClCommandQueue
();
}
bool
isInitSuccess
()
{
return
framework
::
CLEngine
::
Instance
()
->
isInitSuccess
();
}
}
// namespace paddle_mobile
src/io/opencl_interface.h
0 → 100644
浏览文件 @
5e100325
/* 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 once
#include "CL/cl.h"
namespace
paddle_mobile
{
cl_context
getContext
();
cl_command_queue
getClCommandQueue
();
bool
isInitSuccess
();
}
// namespace paddle_mobile
src/io/paddle_mobile.cpp
浏览文件 @
5e100325
...
...
@@ -20,6 +20,8 @@ limitations under the License. */
#endif // _OPENMP
#ifdef PADDLE_MOBILE_CL
#include <CL/cl.h>
#include <mutex>
#include "framework/cl/cl_engine.h"
#include "framework/cl/cl_tensor.h"
#endif
#include "operators/math/gemm.h"
...
...
@@ -202,11 +204,15 @@ double PaddleMobile<CPU, float>::GetPredictTime() {
operators
::
math
::
Gemm
gemm
;
auto
time1
=
paddle_mobile
::
time
();
gemm
.
Sgemm
(
m
,
n
,
k
,
static_cast
<
float
>
(
1
),
a
,
lda
,
b
,
ldb
,
static_cast
<
float
>
(
0
),
c
,
ldc
,
false
,
static_cast
<
float
*>
(
nullptr
));
int
times
=
4
;
for
(
int
j
=
0
;
j
<
times
;
++
j
)
{
gemm
.
Sgemm
(
m
,
n
,
k
,
static_cast
<
float
>
(
1
),
a
,
lda
,
b
,
ldb
,
static_cast
<
float
>
(
0
),
c
,
ldc
,
false
,
static_cast
<
float
*>
(
nullptr
));
}
auto
time2
=
paddle_mobile
::
time
();
double
cost
=
paddle_mobile
::
time_diff
(
time1
,
time2
);
double
cost
=
paddle_mobile
::
time_diff
(
time1
,
time2
)
/
times
;
paddle_mobile
::
memory
::
Free
(
a
);
paddle_mobile
::
memory
::
Free
(
b
);
paddle_mobile
::
memory
::
Free
(
c
);
...
...
@@ -282,21 +288,11 @@ void PaddleMobile<Device, T>::SetCLPath(std::string path) {
template
<
>
double
PaddleMobile
<
GPU_CL
,
float
>::
GetPredictTime
()
{
cl_int
status
;
cl_uint
nPlatform
;
clGetPlatformIDs
(
0
,
NULL
,
&
nPlatform
);
cl_platform_id
*
listPlatform
=
reinterpret_cast
<
cl_platform_id
*>
(
malloc
(
nPlatform
*
sizeof
(
cl_platform_id
)));
clGetPlatformIDs
(
nPlatform
,
listPlatform
,
NULL
);
cl_uint
nDevice
=
0
;
clGetDeviceIDs
(
listPlatform
[
0
],
CL_DEVICE_TYPE_GPU
,
0
,
NULL
,
&
nDevice
);
cl_device_id
*
listDevice
=
reinterpret_cast
<
cl_device_id
*>
(
malloc
(
nDevice
*
sizeof
(
cl_device_id
)));
clGetDeviceIDs
(
listPlatform
[
0
],
CL_DEVICE_TYPE_GPU
,
nDevice
,
listDevice
,
NULL
);
cl_context
context
=
clCreateContext
(
NULL
,
nDevice
,
listDevice
,
NULL
,
NULL
,
&
status
);
cl_command_queue
queue
=
clCreateCommandQueue
(
context
,
listDevice
[
0
],
0
,
&
status
);
if
(
!
framework
::
CLEngine
::
Instance
()
->
isInitSuccess
())
{
return
-
1
;
}
cl_context
context
=
framework
::
CLEngine
::
Instance
()
->
getContext
();
cl_command_queue
queue
=
framework
::
CLEngine
::
Instance
()
->
getClCommandQueue
();
int
n
=
1
;
int
c
=
3
;
...
...
@@ -410,7 +406,7 @@ double PaddleMobile<GPU_CL, float>::GetPredictTime() {
CL_CHECK_ERRORS
(
status
);
clFinish
(
queue
);
queue
=
clCreateCommandQueue
(
context
,
listDevice
[
0
],
0
,
&
status
);
//
queue = clCreateCommandQueue(context, listDevice[0], 0, &status);
path
=
framework
::
CLEngine
::
Instance
()
->
GetCLPath
()
+
"/cl_kernel/conv_kernel.cl"
;
...
...
@@ -465,15 +461,18 @@ double PaddleMobile<GPU_CL, float>::GetPredictTime() {
// cl_event wait_event = param.Input()->GetClEvent();
size_t
global_work_size2
[
3
]
=
{
8
,
224
,
224
};
auto
time1
=
paddle_mobile
::
time
();
status
=
clEnqueueNDRangeKernel
(
queue
,
kernel
,
3
,
NULL
,
global_work_size2
,
NULL
,
0
,
NULL
,
NULL
);
int
times
=
10
;
for
(
int
i
=
0
;
i
<
times
;
++
i
)
{
status
=
clEnqueueNDRangeKernel
(
queue
,
kernel
,
3
,
NULL
,
global_work_size2
,
NULL
,
0
,
NULL
,
NULL
);
}
CL_CHECK_ERRORS
(
status
);
clFinish
(
queue
);
auto
time2
=
paddle_mobile
::
time
();
paddle_mobile
::
memory
::
Free
(
input
);
paddle_mobile
::
memory
::
Free
(
filter
);
if
(
status
==
CL_SUCCESS
)
{
return
paddle_mobile
::
time_diff
(
time1
,
time2
);
return
paddle_mobile
::
time_diff
(
time1
,
time2
)
/
times
;
}
else
{
return
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录