Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a0713b7b
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看板
提交
a0713b7b
编写于
3月 14, 2019
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add init check interface
上级
76ca8f8b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
18 deletion
+43
-18
src/framework/cl/cl_engine.cpp
src/framework/cl/cl_engine.cpp
+14
-9
src/framework/cl/cl_engine.h
src/framework/cl/cl_engine.h
+21
-1
src/framework/cl/cl_scope.h
src/framework/cl/cl_scope.h
+8
-8
未找到文件。
src/framework/cl/cl_engine.cpp
浏览文件 @
a0713b7b
...
...
@@ -27,9 +27,9 @@ bool CLEngine::Init() {
return
true
;
}
cl_int
status
;
SetPlatform
();
SetClDeviceId
();
bool
is_setplatform_success
=
SetPlatform
();
bool
is_setcldeviceid_success
=
SetClDeviceId
();
is_init_success_
=
is_setplatform_success
&&
is_setcldeviceid_success
;
initialized_
=
true
;
return
initialized_
;
// setClCommandQueue();
...
...
@@ -44,11 +44,14 @@ CLEngine *CLEngine::Instance() {
return
&
cl_engine_
;
}
bool
CLEngine
::
isInitSuccess
()
{
return
is_init_success_
;
}
bool
CLEngine
::
SetPlatform
()
{
platform_
=
NULL
;
// the chosen platform
cl_uint
numPlatforms
;
// the NO. of platforms
cl_int
status
=
clGetPlatformIDs
(
0
,
NULL
,
&
numPlatforms
);
if
(
status
!=
CL_SUCCESS
)
{
return
false
;
}
/**For clarity, choose the first available platform. */
if
(
numPlatforms
>
0
)
{
cl_platform_id
*
platforms
=
reinterpret_cast
<
cl_platform_id
*>
(
...
...
@@ -56,10 +59,10 @@ bool CLEngine::SetPlatform() {
status
=
clGetPlatformIDs
(
numPlatforms
,
platforms
,
NULL
);
platform_
=
platforms
[
0
];
free
(
platforms
);
return
true
;
}
else
{
return
false
;
return
status
==
CL_SUCCESS
;
}
return
false
;
}
bool
CLEngine
::
SetClDeviceId
()
{
...
...
@@ -67,13 +70,15 @@ bool CLEngine::SetClDeviceId() {
devices_
=
NULL
;
cl_int
status
=
clGetDeviceIDs
(
platform_
,
CL_DEVICE_TYPE_GPU
,
0
,
NULL
,
&
numDevices
);
if
(
status
!=
CL_SUCCESS
)
{
return
false
;
}
if
(
numDevices
>
0
)
{
devices_
=
reinterpret_cast
<
cl_device_id
*>
(
malloc
(
numDevices
*
sizeof
(
cl_device_id
)));
status
=
clGetDeviceIDs
(
platform_
,
CL_DEVICE_TYPE_GPU
,
numDevices
,
devices_
,
NULL
);
return
true
;
return
status
==
CL_SUCCESS
;
}
return
false
;
}
...
...
src/framework/cl/cl_engine.h
浏览文件 @
a0713b7b
...
...
@@ -31,7 +31,7 @@ class CLEngine {
static
CLEngine
*
Instance
();
bool
Init
();
bool
isInitSuccess
();
std
::
unique_ptr
<
_cl_context
,
CLContextDeleter
>
CreateContext
()
{
cl_int
status
;
cl_context
c
=
clCreateContext
(
NULL
,
1
,
devices_
,
NULL
,
NULL
,
&
status
);
...
...
@@ -51,6 +51,20 @@ class CLEngine {
return
std
::
move
(
command_queue_ptr
);
}
cl_context
getContext
()
{
if
(
context_
==
nullptr
)
{
context_
=
CreateContext
();
}
return
context_
.
get
();
}
cl_command_queue
getClCommandQueue
()
{
if
(
command_queue_
==
nullptr
)
{
command_queue_
=
CreateClCommandQueue
(
getContext
());
}
return
command_queue_
.
get
();
}
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
CreateProgramWith
(
cl_context
context
,
std
::
string
file_name
)
{
FILE
*
file
=
fopen
(
file_name
.
c_str
(),
"rb"
);
...
...
@@ -137,6 +151,11 @@ class CLEngine {
std
::
string
cl_path_
;
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
program_
;
std
::
unique_ptr
<
_cl_context
,
CLContextDeleter
>
context_
=
nullptr
;
std
::
unique_ptr
<
_cl_command_queue
,
CLCommQueueDeleter
>
command_queue_
=
nullptr
;
// bool SetClContext();
// bool SetClCommandQueue();
...
...
@@ -144,6 +163,7 @@ class CLEngine {
// bool LoadKernelFromFile(const char *kernel_file);
// bool BuildProgram();
bool
is_init_success_
=
false
;
};
}
// namespace framework
...
...
src/framework/cl/cl_scope.h
浏览文件 @
a0713b7b
...
...
@@ -29,12 +29,12 @@ namespace framework {
class
CLScope
{
public:
CLScope
()
{
CLEngine
*
engin
=
CLEngine
::
Instance
();
context_
=
engin
->
Create
Context
();
command_queue_
=
engin
->
CreateClCommandQueue
(
context_
.
get
()
);
CLEngine
*
engin
e
=
CLEngine
::
Instance
();
context_
=
engin
e
->
get
Context
();
command_queue_
=
engin
e
->
getClCommandQueue
(
);
}
cl_command_queue
CommandQueue
()
{
return
command_queue_
.
get
()
;
}
cl_command_queue
CommandQueue
()
{
return
command_queue_
;
}
std
::
unique_ptr
<
_cl_kernel
,
CLKernelDeleter
>
GetKernel
(
const
std
::
string
&
kernel_name
,
const
std
::
string
&
file_name
)
{
...
...
@@ -49,7 +49,7 @@ class CLScope {
return
std
::
move
(
kernel
);
}
cl_context
Context
()
{
return
context_
.
get
()
;
}
cl_context
Context
()
{
return
context_
;
}
cl_program
Program
(
const
std
::
string
&
file_name
)
{
auto
it
=
programs_
.
find
(
file_name
);
...
...
@@ -58,7 +58,7 @@ class CLScope {
}
auto
program
=
CLEngine
::
Instance
()
->
CreateProgramWith
(
context_
.
get
()
,
context_
,
CLEngine
::
Instance
()
->
GetCLPath
()
+
"/cl_kernel/"
+
file_name
);
DLOG
<<
" --- begin build program -> "
<<
file_name
<<
" --- "
;
...
...
@@ -72,8 +72,8 @@ class CLScope {
private:
cl_int
status_
;
std
::
unique_ptr
<
_cl_context
,
CLContextDeleter
>
context_
;
std
::
unique_ptr
<
_cl_command_queue
,
CLCommQueueDeleter
>
command_queue_
;
cl_context
context_
;
cl_command_queue
command_queue_
;
std
::
unordered_map
<
std
::
string
,
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>>
programs_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录