Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
6fa059b2
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看板
提交
6fa059b2
编写于
8月 13, 2018
作者:
H
hanbuhe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added test_tensor_qunat executable
上级
a5042501
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
79 addition
and
21 deletion
+79
-21
src/fpga/fpga_quantilization.cpp
src/fpga/fpga_quantilization.cpp
+30
-18
src/operators/kernel/fpga/concat_kernel.cpp
src/operators/kernel/fpga/concat_kernel.cpp
+2
-2
src/operators/kernel/fpga/conv_kernel.cpp
src/operators/kernel/fpga/conv_kernel.cpp
+38
-0
test/CMakeLists.txt
test/CMakeLists.txt
+8
-0
test/fpga/test_tensor_quant.cpp
test/fpga/test_tensor_quant.cpp
+1
-1
未找到文件。
src/fpga/fpga_quantilization.cpp
浏览文件 @
6fa059b2
...
...
@@ -37,45 +37,57 @@ static void chw_to_hwc(Dtype* data_in, Dtype* data_out, int num, int channel,
}
}
template
<
typename
Dtype
>
static
Dtype
find_max
(
Dtype
*
data
,
int
num
)
{
Dtype
max
=
0
;
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
max
=
std
::
max
(
max
,
data
[
i
]);
}
return
max
;
}
template
<
typename
Dtype
>
framework
::
Tensor
*
quantilize_filter
(
framework
::
Tensor
*
filter
)
{
float
scale
=
0
;
float
max
=
0
f
;
float
fix_range
=
static_cast
<
float
>
((
1
<<
(
8
-
1
))
-
1
)
;
const
int
batch_size
=
filter
->
dims
()[
0
];
const
int
channel
=
filter
->
dims
()[
1
];
const
int
height
=
filter
->
dims
()[
2
];
const
int
width
=
filter
->
dims
()[
3
];
int8_t
*
int_data
=
nullptr
;
int8_t
*
tmp_data
=
new
int
[
filter
->
numel
()];
// 32bit filter -> 8bit filter;
if
(
filter
->
type
()
==
typeid
(
float
))
{
float
*
float_data
=
filter
->
data
<
float
>
();
for
(
int
i
=
0
;
i
<
filter
->
numel
();
++
i
)
{
max
=
std
::
max
(
max
,
float_data
[
i
]);
}
float
max
=
find_max
(
float_data
,
filter
->
numel
());
float
fix_range
=
static_cast
<
float
>
((
1
<<
(
8
-
1
))
-
1
);
float
float_range
=
max
;
scale
=
(
float_range
/
fix_range
);
scale
=
(
max
/
fix_range
);
framework
::
Tensor
*
filter
=
filter
;
framework
::
Tensor
*
quant_filter
=
new
framework
::
Tensor
();
int8_t
*
temp
=
new
int8_t
[
filter
->
numel
()];
int
8_t
*
int
_data
=
quant_filter
->
mutable_data
<
int8_t
>
();
int_data
=
quant_filter
->
mutable_data
<
int8_t
>
();
for
(
int
i
=
0
;
i
<
filter
->
numel
();
++
i
)
{
t
emp
[
i
]
=
(
int8_t
)
float_data
[
i
]
*
scale
;
t
mp_data
[
i
]
=
(
int8_t
)
float_data
[
i
]
*
scale
;
}
quant_filter
.
scale
=
scale
;
// NCHW -> NHWC;
chw_to_hwc
<
int8_t
>
(
temp
,
int_data
,
in_batch_size
,
channel
,
height
,
width
);
return
quantFilter
;
}
else
if
(
filter
->
type
()
==
typeid
(
int8_t
))
{
// model is already quantilized
int8_t
*
int_data
=
filter
->
data
<
int8_t
>
();
filter
=
quant_filter
;
}
else
{
int8_t
max
=
find_max
(
filter
->
data
<
int8_t
>
(),
filter
->
numel
());
scale
=
(
max
/
fix_range
);
int_data
=
filter
->
data
<
int8_t
>
();
for
(
int
i
=
0
;
i
<
filter
->
numel
();
++
i
)
{
max
=
std
::
max
(
max
,
int_data
[
i
])
;
tmp_data
[
i
]
=
int_data
[
i
]
;
}
int_data
=
filter
->
mutable_data
<
int8_t
>
();
}
// NCHW -> NHWC;
chw_to_hwc
<
int8_t
>
(
tmp_data
,
int_data
,
batch_size
,
channel
,
height
,
width
);
delete
tmp_data
;
*
(
filter
->
fpga_args
().
scale_pointer
())
=
scale
;
return
filter
;
}
...
...
src/operators/kernel/fpga/concat_kernel.cpp
浏览文件 @
6fa059b2
...
...
@@ -36,18 +36,18 @@ void ConcatKernel<FPGA, float>::Compute(const ConcatParam ¶m) const {
auto
out_channel
=
out_dim
[
3
];
auto
out_offset
=
0
;
for
(
int
i
=
0
;
i
<
inputs
.
size
();
++
i
)
{
auto
input
=
inputs
[
i
];
auto
channels
=
input
->
dims
()[
3
];
out_offset
+=
channels
;
auto
src
=
input
->
data
<
half
>
();
for
(
int
j
=
0
;
j
<
pixels
;
++
j
)
{
auto
dst
=
out
->
data
<
half
>
()
+
out_offset
;
auto
dst
=
out
->
mutable_
data
<
half
>
()
+
out_offset
;
memory
::
Copy
(
dst
,
src
,
sizeof
(
half
));
}
}
}
template
class
ConcatKernel
<
FPGA
,
float
>;
}
// namespace operators
}
// namespace paddle_mobile
...
...
src/operators/kernel/fpga/conv_kernel.cpp
0 → 100644
浏览文件 @
6fa059b2
/* 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
test/CMakeLists.txt
浏览文件 @
6fa059b2
...
...
@@ -160,4 +160,12 @@ else ()
#add_library(test-lib-size SHARED common/test_lib_size.h common/test_lib_size.cpp)
endif
()
if
(
FPGA
)
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
)
endif
()
test/fpga/test_tensor_quant.cpp
浏览文件 @
6fa059b2
...
...
@@ -20,7 +20,7 @@ int main() {
paddle_mobile
::
PaddleMobile
<
paddle_mobile
::
CPU
>
paddle_mobile
;
bool
optimize
=
false
;
if
(
paddle_mobile
.
Load
(
g_googlenet
,
optimize
))
{
auto
time
2
=
time
();
auto
time
1
=
time
();
DLOG
<<
"load cost: "
<<
time_diff
(
time1
,
time1
)
<<
"ms"
;
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录