Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
414ec29a
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看板
提交
414ec29a
编写于
10月 15, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add debug code
上级
62dce83a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
58 addition
and
25 deletion
+58
-25
src/framework/cl/cl_half.cpp
src/framework/cl/cl_half.cpp
+12
-0
src/framework/cl/cl_half.h
src/framework/cl/cl_half.h
+5
-0
src/framework/cl/cl_image.h
src/framework/cl/cl_image.h
+4
-0
src/framework/executor.cpp
src/framework/executor.cpp
+15
-7
src/framework/operator.cpp
src/framework/operator.cpp
+4
-1
src/operators/op_param.h
src/operators/op_param.h
+1
-0
test/net/test_mobilenet_GPU.cpp
test/net/test_mobilenet_GPU.cpp
+17
-17
未找到文件。
src/framework/cl/cl_half.cpp
浏览文件 @
414ec29a
...
...
@@ -498,3 +498,15 @@ float half2float(half_t h) {
exponenttable
[
h
>>
10
];
return
*
reinterpret_cast
<
float
*>
(
&
v
);
}
void
FloatArray2HalfArray
(
float
*
f_array
,
half_t
*
h_array
,
int
count
)
{
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
h_array
[
i
]
=
float2half
(
f_array
[
i
]);
}
}
void
HalfArray2FloatArray
(
half_t
*
h_array
,
float
*
f_array
,
int
count
)
{
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
f_array
[
i
]
=
float2half
(
h_array
[
i
]);
}
}
src/framework/cl/cl_half.h
浏览文件 @
414ec29a
...
...
@@ -18,4 +18,9 @@ limitations under the License. */
typedef
uint16_t
half_t
;
half_t
float2half
(
float
f
);
float
half2float
(
half_t
h
);
void
FloatArray2HalfArray
(
float
*
f_array
,
half_t
*
h_array
,
int
count
);
void
HalfArray2FloatArray
(
half_t
*
h_array
,
float
*
f_array
,
int
count
);
src/framework/cl/cl_image.h
浏览文件 @
414ec29a
...
...
@@ -226,5 +226,9 @@ void TensorToCLImage(Tensor *tensor, CLImage *image);
void
CLImageToTensor
(
CLImage
*
image
,
Tensor
*
tensor
);
#ifdef PADDLE_MOBILE_DEBUG
Print
&
operator
<<
(
Print
&
printer
,
const
CLImage
&
image
);
#endif
}
// namespace framework
}
// namespace paddle_mobile
src/framework/executor.cpp
浏览文件 @
414ec29a
...
...
@@ -414,7 +414,7 @@ std::shared_ptr<framework::Tensor> Executor<Dtype, P>::Predict(
}
}
#else
for
(
int
i
=
0
;
i
<
ops
.
size
()
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1
;
i
++
)
{
#ifdef PADDLE_MOBILE_PROFILE
struct
timespec
ts
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
...
...
@@ -428,6 +428,9 @@ std::shared_ptr<framework::Tensor> Executor<Dtype, P>::Predict(
#endif
}
#endif
DLOG
<<
" predict return nullptr"
;
return
nullptr
;
auto
last_op
=
ops
.
rbegin
();
auto
output_map
=
(
*
last_op
)
->
Outputs
();
std
::
vector
<
std
::
string
>
out_keys
=
(
*
last_op
)
->
GetOutKeys
();
...
...
@@ -647,13 +650,18 @@ std::vector<typename Executor<Dtype, P>::Ptype> Executor<Dtype, P>::Predict(
const
std
::
vector
<
Ptype
>
&
input
,
const
std
::
vector
<
int64_t
>
&
dims
)
{
framework
::
Tensor
tensor
(
input
,
framework
::
make_ddim
(
dims
));
std
::
shared_ptr
<
framework
::
Tensor
>
output_tensor
=
Predict
(
tensor
,
0
);
Executor
<
Dtype
,
P
>::
Ptype
*
output_ptr
=
output_tensor
->
data
<
typename
Executor
<
Dtype
,
P
>::
Ptype
>
();
std
::
vector
<
typename
Executor
<
Dtype
,
P
>::
Ptype
>
result_vector
;
for
(
int
j
=
0
;
j
<
output_tensor
->
numel
();
++
j
)
{
result_vector
.
push_back
(
output_ptr
[
j
]);
if
(
output_tensor
!=
nullptr
)
{
Executor
<
Dtype
,
P
>::
Ptype
*
output_ptr
=
output_tensor
->
data
<
typename
Executor
<
Dtype
,
P
>::
Ptype
>
();
std
::
vector
<
typename
Executor
<
Dtype
,
P
>::
Ptype
>
result_vector
;
for
(
int
j
=
0
;
j
<
output_tensor
->
numel
();
++
j
)
{
result_vector
.
push_back
(
output_ptr
[
j
]);
}
return
result_vector
;
}
else
{
DLOG
<<
"return empty vector"
;
return
{};
}
return
result_vector
;
}
#ifdef PADDLE_MOBILE_FPGA
...
...
src/framework/operator.cpp
浏览文件 @
414ec29a
...
...
@@ -57,7 +57,9 @@ void OperatorBase<Dtype>::CheckAllInputOutputSet() const {}
template
<
typename
Dtype
>
void
OperatorBase
<
Dtype
>::
Run
()
{
DLOG
<<
" begin run "
<<
type_
;
RunImpl
();
DLOG
<<
" end run "
<<
type_
;
#ifdef PADDLE_MOBILE_DEBUG
DLOG
<<
"-------------"
<<
type_
<<
"----------------------------"
;
vector
<
string
>
input_keys
=
GetInputKeys
();
...
...
@@ -100,8 +102,9 @@ void OperatorBase<Dtype>::Run() {
#ifdef PADDLE_MOBILE_CL
if
(
type_
==
"fetch"
)
{
Tensor
*
tensor
=
vari
->
template
GetMutable
<
framework
::
LoDTensor
>();
if
(
tensor
)
if
(
tensor
)
{
DLOG
<<
type_
<<
" output- "
<<
key
<<
"="
<<
tensor
->
dims
();
}
}
else
{
CLImage
*
cl_image
=
vari
->
template
GetMutable
<
framework
::
CLImage
>();
// cl_command_queue commandQueue =
...
...
src/operators/op_param.h
浏览文件 @
414ec29a
...
...
@@ -948,6 +948,7 @@ class FetchParam : public OpParam {
input_x_
=
InputXFrom
<
GType
>
(
inputs
,
scope
);
out_
=
OutFrom
(
outputs
,
scope
);
}
const
RType
*
InputX
()
const
{
return
input_x_
;
}
Tensor
*
Out
()
const
{
return
out_
;
}
...
...
test/net/test_mobilenet_GPU.cpp
浏览文件 @
414ec29a
...
...
@@ -34,23 +34,23 @@ int main() {
GetInput
<
float
>
(
g_test_image_1x3x224x224_banana
,
&
input
,
dims
);
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
std
::
vector
<
float
>::
iterator
biggest
=
std
::
max_element
(
std
::
begin
(
vec_result
),
std
::
end
(
vec_result
));
std
::
cout
<<
" Max element is "
<<
*
biggest
<<
" at position "
<<
std
::
distance
(
std
::
begin
(
vec_result
),
biggest
)
<<
std
::
endl
;
// 预热十次
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
auto
time3
=
paddle_mobile
::
time
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
}
DLOG
<<
vec_result
;
auto
time4
=
paddle_mobile
::
time
();
std
::
cout
<<
"predict cost :"
<<
paddle_mobile
::
time_diff
(
time3
,
time4
)
/
10
<<
"ms"
<<
std
::
endl
;
//
std::vector<float>::iterator biggest =
//
std::max_element(std::begin(vec_result), std::end(vec_result));
//
std::cout << " Max element is " << *biggest << " at position "
//
<< std::distance(std::begin(vec_result), biggest) << std::endl;
//
for (int i = 0; i < 10; ++i) {
//
auto vec_result = paddle_mobile.Predict(input, dims);
//
}
//
auto time3 = paddle_mobile::time();
//
for (int i = 0; i < 10; ++i) {
//
auto vec_result = paddle_mobile.Predict(input, dims);
//
}
//
DLOG << vec_result;
//
auto time4 = paddle_mobile::time();
// std::cout << "predict cost :" << paddle_mobile::time_diff(time3, time4) / 10 << "ms"
//
<< std::endl;
}
std
::
cout
<<
"如果结果Nan请查看: test/images/g_test_image_1x3x224x224_banana "
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录