Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
b0d37e56
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看板
提交
b0d37e56
编写于
9月 28, 2018
作者:
R
Ray Liu
提交者:
GitHub
9月 28, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1021 from codeWorm2015/opencl
update cl engineC
上级
1bd2a695
ab677b54
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
41 addition
and
41 deletion
+41
-41
src/framework/cl/cl_engine.cpp
src/framework/cl/cl_engine.cpp
+16
-15
src/framework/cl/cl_engine.h
src/framework/cl/cl_engine.h
+24
-25
src/framework/scope.h
src/framework/scope.h
+1
-1
未找到文件。
src/framework/cl/cl_engine.cpp
浏览文件 @
b0d37e56
...
@@ -26,12 +26,13 @@ bool CLEngine::Init() {
...
@@ -26,12 +26,13 @@ bool CLEngine::Init() {
cl_int
status
;
cl_int
status
;
SetPlatform
();
SetPlatform
();
SetClDeviceId
();
SetClDeviceId
();
initialized_
=
true
;
// setClContext();
// setClContext();
// setClCommandQueue();
// setClCommandQueue();
// std::string filename = "./HelloWorld_Kernel.cl";
// std::string filename = "./HelloWorld_Kernel.cl";
// loadKernelFromFile(filename.c_str());
// loadKernelFromFile(filename.c_str());
// buildProgram();
// buildProgram();
initialized_
=
true
;
}
}
CLEngine
*
CLEngine
::
Instance
()
{
CLEngine
*
CLEngine
::
Instance
()
{
...
@@ -39,20 +40,6 @@ CLEngine *CLEngine::Instance() {
...
@@ -39,20 +40,6 @@ CLEngine *CLEngine::Instance() {
return
&
cl_engine_
;
return
&
cl_engine_
;
}
}
//std::unique_ptr<_cl_kernel, clKernel_deleter> CLEngine::GSetKernel(
// const std::string &kernel_name) {
// std::unique_ptr<_cl_kernel, clKernel_deleter> kernel(
// clCreateKernel(program_.get(), kernel_name.c_str(), NULL));
// return std::move(kernel);
//}
//
//bool CLEngine::SetClCommandQueue() {
// cl_int status;
// command_queue_.reset(
// clCreateCommandQueue(context_.get(), devices_[0], 0, &status));
// return true;
//}
bool
CLEngine
::
SetPlatform
()
{
bool
CLEngine
::
SetPlatform
()
{
platform_
=
NULL
;
// the chosen platform
platform_
=
NULL
;
// the chosen platform
cl_uint
numPlatforms
;
// the NO. of platforms
cl_uint
numPlatforms
;
// the NO. of platforms
...
@@ -87,6 +74,20 @@ bool CLEngine::SetClDeviceId() {
...
@@ -87,6 +74,20 @@ bool CLEngine::SetClDeviceId() {
return
false
;
return
false
;
}
}
//std::unique_ptr<_cl_kernel, clKernel_deleter> CLEngine::GSetKernel(
// const std::string &kernel_name) {
// std::unique_ptr<_cl_kernel, clKernel_deleter> kernel(
// clCreateKernel(program_.get(), kernel_name.c_str(), NULL));
// return std::move(kernel);
//}
//
//bool CLEngine::SetClCommandQueue() {
// cl_int status;
// command_queue_.reset(
// clCreateCommandQueue(context_.get(), devices_[0], 0, &status));
// return true;
//}
//bool CLEngine::SetClContext() {
//bool CLEngine::SetClContext() {
// context_.reset(clCreateContext(NULL, 1, devices_, NULL, NULL, NULL));
// context_.reset(clCreateContext(NULL, 1, devices_, NULL, NULL, NULL));
// return true;
// return true;
...
...
src/framework/cl/cl_engine.h
浏览文件 @
b0d37e56
...
@@ -16,7 +16,6 @@ limitations under the License. */
...
@@ -16,7 +16,6 @@ limitations under the License. */
#include <memory>
#include <memory>
#include <string>
#include <string>
#include <fstream>
#include "common/enforce.h"
#include "common/enforce.h"
#include "framework/cl/cl_deleter.h"
#include "framework/cl/cl_deleter.h"
...
@@ -45,25 +44,23 @@ class CLEngine {
...
@@ -45,25 +44,23 @@ class CLEngine {
}
}
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
CreateProgramWith
(
cl_context
context
,
std
::
string
file_name
)
{
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
CreateProgramWith
(
cl_context
context
,
std
::
string
file_name
)
{
const
char
*
kernel_file
=
file_name
.
c_str
();
size_t
size
;
char
*
str
;
std
::
fstream
f
(
kernel_file
,
(
std
::
fstream
::
in
|
std
::
fstream
::
binary
));
PADDLE_MOBILE_ENFORCE
(
f
.
is_open
(),
" file open failed"
)
size_t
fileSize
;
FILE
*
file
=
fopen
(
file_name
.
c_str
(),
"rb"
);
f
.
seekg
(
0
,
std
::
fstream
::
end
);
PADDLE_MOBILE_ENFORCE
(
file
!=
nullptr
,
"can't open file: %s "
,
size
=
fileSize
=
(
size_t
)
f
.
tellg
();
filename
.
c_str
());
f
.
seekg
(
0
,
std
::
fstream
::
beg
);
fseek
(
file
,
0
,
SEEK_END
);
str
=
new
char
[
size
+
1
];
int64_t
size
=
ftell
(
file
);
PADDLE_MOBILE_ENFORCE
(
size
>
0
,
"size is too small"
);
PADDLE_MOBILE_ENFORCE
(
str
!=
NULL
,
" str null"
)
rewind
(
file
);
char
*
data
=
new
char
[
size
+
1
];
f
.
read
(
str
,
fileSize
);
size_t
bytes_read
=
fread
(
data
,
1
,
size
,
file
);
f
.
close
();
data
[
size
]
=
'\0'
;
str
[
size
]
=
'\0'
;
PADDLE_MOBILE_ENFORCE
(
bytes_read
==
size
,
const
char
*
source
=
str
;
"read binary file bytes do not match with fseek"
);
fclose
(
file
);
const
char
*
source
=
data
;
size_t
sourceSize
[]
=
{
strlen
(
source
)};
size_t
sourceSize
[]
=
{
strlen
(
source
)};
cl_program
p
=
clCreateProgramWithSource
(
context
,
1
,
&
source
,
sourceSize
,
NULL
);
cl_program
p
=
clCreateProgramWithSource
(
context
,
1
,
&
source
,
sourceSize
,
NULL
);
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
program_ptr
(
p
);
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
program_ptr
(
p
);
...
@@ -84,13 +81,6 @@ class CLEngine {
...
@@ -84,13 +81,6 @@ class CLEngine {
bool
SetClDeviceId
();
bool
SetClDeviceId
();
// bool SetClContext();
// bool SetClCommandQueue();
// bool LoadKernelFromFile(const char *kernel_file);
// bool BuildProgram();
bool
initialized_
;
bool
initialized_
;
...
@@ -103,6 +93,15 @@ class CLEngine {
...
@@ -103,6 +93,15 @@ class CLEngine {
std
::
unique_ptr
<
_cl_command_queue
,
CLCommQueueDeleter
>
command_queue_
;
std
::
unique_ptr
<
_cl_command_queue
,
CLCommQueueDeleter
>
command_queue_
;
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
program_
;
std
::
unique_ptr
<
_cl_program
,
CLProgramDeleter
>
program_
;
// bool SetClContext();
// bool SetClCommandQueue();
// bool LoadKernelFromFile(const char *kernel_file);
// bool BuildProgram();
};
};
}
// namespace framework
}
// namespace framework
...
...
src/framework/scope.h
浏览文件 @
b0d37e56
...
@@ -93,7 +93,7 @@ class Scope {
...
@@ -93,7 +93,7 @@ class Scope {
mutable
std
::
unordered_map
<
std
::
string
,
Variable
*>
vars_
;
mutable
std
::
unordered_map
<
std
::
string
,
Variable
*>
vars_
;
mutable
std
::
list
<
Scope
*>
kids_
;
mutable
std
::
list
<
Scope
*>
kids_
;
Scope
const
*
parent_
{
nullptr
};
Scope
const
*
parent_
{
nullptr
};
//#ifdef PADDLE_MOBILE_
O
CL
//#ifdef PADDLE_MOBILE_CL
CLScope
*
cl_scope_
=
new
CLScope
();
CLScope
*
cl_scope_
=
new
CLScope
();
//#endif
//#endif
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录