Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
ecfe47d2
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看板
未验证
提交
ecfe47d2
编写于
8月 15, 2018
作者:
Z
zhangyang0701
提交者:
GitHub
8月 15, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #755 from chonwhite/develop
fix:
#753
上级
baa1ab86
8d77e47e
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
45 addition
and
74 deletion
+45
-74
src/fpga/fpga_quantilization.cpp
src/fpga/fpga_quantilization.cpp
+7
-11
src/fpga/fpga_quantilization.h
src/fpga/fpga_quantilization.h
+2
-1
src/io/executor.cpp
src/io/executor.cpp
+0
-1
src/memory/t_malloc.cpp
src/memory/t_malloc.cpp
+1
-1
src/operators/feed_op.h
src/operators/feed_op.h
+1
-1
src/operators/kernel/fpga/conv_add_bn_kernel.cpp
src/operators/kernel/fpga/conv_add_bn_kernel.cpp
+1
-4
src/operators/kernel/fpga/conv_kernel.cpp
src/operators/kernel/fpga/conv_kernel.cpp
+0
-38
src/operators/op_param.h
src/operators/op_param.h
+1
-1
test/CMakeLists.txt
test/CMakeLists.txt
+9
-5
test/fpga/test_tensor_quant.cpp
test/fpga/test_tensor_quant.cpp
+22
-11
tools/op.cmake
tools/op.cmake
+1
-0
未找到文件。
src/fpga/fpga_quantilization.cpp
浏览文件 @
ecfe47d2
...
@@ -47,7 +47,9 @@ static Dtype find_max(Dtype* data, int num) {
...
@@ -47,7 +47,9 @@ static Dtype find_max(Dtype* data, int num) {
}
}
// template <typename Dtype>
// template <typename Dtype>
framework
::
Tensor
*
quantify_filter
(
framework
::
Tensor
*
filter
)
{
void
quantify_filter
(
framework
::
Tensor
*
filter
)
{
DLOG
<<
"quantilize_filter........"
;
float
scale
=
0
;
float
scale
=
0
;
float
fix_range
=
static_cast
<
float
>
((
1
<<
(
8
-
1
))
-
1
);
float
fix_range
=
static_cast
<
float
>
((
1
<<
(
8
-
1
))
-
1
);
...
@@ -62,25 +64,20 @@ framework::Tensor* quantify_filter(framework::Tensor* filter) {
...
@@ -62,25 +64,20 @@ framework::Tensor* quantify_filter(framework::Tensor* filter) {
// 32bit filter -> 8bit filter;
// 32bit filter -> 8bit filter;
if
(
filter
->
type
()
==
typeid
(
float
))
{
if
(
filter
->
type
()
==
typeid
(
float
))
{
float
*
float_data
=
filter
->
data
<
float
>
();
float
*
float_data
=
filter
->
data
<
float
>
();
float
max
=
find_max
(
float_data
,
filter
->
numel
());
float
max
=
find_max
<
float
>
(
float_data
,
filter
->
numel
());
scale
=
(
max
/
fix_range
);
scale
=
(
max
/
fix_range
);
framework
::
Tensor
*
filter
=
filter
;
framework
::
Tensor
*
quant_filter
=
new
framework
::
Tensor
();
int_data
=
quant_filter
->
mutable_data
<
int8_t
>
();
for
(
int
i
=
0
;
i
<
filter
->
numel
();
++
i
)
{
for
(
int
i
=
0
;
i
<
filter
->
numel
();
++
i
)
{
tmp_data
[
i
]
=
(
int8_t
)
float_data
[
i
]
*
scale
;
tmp_data
[
i
]
=
(
int8_t
)
float_data
[
i
]
*
scale
;
}
}
filter
=
quant_filter
;
int_data
=
filter
->
mutable_data
<
int8_t
>
()
;
}
else
{
}
else
{
int8_t
max
=
find_max
(
filter
->
data
<
int8_t
>
(),
filter
->
numel
());
int8_t
max
=
find_max
<
int8_t
>
(
filter
->
data
<
int8_t
>
(),
filter
->
numel
());
scale
=
(
max
/
fix_range
);
scale
=
(
max
/
fix_range
);
int_data
=
filter
->
data
<
int8_t
>
();
for
(
int
i
=
0
;
i
<
filter
->
numel
();
++
i
)
{
for
(
int
i
=
0
;
i
<
filter
->
numel
();
++
i
)
{
tmp_data
[
i
]
=
int_data
[
i
];
tmp_data
[
i
]
=
filter
->
data
<
int8_t
>
()
[
i
];
}
}
int_data
=
filter
->
mutable_data
<
int8_t
>
();
int_data
=
filter
->
mutable_data
<
int8_t
>
();
}
}
...
@@ -88,7 +85,6 @@ framework::Tensor* quantify_filter(framework::Tensor* filter) {
...
@@ -88,7 +85,6 @@ framework::Tensor* quantify_filter(framework::Tensor* filter) {
chw_to_hwc
<
int8_t
>
(
tmp_data
,
int_data
,
batch_size
,
channel
,
height
,
width
);
chw_to_hwc
<
int8_t
>
(
tmp_data
,
int_data
,
batch_size
,
channel
,
height
,
width
);
delete
tmp_data
;
delete
tmp_data
;
*
(
filter
->
fpga_args
().
scale_pointer
())
=
scale
;
*
(
filter
->
fpga_args
().
scale_pointer
())
=
scale
;
return
filter
;
}
}
}
// namespace fpga
}
// namespace fpga
...
...
src/fpga/fpga_quantilization.h
浏览文件 @
ecfe47d2
...
@@ -25,6 +25,7 @@ static void chw_to_hwc(Dtype* data_in, Dtype* data_out, int num, int channel,
...
@@ -25,6 +25,7 @@ static void chw_to_hwc(Dtype* data_in, Dtype* data_out, int num, int channel,
int
height
,
int
width
);
int
height
,
int
width
);
// template <typename Dtype>
// template <typename Dtype>
framework
::
Tensor
*
quantify_filter
(
framework
::
Tensor
*
filter
);
void
quantify_filter
(
framework
::
Tensor
*
filter
);
}
// namespace fpga
}
// namespace fpga
}
// namespace paddle_mobile
}
// namespace paddle_mobile
src/io/executor.cpp
浏览文件 @
ecfe47d2
...
@@ -89,7 +89,6 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size,
...
@@ -89,7 +89,6 @@ Executor<Dtype, P>::Executor(const framework::Program<Dtype> p, int batch_size,
}
else
{
}
else
{
InitMemory
();
InitMemory
();
}
}
std
::
shared_ptr
<
framework
::
BlockDesc
>
to_predict_block
=
std
::
shared_ptr
<
framework
::
BlockDesc
>
to_predict_block
=
to_predict_program_
->
Block
(
0
);
to_predict_program_
->
Block
(
0
);
auto
&
ops
=
ops_of_block_
[
*
to_predict_block
.
get
()];
auto
&
ops
=
ops_of_block_
[
*
to_predict_block
.
get
()];
...
...
src/memory/t_malloc.cpp
浏览文件 @
ecfe47d2
...
@@ -26,7 +26,7 @@ namespace paddle_mobile {
...
@@ -26,7 +26,7 @@ namespace paddle_mobile {
namespace
memory
{
namespace
memory
{
const
int
MALLOC_ALIGN
=
64
;
const
int
MALLOC_ALIGN
=
64
;
#ifdef PADDLE_MOBILE_FPGA
#ifdef PADDLE_MOBILE_FPGA
__VV
namespace
fpga
=
paddle_mobile
::
fpga
;
namespace
fpga
=
paddle_mobile
::
fpga
;
void
Copy
(
void
*
dst
,
const
void
*
src
,
size_t
num
)
{
void
Copy
(
void
*
dst
,
const
void
*
src
,
size_t
num
)
{
...
...
src/operators/feed_op.h
浏览文件 @
ecfe47d2
...
@@ -41,7 +41,7 @@ class FeedOp : public framework::OperatorBase<DeviceType> {
...
@@ -41,7 +41,7 @@ class FeedOp : public framework::OperatorBase<DeviceType> {
void
RunImpl
()
const
{
fpga
::
PerformBypass
(
param_
.
FpgaArgs
());
}
void
RunImpl
()
const
{
fpga
::
PerformBypass
(
param_
.
FpgaArgs
());
}
void
Init
()
{
void
Init
()
{
const
Tensor
*
input
=
param_
.
InputX
();
const
Tensor
*
input
=
param_
.
InputX
();
auto
input_ptr
=
input
->
data
<
float
>
();
auto
input_ptr
=
input
->
mutable_
data
<
float
>
();
Tensor
*
output
=
param_
.
Out
();
Tensor
*
output
=
param_
.
Out
();
auto
output_ptr
=
output
->
mutable_data
<
half
>
();
auto
output_ptr
=
output
->
mutable_data
<
half
>
();
fpga
::
BypassArgs
args
;
fpga
::
BypassArgs
args
;
...
...
src/operators/kernel/fpga/conv_add_bn_kernel.cpp
浏览文件 @
ecfe47d2
...
@@ -60,10 +60,7 @@ bool ConvAddBNKernel<FPGA, float>::Init(FusionConvAddBNParam *param) {
...
@@ -60,10 +60,7 @@ bool ConvAddBNKernel<FPGA, float>::Init(FusionConvAddBNParam *param) {
param
->
SetNewScale
(
new_scale
);
param
->
SetNewScale
(
new_scale
);
param
->
SetNewBias
(
new_bias
);
param
->
SetNewBias
(
new_bias
);
Tensor
*
quant_filter
=
fpga
::
quantify_filter
(
filter
);
fpga
::
quantify_filter
(
filter
);
// delete original filter?
filter
=
quant_filter
;
auto
filter_ptr
=
filter
->
data
<
float
>
();
auto
filter_ptr
=
filter
->
data
<
float
>
();
fpga
::
ConvArgs
convArgs
;
fpga
::
ConvArgs
convArgs
;
...
...
src/operators/kernel/fpga/conv_kernel.cpp
已删除
100644 → 0
浏览文件 @
baa1ab86
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#ifdef CONV_OP
#include "operators/kernel/conv_kernel.h"
#include "operators/kernel/central-arm-func/conv_arm_func.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
bool
ConvKernel
<
FPGA
,
float
>::
Init
(
ConvParam
*
param
)
{
return
true
;
}
template
<
>
void
ConvKernel
<
FPGA
,
float
>::
Compute
(
const
ConvParam
&
param
)
const
{
// ConvCompute<float>(param);
}
template
class
ConvKernel
<
FPGA
,
float
>;
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/op_param.h
浏览文件 @
ecfe47d2
...
@@ -210,7 +210,7 @@ class ConvParam : OpParam {
...
@@ -210,7 +210,7 @@ class ConvParam : OpParam {
const
Tensor
*
Input
()
const
{
return
input_
;
}
const
Tensor
*
Input
()
const
{
return
input_
;
}
const
Tensor
*
Filter
()
const
{
return
filter_
;
}
Tensor
*
Filter
()
const
{
return
filter_
;
}
Tensor
*
Output
()
const
{
return
output_
;
}
Tensor
*
Output
()
const
{
return
output_
;
}
...
...
test/CMakeLists.txt
浏览文件 @
ecfe47d2
...
@@ -27,6 +27,11 @@ elseif("resnet" IN_LIST NET)
...
@@ -27,6 +27,11 @@ elseif("resnet" IN_LIST NET)
ADD_EXECUTABLE
(
test-resnet net/test_resnet.cpp test_helper.h test_include.h executor_for_test.h
)
ADD_EXECUTABLE
(
test-resnet net/test_resnet.cpp test_helper.h test_include.h executor_for_test.h
)
target_link_libraries
(
test-resnet paddle-mobile
)
target_link_libraries
(
test-resnet paddle-mobile
)
elseif
(
"FPGAnets"
IN_LIST NET
)
elseif
(
"FPGAnets"
IN_LIST NET
)
# ADD_EXECUTABLE(test-resnet net/test_resnet.cpp test_helper.h test_include.h executor_for_test.h)
# target_link_libraries(test-resnet paddle-mobile)
ADD_EXECUTABLE
(
test-tensor-quant fpga/test_tensor_quant.cpp test_helper.h test_include.h executor_for_test.h
)
target_link_libraries
(
test-tensor-quant paddle-mobile
)
else
()
else
()
# gen test
# gen test
...
@@ -173,8 +178,7 @@ else ()
...
@@ -173,8 +178,7 @@ else ()
endif
()
endif
()
if
(
FPGA
)
# if(FPGA)
ADD_EXECUTABLE
(
test-tensor-quant fpga/test_tensor_quant.cpp test_helper.h test_include.h executor_for_test.h
)
# ADD_EXECUTABLE(test-tensor-quant fpga/test_tensor_quant.cpp test_helper.h test_include.h executor_for_test.h)
target_link_libraries
(
test-tensor-quant paddle-mobile
)
# target_link_libraries(test-tensor-quant paddle-mobile)
# endif()
endif
()
test/fpga/test_tensor_quant.cpp
浏览文件 @
ecfe47d2
...
@@ -12,23 +12,34 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,23 +12,34 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <
f
stream>
#include <
io
stream>
#include "../test_helper.h"
#include "../test_helper.h"
#include "../test_include.h"
#include "../test_include.h"
int
main
()
{
int
main
()
{
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
FPGA
>
paddle_mobile
;
bool
optimize
=
false
;
paddle_mobile
.
SetThreadNum
(
4
);
if
(
paddle_mobile
.
Load
(
g_googlenet
,
optimize
))
{
auto
time1
=
time
();
auto
time1
=
time
();
if
(
paddle_mobile
.
Load
(
g_resnet
,
true
))
{
DLOG
<<
"load cost: "
<<
time_diff
(
time1
,
time1
)
<<
"ms"
;
auto
time2
=
time
();
std
::
vector
<
float
>
input
;
std
::
cout
<<
"load cost :"
<<
time_diff
(
time1
,
time1
)
<<
"ms"
<<
std
::
endl
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
32
,
32
};
GetInput
<
float
>
(
g_test_image_1x3x224x224
,
&
input
,
dims
);
Tensor
input_tensor
;
SetupTensor
<
float
>
(
&
input_tensor
,
{
1
,
3
,
32
,
32
},
static_cast
<
float
>
(
0
),
static_cast
<
float
>
(
1
));
std
::
vector
<
float
>
input
(
input_tensor
.
data
<
float
>
(),
input_tensor
.
data
<
float
>
()
+
input_tensor
.
numel
());
// 预热一次
paddle_mobile
.
Predict
(
input
,
dims
);
auto
time3
=
time
();
auto
time3
=
time
();
auto
vec_result
=
paddle_mobile
.
Predict
(
input
,
dims
);
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
paddle_mobile
.
Predict
(
input
,
dims
);
}
auto
time4
=
time
();
auto
time4
=
time
();
DLOG
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
<<
"ms"
;
std
::
cout
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
<<
"ms"
<<
std
::
endl
;
}
}
return
0
;
return
0
;
}
}
tools/op.cmake
浏览文件 @
ecfe47d2
...
@@ -82,6 +82,7 @@ if ("FPGAnets" IN_LIST NET)
...
@@ -82,6 +82,7 @@ if ("FPGAnets" IN_LIST NET)
set
(
CONCAT_OP ON
)
set
(
CONCAT_OP ON
)
set
(
SOFTMAX_OP ON
)
set
(
SOFTMAX_OP ON
)
set
(
DROPOUT_OP ON
)
set
(
DROPOUT_OP ON
)
# set(CONV_OP ON)
set
(
FOUND_MATCH ON
)
set
(
FOUND_MATCH ON
)
endif
()
endif
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录