Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
196267f8
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看板
提交
196267f8
编写于
9月 15, 2018
作者:
Z
zhangyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement predict_from_to for FPGA track
上级
ca4793a7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
122 addition
and
3 deletion
+122
-3
src/io/executor.cpp
src/io/executor.cpp
+63
-0
src/io/executor.h
src/io/executor.h
+9
-0
src/io/paddle_mobile.cpp
src/io/paddle_mobile.cpp
+27
-0
src/io/paddle_mobile.h
src/io/paddle_mobile.h
+9
-0
src/operators/kernel/fpga/pool_kernel.cpp
src/operators/kernel/fpga/pool_kernel.cpp
+1
-1
test/net/test_resnet.cpp
test/net/test_resnet.cpp
+13
-2
未找到文件。
src/io/executor.cpp
浏览文件 @
196267f8
...
...
@@ -93,6 +93,7 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size,
depManager
[
i
].
analysisDep
(
ops_of_block_
[
*
block_desc
.
get
()]);
#endif
}
DLOG
<<
"Total "
<<
ops
.
size
()
<<
" ops have been created "
;
}
if
(
program_
.
combined
)
{
InitCombineMemory
();
...
...
@@ -643,6 +644,68 @@ std::vector<typename Executor<Dtype, P>::Ptype> Executor<Dtype, P>::Predict(
return
result_vector
;
}
#ifdef PADDLE_MOBILE_FPGA
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
FeedData
(
const
framework
::
Tensor
&
t
)
{
framework
::
Variable
*
g_feed_value
=
program_
.
scope
->
Var
(
"feed"
);
framework
::
Tensor
*
feed_tensor
=
g_feed_value
->
GetMutable
<
framework
::
LoDTensor
>
();
feed_tensor
->
Resize
(
t
.
dims
());
feed_tensor
->
ShareDataWith
(
t
);
};
template
<
typename
Dtype
,
Precision
P
>
std
::
shared_ptr
<
framework
::
Tensor
>
Executor
<
Dtype
,
P
>::
FetchResult
()
{
std
::
shared_ptr
<
framework
::
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
0
);
auto
&
ops
=
ops_of_block_
[
*
to_predict_block
.
get
()];
auto
last_op
=
ops
.
rbegin
();
auto
output_map
=
(
*
last_op
)
->
Outputs
();
std
::
vector
<
std
::
string
>
out_keys
=
(
*
last_op
)
->
GetOutKeys
();
PADDLE_MOBILE_ENFORCE
(
!
out_keys
.
empty
(),
"the last op contains no output"
);
auto
*
output_tensor
=
framework
::
GetVarValue
<
framework
::
LoDTensor
>
(
out_keys
[
0
],
output_map
,
*
(
program_
.
scope
));
return
std
::
make_shared
<
framework
::
Tensor
>
(
framework
::
Tensor
(
*
output_tensor
));
};
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
Predict_From_To
(
int
start
,
int
end
)
{
std
::
shared_ptr
<
framework
::
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
0
);
auto
&
ops
=
ops_of_block_
[
*
to_predict_block
.
get
()];
end
=
end
<
0
?
(
int
)
ops
.
size
()
:
end
;
PADDLE_MOBILE_ENFORCE
(
start
>=
0
&&
start
<
end
&&
end
<=
ops
.
size
(),
"start or end parameter is wrong"
);
#ifdef PADDLE_MOBILE_PROFILE
std
::
vector
<
ProfInfo
>
profile
(
ops
.
size
());
#endif
for
(
int
i
=
start
;
i
<
end
;
i
++
)
{
#ifdef PADDLE_MOBILE_PROFILE
struct
timespec
ts
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
profile
[
i
].
runBegin
=
(
uint64_t
)
ts
.
tv_sec
*
1e9
+
ts
.
tv_nsec
;
#endif
ops
[
i
]
->
Run
();
#ifdef PADDLE_MOBILE_PROFILE
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
profile
[
i
].
runEnd
=
(
uint64_t
)
ts
.
tv_sec
*
1e9
+
ts
.
tv_nsec
;
#endif
}
};
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
Predict_From
(
int
start
)
{
Predict_From_To
(
start
);
};
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
Predict_To
(
int
end
)
{
Predict_From_To
(
0
,
end
);
};
#endif
template
class
Executor
<
CPU
,
Precision
::
FP32
>;
template
class
Executor
<
GPU_MALI
,
Precision
::
FP32
>;
template
class
Executor
<
FPGA
,
Precision
::
FP32
>;
...
...
src/io/executor.h
浏览文件 @
196267f8
...
...
@@ -92,6 +92,15 @@ class Executor {
bool
varInputMemory
(
const
std
::
shared_ptr
<
framework
::
VarDesc
>
&
var_desc
,
framework
::
Variable
*
var
,
framework
::
LoDTensor
*
tensor
)
const
;
#ifdef PADDLE_MOBILE_FPGA
public:
void
FeedData
(
const
framework
::
Tensor
&
t
);
std
::
shared_ptr
<
framework
::
Tensor
>
FetchResult
();
void
Predict_From_To
(
int
start
=
0
,
int
end
=
-
1
);
void
Predict_From
(
int
start
);
void
Predict_To
(
int
end
);
#endif
};
}
// namespace paddle_mobile
src/io/paddle_mobile.cpp
浏览文件 @
196267f8
...
...
@@ -124,6 +124,33 @@ PaddleMobile<Dtype, P>::~PaddleMobile() {
loader_
=
nullptr
;
}
#ifdef PADDLE_MOBILE_FPGA
template
<
typename
Dtype
,
Precision
P
>
void
PaddleMobile
<
Dtype
,
P
>::
FeedData
(
const
framework
::
Tensor
&
t
)
{
return
executor_
->
FeedData
(
t
);
};
template
<
typename
Dtype
,
Precision
P
>
std
::
shared_ptr
<
framework
::
Tensor
>
PaddleMobile
<
Dtype
,
P
>::
FetchResult
()
{
return
executor_
->
FetchResult
();
};
template
<
typename
Dtype
,
Precision
P
>
void
PaddleMobile
<
Dtype
,
P
>::
Predict_From_To
(
int
start
,
int
end
)
{
executor_
->
Predict_From_To
(
start
,
end
);
};
template
<
typename
Dtype
,
Precision
P
>
void
PaddleMobile
<
Dtype
,
P
>::
Predict_From
(
int
start
)
{
executor_
->
Predict_From
(
start
);
};
template
<
typename
Dtype
,
Precision
P
>
void
PaddleMobile
<
Dtype
,
P
>::
Predict_To
(
int
end
)
{
executor_
->
Predict_To
(
end
);
};
#endif
template
class
PaddleMobile
<
CPU
,
Precision
::
FP32
>;
template
class
PaddleMobile
<
FPGA
,
Precision
::
FP32
>;
...
...
src/io/paddle_mobile.h
浏览文件 @
196267f8
...
...
@@ -92,6 +92,15 @@ class PaddleMobile {
private:
std
::
shared_ptr
<
Loader
<
Dtype
,
P
>>
loader_
;
std
::
shared_ptr
<
Executor
<
Dtype
,
P
>>
executor_
;
#ifdef PADDLE_MOBILE_FPGA
public:
void
FeedData
(
const
framework
::
Tensor
&
t
);
std
::
shared_ptr
<
framework
::
Tensor
>
FetchResult
();
void
Predict_From_To
(
int
start
=
0
,
int
end
=
-
1
);
void
Predict_From
(
int
start
);
void
Predict_To
(
int
end
);
#endif
};
}
// namespace paddle_mobile
src/operators/kernel/fpga/pool_kernel.cpp
浏览文件 @
196267f8
...
...
@@ -39,7 +39,7 @@ bool PoolKernel<FPGA, float>::Init(PoolParam<FPGA> *param) {
poolArgs
.
image
.
pad_width
=
(
uint32_t
)
paddings
[
1
];
poolArgs
.
image
.
scale_address
=
input
->
scale
;
poolArgs
.
output
.
address
=
output_ptr
;
poolArgs
.
output
.
scale_address
=
in
put
->
scale
;
poolArgs
.
output
.
scale_address
=
out
put
->
scale
;
poolArgs
.
kernel
.
height
=
(
uint32_t
)
ksize
[
0
];
poolArgs
.
kernel
.
width
=
(
uint32_t
)
ksize
[
1
];
poolArgs
.
kernel
.
stride_h
=
(
uint32_t
)
strides
[
0
];
...
...
test/net/test_resnet.cpp
浏览文件 @
196267f8
...
...
@@ -36,7 +36,8 @@ int main() {
std
::
vector
<
float
>
input
(
input_tensor
.
data
<
float
>
(),
input_tensor
.
data
<
float
>
()
+
input_tensor
.
numel
());
// 预热十次
#ifndef PADDLE_MOBILE_FPGA
// 预热十次
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
paddle_mobile
.
Predict
(
input
,
dims
);
}
...
...
@@ -47,7 +48,17 @@ int main() {
auto
time4
=
time
();
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
<<
"ms"
<<
std
::
endl
;
}
#else
auto
time3
=
time
();
paddle_mobile
.
FeedData
(
input_tensor
);
paddle_mobile
.
Predict_To
(
10
);
paddle_mobile
.
Predict_From
(
10
);
paddle_mobile
.
FetchResult
();
auto
time4
=
time
();
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
<<
"ms"
<<
std
::
endl
;
#endif
}
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录