Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
549ebc0a
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
未验证
提交
549ebc0a
编写于
7月 29, 2019
作者:
Y
Yanzhan Yang
提交者:
GitHub
7月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
restore fetch utility for opencl (#1770)
上级
ff4fb9b2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
71 addition
and
0 deletion
+71
-0
src/framework/executor.cpp
src/framework/executor.cpp
+14
-0
src/framework/executor.h
src/framework/executor.h
+3
-0
src/io/paddle_mobile.cpp
src/io/paddle_mobile.cpp
+8
-0
src/io/paddle_mobile.h
src/io/paddle_mobile.h
+3
-0
test/net/test_net.cpp
test/net/test_net.cpp
+39
-0
test/test_include.h
test/test_include.h
+4
-0
未找到文件。
src/framework/executor.cpp
浏览文件 @
549ebc0a
...
@@ -460,6 +460,20 @@ std::shared_ptr<LoDTensor> Executor<Device, T>::GetOutput(
...
@@ -460,6 +460,20 @@ std::shared_ptr<LoDTensor> Executor<Device, T>::GetOutput(
}
}
}
}
#ifdef PADDLE_MOBILE_CL
template
<
typename
Device
,
typename
T
>
const
CLImage
*
Executor
<
Device
,
T
>::
GetOutputImage
(
const
std
::
string
&
var_name
)
{
auto
var
=
program_
.
scope
->
FindVar
(
var_name
);
if
(
var
->
IsInitialized
()
&&
var
->
template
IsType
<
framework
::
CLImage
>())
{
const
CLImage
*
cl_image
=
var
->
template
Get
<
framework
::
CLImage
>();
return
cl_image
;
}
else
{
return
nullptr
;
}
}
#endif
template
<
typename
Device
,
typename
T
>
template
<
typename
Device
,
typename
T
>
PMStatus
Executor
<
Device
,
T
>::
Predict
()
{
PMStatus
Executor
<
Device
,
T
>::
Predict
()
{
#if _OPENMP
#if _OPENMP
...
...
src/framework/executor.h
浏览文件 @
549ebc0a
...
@@ -53,6 +53,9 @@ class Executor {
...
@@ -53,6 +53,9 @@ class Executor {
void
SetInput
(
const
LoDTensor
&
input
,
const
std
::
string
&
var_name
);
void
SetInput
(
const
LoDTensor
&
input
,
const
std
::
string
&
var_name
);
std
::
shared_ptr
<
LoDTensor
>
GetOutput
(
const
std
::
string
&
var_name
);
std
::
shared_ptr
<
LoDTensor
>
GetOutput
(
const
std
::
string
&
var_name
);
#ifdef PADDLE_MOBILE_CL
const
CLImage
*
GetOutputImage
(
const
std
::
string
&
var_name
);
#endif
void
FeedTensorData
(
const
std
::
vector
<
framework
::
Tensor
>
&
v
);
void
FeedTensorData
(
const
std
::
vector
<
framework
::
Tensor
>
&
v
);
void
GetTensorResults
(
std
::
vector
<
framework
::
Tensor
*>
*
v
);
void
GetTensorResults
(
std
::
vector
<
framework
::
Tensor
*>
*
v
);
...
...
src/io/paddle_mobile.cpp
浏览文件 @
549ebc0a
...
@@ -170,6 +170,14 @@ LoDTensorPtr PaddleMobile<Device, T>::Fetch(const std::string &var_name) {
...
@@ -170,6 +170,14 @@ LoDTensorPtr PaddleMobile<Device, T>::Fetch(const std::string &var_name) {
return
executor_
->
GetOutput
(
var_name
);
return
executor_
->
GetOutput
(
var_name
);
}
}
#ifdef PADDLE_MOBILE_CL
template
<
typename
Device
,
typename
T
>
const
framework
::
CLImage
*
PaddleMobile
<
Device
,
T
>::
FetchImage
(
const
std
::
string
&
var_name
)
{
return
executor_
->
GetOutputImage
(
var_name
);
}
#endif
template
<
typename
Device
,
typename
T
>
template
<
typename
Device
,
typename
T
>
void
PaddleMobile
<
Device
,
T
>::
Clear
()
{
void
PaddleMobile
<
Device
,
T
>::
Clear
()
{
executor_
=
nullptr
;
executor_
=
nullptr
;
...
...
src/io/paddle_mobile.h
浏览文件 @
549ebc0a
...
@@ -74,6 +74,9 @@ class PaddleMobile {
...
@@ -74,6 +74,9 @@ class PaddleMobile {
typedef
std
::
shared_ptr
<
framework
::
LoDTensor
>
LoDTensorPtr
;
typedef
std
::
shared_ptr
<
framework
::
LoDTensor
>
LoDTensorPtr
;
LoDTensorPtr
Fetch
(
const
std
::
string
&
var_name
);
LoDTensorPtr
Fetch
(
const
std
::
string
&
var_name
);
#ifdef PADDLE_MOBILE_CL
const
framework
::
CLImage
*
FetchImage
(
const
std
::
string
&
var_name
);
#endif
LoDTensorPtr
Fetch
()
{
return
Fetch
(
"fetch"
);
}
LoDTensorPtr
Fetch
()
{
return
Fetch
(
"fetch"
);
}
...
...
test/net/test_net.cpp
浏览文件 @
549ebc0a
...
@@ -167,6 +167,44 @@ void test(int argc, char *argv[]) {
...
@@ -167,6 +167,44 @@ void test(int argc, char *argv[]) {
paddle_mobile
.
Feed
(
var_names
[
0
],
input_tensor
);
paddle_mobile
.
Feed
(
var_names
[
0
],
input_tensor
);
paddle_mobile
.
Predict
();
paddle_mobile
.
Predict
();
}
}
#ifdef PADDLE_MOBILE_CL
for
(
auto
var_name
:
var_names
)
{
auto
cl_image
=
paddle_mobile
.
FetchImage
(
var_name
);
auto
len
=
cl_image
->
numel
();
if
(
len
==
0
)
{
continue
;
}
int
width
=
cl_image
->
ImageDims
()[
0
];
int
height
=
cl_image
->
ImageDims
()[
1
];
paddle_mobile
::
framework
::
half_t
*
image_data
=
new
paddle_mobile
::
framework
::
half_t
[
height
*
width
*
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
(
cl_image
->
CommandQueue
(),
image
,
CL_TRUE
,
origin
,
region
,
0
,
0
,
image_data
,
0
,
NULL
,
NULL
);
CL_CHECK_ERRORS
(
err
);
float
*
tensor_data
=
new
float
[
cl_image
->
numel
()];
auto
converter
=
cl_image
->
Converter
();
converter
->
ImageToNCHW
(
image_data
,
tensor_data
,
cl_image
->
ImageDims
(),
cl_image
->
dims
());
auto
data
=
tensor_data
;
std
::
string
sample
=
""
;
if
(
!
is_sample_step
)
{
sample_step
=
len
/
sample_num
;
}
if
(
sample_step
<=
0
)
{
sample_step
=
1
;
}
for
(
int
i
=
0
;
i
<
len
;
i
+=
sample_step
)
{
sample
+=
" "
+
std
::
to_string
(
data
[
i
]);
}
std
::
cout
<<
"auto-test"
<<
" var "
<<
var_name
<<
sample
<<
std
::
endl
;
}
#else
for
(
auto
var_name
:
var_names
)
{
for
(
auto
var_name
:
var_names
)
{
auto
out
=
paddle_mobile
.
Fetch
(
var_name
);
auto
out
=
paddle_mobile
.
Fetch
(
var_name
);
auto
len
=
out
->
numel
();
auto
len
=
out
->
numel
();
...
@@ -206,6 +244,7 @@ void test(int argc, char *argv[]) {
...
@@ -206,6 +244,7 @@ void test(int argc, char *argv[]) {
<<
" var "
<<
var_name
<<
sample
<<
std
::
endl
;
<<
" var "
<<
var_name
<<
sample
<<
std
::
endl
;
}
}
}
}
#endif
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
}
}
}
}
test/test_include.h
浏览文件 @
549ebc0a
...
@@ -33,3 +33,7 @@ limitations under the License. */
...
@@ -33,3 +33,7 @@ limitations under the License. */
#include "framework/tensor.h"
#include "framework/tensor.h"
#include "framework/variable.h"
#include "framework/variable.h"
#include "io/paddle_mobile.h"
#include "io/paddle_mobile.h"
#ifdef PADDLE_MOBILE_CL
#include "framework/cl/cl_image.h"
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录