Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
4d001f09
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看板
未验证
提交
4d001f09
编写于
10月 11, 2018
作者:
H
Houjiang Chen
提交者:
GitHub
10月 11, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into dev-latest
上级
4dad58c1
15eb9986
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
52 addition
and
10 deletion
+52
-10
src/fpga/api.cpp
src/fpga/api.cpp
+27
-4
src/fpga/api.h
src/fpga/api.h
+7
-2
src/fpga/filter.cpp
src/fpga/filter.cpp
+12
-2
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
+2
-2
src/operators/kernel/fpga/pool_kernel.cpp
src/operators/kernel/fpga/pool_kernel.cpp
+4
-0
未找到文件。
src/fpga/api.cpp
浏览文件 @
4d001f09
...
...
@@ -59,8 +59,8 @@ void *fpga_malloc(size_t size) {
#endif
counter
+=
size
;
memory_map
.
insert
(
std
::
make_pair
(
ptr
,
size
));
DLOG
<<
"Address: "
<<
ptr
<<
", "
<<
size
<<
" bytes allocated. Total "
<<
counter
<<
" bytes"
;
//
DLOG << "Address: " << ptr << ", " << size << " bytes allocated. Total "
//
<< counter << " bytes";
return
ptr
;
}
...
...
@@ -78,8 +78,8 @@ void fpga_free(void *ptr) {
free
(
ptr
);
#endif
counter
+=
size
;
DLOG
<<
"Address: "
<<
ptr
<<
", "
<<
size
<<
" bytes freed. Total "
<<
counter
<<
" bytes"
;
//
DLOG << "Address: " << ptr << ", " << size << " bytes freed. Total "
//
<< counter << " bytes";
}
else
{
DLOG
<<
"Invalid pointer"
;
}
...
...
@@ -103,6 +103,27 @@ int fpga_invalidate(void *address, size_t size) {
return
do_ioctl
(
IOCTL_MEMCACHE_INVAL
,
&
args
);
}
half
fp32_2_fp16
(
float
fp32_num
)
{
unsigned
long
tmp
=
*
(
unsigned
long
*
)(
&
fp32_num
);
half
t
=
((
tmp
&
0x007fffff
)
>>
13
)
|
((
tmp
&
0x80000000
)
>>
16
)
|
(((
tmp
&
0x7f800000
)
>>
13
)
-
(
112
<<
10
));
if
(
tmp
&
0x1000
)
{
t
++
;
// roundoff
}
return
t
;
}
float
fp16_2_fp32
(
half
fp16_num
)
{
int
frac
=
(
fp16_num
&
0x3ff
);
int
exp
=
((
fp16_num
&
0x7c00
)
>>
10
)
+
112
;
int
s
=
fp16_num
&
0x8000
;
int
tmp
=
0
;
float
fp32_num
;
tmp
=
s
<<
16
|
exp
<<
23
|
frac
<<
13
;
fp32_num
=
*
(
float
*
)
&
tmp
;
return
fp32_num
;
}
int
ComputeBasicConv
(
const
struct
ConvArgs
&
args
)
{
DLOG
<<
"======Compute Basic Conv======"
;
DLOG
<<
" relu_enabled:"
<<
args
.
relu_enabled
...
...
@@ -148,6 +169,8 @@ int ComputeFpgaConv(const struct WrapperConvArgs &args) {
int
ComputeFpgaPool
(
const
struct
PoolingArgs
&
args
)
{
#ifdef FPGA_TEST_MODE
DLOG
<<
"=============ComputeFpgaPool==========="
;
DLOG
<<
" mode:"
<<
args
.
mode
<<
" kernel_reciprocal:"
<<
fp16_2_fp32
(
args
.
kernel_reciprocal
);
DLOG
<<
" image_address:"
<<
args
.
image
.
address
<<
" image_scale_address:"
<<
args
.
image
.
scale_address
<<
" image_channels:"
<<
args
.
image
.
channels
...
...
src/fpga/api.h
浏览文件 @
4d001f09
...
...
@@ -99,6 +99,8 @@ struct WrapperConvArgs {
};
struct
PoolingArgs
{
int16_t
mode
;
// mode: 0:max, 1:avg
half
kernel_reciprocal
;
struct
KernelArgs
kernel
;
struct
ImageInputArgs
image
;
// input image;
struct
ImageOutputArgs
output
;
...
...
@@ -107,8 +109,8 @@ struct PoolingArgs {
struct
EWAddArgs
{
bool
relu_enabled
;
uint32_t
const0
;
// output0 = const0 x input0 + const1 x input1;
uint32_t
const1
;
half
const0
;
// output0 = const0 x input0 + const1 x input1;
half
const1
;
struct
ImageInputArgs
image0
;
struct
ImageInputArgs
image1
;
struct
ImageOutputArgs
output
;
...
...
@@ -222,5 +224,8 @@ void fill_conv_arg(struct WrapperConvArgs* arg, framework::Tensor* input,
bool
relu_enabled
,
int
group_num
,
int
stride_h
,
int
stride_w
,
int
padding_h
,
int
padding_w
,
float
*
bs_ptr
);
half
fp32_2_fp16
(
float
fp32_num
);
float
fp16_2_fp32
(
half
fp16_num
);
}
// namespace fpga
}
// namespace paddle_mobile
src/fpga/filter.cpp
浏览文件 @
4d001f09
...
...
@@ -85,14 +85,24 @@ float find_max(float *data_in, int data_size) {
return
max
;
}
signed
char
float_to_int8
(
float
fdata
)
{
if
(
fdata
<
0.0
)
{
fdata
-=
0.5
;
}
else
{
fdata
+=
0.5
;
}
return
(
signed
char
)
fdata
;
}
void
quantize
(
float
**
data_in
,
int
data_size
,
float
max
)
{
float
*
tmp
=
*
data_in
;
float
fix_range
=
127
;
float
scale
=
fix_range
/
max
;
char
*
tmp_data
=
(
char
*
)
fpga_malloc
(
data_size
*
sizeof
(
char
));
// NOLINT
signed
char
*
tmp_data
=
(
signed
char
*
)
fpga_malloc
(
data_size
*
sizeof
(
char
));
for
(
int
i
=
0
;
i
<
data_size
;
i
++
)
{
tmp_data
[
i
]
=
(
char
)((
*
data_in
)[
i
]
*
scale
);
// NOLINT
tmp_data
[
i
]
=
float_to_int8
(
(
*
data_in
)[
i
]
*
scale
);
// (signed char)((*data_in)[i] * scale);
}
*
data_in
=
(
float
*
)
tmp_data
;
// NOLINT
fpga_free
(
tmp
);
...
...
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
浏览文件 @
4d001f09
...
...
@@ -32,8 +32,8 @@ bool ElementwiseAddReluKernel<FPGA, float>::Init(
fpga
::
EWAddArgs
ewaddArgs
=
{
0
};
ewaddArgs
.
relu_enabled
=
relu_enabled
;
ewaddArgs
.
const0
=
1
;
ewaddArgs
.
const1
=
1
;
ewaddArgs
.
const0
=
0x3c00
;
// =1
ewaddArgs
.
const1
=
0x3c00
;
// =1
ewaddArgs
.
image0
.
address
=
input_x_ptr
;
ewaddArgs
.
image0
.
channels
=
(
uint32_t
)
input_x
->
dims
()[
1
];
ewaddArgs
.
image0
.
scale_address
=
input_x
->
scale
;
...
...
src/operators/kernel/fpga/pool_kernel.cpp
浏览文件 @
4d001f09
...
...
@@ -29,8 +29,12 @@ bool PoolKernel<FPGA, float>::Init(PoolParam<FPGA> *param) {
vector
<
int
>
ksize
=
param
->
Ksize
();
vector
<
int
>
strides
=
param
->
Strides
();
vector
<
int
>
paddings
=
param
->
Paddings
();
std
::
string
pooling_type
=
param
->
PoolingType
();
fpga
::
PoolingArgs
poolArgs
=
{
0
};
poolArgs
.
mode
=
pooling_type
==
"max"
?
0
:
1
;
// max:0, avg:1
poolArgs
.
kernel_reciprocal
=
fpga
::
fp32_2_fp16
(
float
(
1.0
/
(
ksize
[
0
]
*
ksize
[
1
])));
poolArgs
.
image
.
address
=
input_ptr
;
poolArgs
.
image
.
channels
=
(
uint32_t
)
input
->
dims
()[
1
];
poolArgs
.
image
.
height
=
(
uint32_t
)
input
->
dims
()[
2
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录