Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
458183af
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
提交
458183af
编写于
2月 01, 2019
作者:
Z
zhangyang0701
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support multiple feed for FPGA track
上级
ef972b7a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
130 addition
and
4 deletion
+130
-4
src/framework/executor.cpp
src/framework/executor.cpp
+68
-1
src/framework/executor.h
src/framework/executor.h
+3
-0
src/framework/operator.cpp
src/framework/operator.cpp
+15
-0
src/framework/operator.h
src/framework/operator.h
+3
-1
src/framework/program/program_desc.cpp
src/framework/program/program_desc.cpp
+2
-1
src/framework/scope.cpp
src/framework/scope.cpp
+26
-0
src/framework/scope.h
src/framework/scope.h
+7
-0
src/io/paddle_mobile.cpp
src/io/paddle_mobile.cpp
+5
-1
src/io/paddle_mobile.h
src/io/paddle_mobile.h
+1
-0
未找到文件。
src/framework/executor.cpp
浏览文件 @
458183af
...
...
@@ -92,6 +92,14 @@ Executor<Device, T>::Executor(const Program<Device> &program,
ops_list_
.
push_back
(
op_handler
);
}
}
#ifdef PADDLE_MOBILE_FPGA
TalorFeedOp
();
DLOG
<<
"TalorFeed finished"
;
TalorFetchdOp
();
DLOG
<<
"TalorFetch finished"
;
program_
.
scope
->
print_vars
();
#endif
}
template
<
typename
T
>
...
...
@@ -443,11 +451,54 @@ std::shared_ptr<LoDTensor> Executor<Device, T>::GetOutput(
}
#ifdef PADDLE_MOBILE_FPGA
template
<
typename
Device
,
typename
T
>
void
Executor
<
Device
,
T
>::
TalorFeedOp
()
{
auto
&
ops
=
ops_of_block_
[
0
];
int
num
=
0
;
program_
.
scope
->
EraseVars
(
std
::
vector
<
string
>
{
string
(
"feed"
)});
for
(
auto
op
:
ops
)
{
if
(
op
->
Type
()
==
"feed"
)
{
auto
new_name
=
string
(
"feed"
)
+
std
::
to_string
(
num
++
);
auto
var
=
program_
.
scope
->
Var
(
new_name
);
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
auto
output_map
=
op
->
Outputs
();
std
::
vector
<
std
::
string
>
out_keys
=
op
->
GetOutKeys
();
PADDLE_MOBILE_ENFORCE
(
!
out_keys
.
empty
(),
"this op contains no output"
);
auto
output_tensor
=
GetVarValue
<
LoDTensor
>
(
out_keys
[
0
],
output_map
,
*
(
program_
.
scope
));
tensor
->
Resize
(
output_tensor
->
dims
());
tensor
->
init
(
typeid
(
float
));
op
->
ChangeNameMap
(
"X"
,
std
::
vector
<
string
>
{
new_name
});
}
}
}
template
<
typename
Device
,
typename
T
>
void
Executor
<
Device
,
T
>::
TalorFetchdOp
()
{
auto
&
ops
=
ops_of_block_
[
0
];
int
num
=
0
;
program_
.
scope
->
EraseVars
(
std
::
vector
<
string
>
{
string
(
"fetch"
)});
for
(
auto
op
:
ops
)
{
if
(
op
->
Type
()
==
"fetch"
)
{
auto
new_name
=
string
(
"fetch"
)
+
std
::
to_string
(
num
++
);
auto
var
=
program_
.
scope
->
Var
(
new_name
);
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
auto
input_map
=
op
->
Inputs
();
std
::
vector
<
std
::
string
>
in_keys
=
op
->
GetInputKeys
();
PADDLE_MOBILE_ENFORCE
(
!
in_keys
.
empty
(),
"this op contains no input"
);
auto
input_tensor
=
GetVarValue
<
LoDTensor
>
(
in_keys
[
0
],
input_map
,
*
(
program_
.
scope
));
tensor
->
Resize
(
input_tensor
->
dims
());
tensor
->
init
(
typeid
(
float
));
op
->
ChangeNameMap
(
"Out"
,
std
::
vector
<
string
>
{
new_name
});
}
}
}
template
<
typename
Device
,
typename
T
>
void
Executor
<
Device
,
T
>::
InjectVariable
(
const
Tensor
&
t
,
std
::
string
var_name
)
{
Variable
*
g_feed_value
=
program_
.
scope
->
Var
(
var_name
);
Tensor
*
feed_tensor
=
g_feed_value
->
GetMutable
<
LoDTensor
>
();
Tensor
*
feed_tensor
=
g_feed_value
->
template
GetMutable
<
LoDTensor
>();
feed_tensor
->
Resize
(
t
.
dims
());
feed_tensor
->
ShareDataWith
(
t
);
}
...
...
@@ -457,6 +508,22 @@ void Executor<Device, T>::FeedData(const Tensor &t) {
InjectVariable
(
t
,
"feed"
);
}
template
<
typename
Device
,
typename
T
>
void
Executor
<
Device
,
T
>::
FeedData
(
const
std
::
vector
<
Tensor
>
&
v
)
{
auto
input_size
=
v
.
size
();
PADDLE_MOBILE_ENFORCE
(
input_size
>
0
,
"Empty input"
);
int
counter
=
0
;
auto
vars
=
program_
.
scope
->
VarContain
(
"feed"
);
for
(
auto
var
:
vars
)
{
Tensor
*
feed_tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
feed_tensor
->
Resize
(
v
[
counter
].
dims
());
feed_tensor
->
ShareDataWith
(
v
[
counter
]);
if
(
++
counter
>
v
.
size
())
{
return
;
}
}
}
template
<
typename
Device
,
typename
T
>
std
::
shared_ptr
<
Tensor
>
Executor
<
Device
,
T
>::
FetchResult
(
int
id
)
{
auto
&
ops
=
ops_of_block_
[
0
];
...
...
src/framework/executor.h
浏览文件 @
458183af
...
...
@@ -50,8 +50,11 @@ class Executor {
std
::
shared_ptr
<
LoDTensor
>
GetOutput
(
const
std
::
string
&
var_name
);
#ifdef PADDLE_MOBILE_FPGA
void
TalorFeedOp
();
void
TalorFetchdOp
();
void
InjectVariable
(
const
Tensor
&
t
,
std
::
string
var_name
);
void
FeedData
(
const
Tensor
&
t
);
void
FeedData
(
const
std
::
vector
<
Tensor
>
&
v
);
std
::
shared_ptr
<
Tensor
>
FetchResult
(
int
id
=
-
1
);
void
Predict_From_To
(
int
start
=
0
,
int
end
=
-
1
);
void
Predict_From
(
int
start
);
...
...
src/framework/operator.cpp
浏览文件 @
458183af
...
...
@@ -131,6 +131,21 @@ void OperatorBase<GPU_CL>::Run() {
}
#endif
#ifdef PADDLE_MOBILE_FPGA
template
<
typename
Dtype
>
void
OperatorBase
<
Dtype
>::
ChangeNameMap
(
string
key
,
std
::
vector
<
string
>
value
)
{
auto
it
=
inputs_
.
find
(
key
);
if
(
it
!=
inputs_
.
end
())
{
inputs_
[
key
]
=
value
;
return
;
}
it
=
outputs_
.
find
(
key
);
if
(
it
!=
outputs_
.
end
())
{
inputs_
[
key
]
=
value
;
}
}
#endif
template
class
OperatorBase
<
CPU
>;
template
class
OperatorBase
<
FPGA
>;
template
class
OperatorBase
<
GPU_MALI
>;
...
...
src/framework/operator.h
浏览文件 @
458183af
...
...
@@ -78,7 +78,9 @@ class OperatorBase {
this
->
scope_
->
EraseVars
(
var_names
);
}
}
#ifdef PADDLE_MOBILE_FPGA
void
ChangeNameMap
(
string
key
,
std
::
vector
<
string
>
value
);
#endif
protected:
std
::
shared_ptr
<
Scope
>
scope_
;
std
::
string
type_
;
...
...
src/framework/program/program_desc.cpp
浏览文件 @
458183af
...
...
@@ -53,7 +53,8 @@ void ProgramDesc::Description(std::string header) {
}
}
for
(
auto
&
attr
:
op
->
GetAttrMap
())
{
LOG
(
kLOG_DEBUG2
)
<<
"attr name:: "
<<
attr
.
first
;
if
(
attr
.
first
==
"op_callstack"
)
continue
;
LOG
(
kLOG_DEBUG2
)
<<
"attr name: "
<<
attr
.
first
;
LOG
(
kLOG_DEBUG3
)
<<
"argument - "
<<
attr
.
second
;
}
}
...
...
src/framework/scope.cpp
浏览文件 @
458183af
...
...
@@ -111,5 +111,31 @@ Variable *Scope::FindVarLocally(const std::string &name) const {
return
nullptr
;
}
#ifdef PADDLE_MOBILE_FPGA
Variable
*
Scope
::
Var
(
const
std
::
string
&
name
,
const
int
id
)
{
return
Var
(
name
+
std
::
to_string
(
id
));
}
std
::
vector
<
Variable
*>
Scope
::
VarContain
(
const
std
::
string
substring
)
{
std
::
vector
<
Variable
*>
v
;
for
(
auto
pair
:
vars_
)
{
if
(
pair
.
first
.
find
(
substring
)
==
0
)
{
v
.
push_back
(
pair
.
second
);
}
}
return
v
;
}
void
Scope
::
InsertVar
(
const
std
::
string
str
,
Variable
*
var
)
{}
void
Scope
::
print_vars
()
{
DLOG
<<
"====================start to print variables================="
;
for
(
auto
pair
:
vars_
)
{
DLOG
<<
pair
.
first
;
}
DLOG
<<
"==================complete printing variables================"
;
}
#endif
}
// namespace framework
}
// namespace paddle_mobile
src/framework/scope.h
浏览文件 @
458183af
...
...
@@ -83,6 +83,13 @@ class Scope {
Variable
*
FindVarLocally
(
const
std
::
string
&
name
)
const
;
#ifdef PADDLE_MOBILE_FPGA
Variable
*
Var
(
const
std
::
string
&
name
,
const
int
id
);
std
::
vector
<
Variable
*>
VarContain
(
const
std
::
string
substring
);
void
InsertVar
(
const
std
::
string
str
,
Variable
*
var
);
void
print_vars
();
#endif
#ifdef PADDLE_MOBILE_CL
CLScope
*
GetCLScpoe
()
{
return
cl_scope_
;
}
#endif
...
...
src/io/paddle_mobile.cpp
浏览文件 @
458183af
...
...
@@ -227,7 +227,11 @@ template <typename Device, typename T>
void
PaddleMobile
<
Device
,
T
>::
FeedData
(
const
framework
::
Tensor
&
t
)
{
executor_
->
FeedData
(
t
);
}
template
<
typename
Device
,
typename
T
>
void
PaddleMobile
<
Device
,
T
>::
FeedData
(
const
std
::
vector
<
framework
::
Tensor
>
&
v
)
{
executor_
->
FeedData
(
v
);
};
template
<
typename
Device
,
typename
T
>
std
::
shared_ptr
<
framework
::
Tensor
>
PaddleMobile
<
Device
,
T
>::
FetchResult
(
int
id
)
{
...
...
src/io/paddle_mobile.h
浏览文件 @
458183af
...
...
@@ -90,6 +90,7 @@ class PaddleMobile {
#ifdef PADDLE_MOBILE_FPGA
void
InjectVariable
(
const
framework
::
Tensor
&
t
,
std
::
string
var_name
);
void
FeedData
(
const
framework
::
Tensor
&
t
);
void
FeedData
(
const
std
::
vector
<
framework
::
Tensor
>
&
v
);
std
::
shared_ptr
<
framework
::
Tensor
>
FetchResult
(
int
id
=
-
1
);
void
Predict_From_To
(
int
start
=
0
,
int
end
=
-
1
);
void
Predict_From
(
int
start
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录