Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e82bc1f8
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看板
提交
e82bc1f8
编写于
8月 03, 2018
作者:
qnqinan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some bugs of new added FPGA ops and kernels
上级
380c55f2
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
84 addition
and
36 deletion
+84
-36
CMakeLists.txt
CMakeLists.txt
+11
-4
src/operators/fusion_elementwise_add_relu_op.cpp
src/operators/fusion_elementwise_add_relu_op.cpp
+4
-4
src/operators/fusion_elementwise_add_relu_op.h
src/operators/fusion_elementwise_add_relu_op.h
+48
-6
src/operators/fusion_fc_op.h
src/operators/fusion_fc_op.h
+6
-2
src/operators/fusion_fc_relu_op.h
src/operators/fusion_fc_relu_op.h
+1
-1
src/operators/kernel/elementwise_add_relu_kernel.h
src/operators/kernel/elementwise_add_relu_kernel.h
+0
-1
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
+5
-6
src/operators/kernel/fpga/fc_relu_kernel.cpp
src/operators/kernel/fpga/fc_relu_kernel.cpp
+4
-5
src/operators/kernel/fpga/fusion_fc_kernel.cpp
src/operators/kernel/fpga/fusion_fc_kernel.cpp
+4
-5
src/operators/kernel/fpga/pool_kernel.cpp
src/operators/kernel/fpga/pool_kernel.cpp
+1
-2
未找到文件。
CMakeLists.txt
浏览文件 @
e82bc1f8
...
...
@@ -6,9 +6,15 @@ option(USE_OPENMP "openmp support" OFF)
option
(
USE_EXCEPTION
"use std exception"
ON
)
option
(
LOG_PROFILE
"log profile"
ON
)
# select the platform to build
option
(
CPU
"armv7 with neon"
O
N
)
option
(
CPU
"armv7 with neon"
O
FF
)
option
(
MALI_GPU
"mali gpu"
OFF
)
option
(
FPGA
"fpga"
OFF
)
option
(
FPGA
"fpga"
ON
)
SET
(
FPGA ON
)
SET
(
FUSION_ELEMENTWISEADDRELU_OP ON
)
SET
(
FUSION_FC_OP ON
)
SET
(
FUSION_FCRELU_OP ON
)
SET
(
POOL_OP ON
)
SET
(
DROPOUT_OP ON
)
file
(
GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c src/*.mm
)
file
(
GLOB_RECURSE PADDLE_MOBILE_H src/*.h
)
...
...
@@ -139,7 +145,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build)
set
(
CMAKE_RUNTIME_OUTPUT_DIRECTORY build
)
# NET default
set
(
NET
"default"
CACHE STRING
"select net type"
)
#set(NET "default" CACHE STRING "select net type")
set
(
NET
"FPGAnets"
CACHE STRING
"select net type"
)
set_property
(
CACHE NET PROPERTY STRINGS
"default"
"googlenet"
"mobilenet"
"yolo"
"squeezenet"
"FPGAnets"
)
include
(
"
${
CMAKE_CURRENT_LIST_DIR
}
/tools/op.cmake"
)
...
...
@@ -151,7 +158,7 @@ if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
elseif
(
IS_IOS
)
add_library
(
paddle-mobile STATIC
${
PADDLE_MOBILE_CC
}
${
PADDLE_MOBILE_H
}
)
else
()
add_library
(
paddle-mobile SHARED
${
PADDLE_MOBILE_CC
}
${
PADDLE_MOBILE_H
}
)
add_library
(
paddle-mobile SHARED
${
PADDLE_MOBILE_CC
}
${
PADDLE_MOBILE_H
}
src/operators/kernel/fc_relu_kernel.h src/operators/kernel/fc_relu_kernel.h src/operators/kernel/fpga/fusion_fc_kernel.cpp src/operators/kernel/fpga/fc_relu_kernel.cpp src/operators/fusion_elementwise_add_relu_op.h src/operators/fusion_elementwise_add_relu_op.cpp src/operators/kernel/elementwise_add_relu_kernel.h src/operators/kernel/fpga/pool_kernel.cpp src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp src/operators/kernel/fpga/dropout_kernel.cpp
)
endif
()
# unit test
...
...
src/operators/fusion_elementwise_add_relu_op.cpp
浏览文件 @
e82bc1f8
...
...
@@ -30,12 +30,12 @@ void FusionElementwiseAddReluOp<Dtype, T>::InferShape() const {
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
REGISTER_OPERATOR_CPU
(
fusion_elementwise_add_relu
,
ops
::
FusionElementwiseAddReluOp
);
//
REGISTER_OPERATOR_CPU(fusion_elementwise_add_relu,
//
ops::FusionElementwiseAddReluOp);
#endif
#ifdef PADDLE_MOBILE_MALI_GPU
REGISTER_OPERATOR_MALI_GPU
(
fusion_elementwise_add_relu
,
ops
::
FusionElementwiseAddReluOp
);
//
REGISTER_OPERATOR_MALI_GPU(fusion_elementwise_add_relu,
//
ops::FusionElementwiseAddReluOp);
#endif
#ifdef PADDLE_MOBILE_FPGA
REGISTER_OPERATOR_FPGA
(
fusion_elementwise_add_relu
,
...
...
src/operators/fusion_elementwise_add_relu_op.h
浏览文件 @
e82bc1f8
...
...
@@ -18,12 +18,29 @@ limitations under the License. */
#include <string>
#include "framework/operator.h"
#include "
kernel/elementwise_add_relu_kernel
.h"
#include "operators/
op_param
.h"
#include "
framework/program/program-optimize/fusion_op_register
.h"
#include "operators/
kernel/elementwise_add_relu_kernel
.h"
namespace
paddle_mobile
{
namespace
operators
{
using
std
::
string
;
using
std
::
vector
;
class
FusioneElementwiseAddReluMatcher
:
public
framework
::
FusionOpMatcher
{
public:
FusioneElementwiseAddReluMatcher
()
{
node_
=
framework
::
Node
(
G_OP_TYPE_FUSION_ELEMENTWISE_ADD_RELU
);
node_
>
std
::
make_shared
<
framework
::
Node
>
(
G_OP_TYPE_RELU
);
}
void
FolderNodes
(
framework
::
Node
*
node
,
std
::
vector
<
std
::
shared_ptr
<
framework
::
Node
>>
*
removed_nodes
)
{
node
->
Folder
(
node_
.
Depth
(),
Type
(),
{},
removed_nodes
);
}
std
::
string
Type
()
{
return
G_OP_TYPE_FUSION_ELEMENTWISE_ADD_RELU
;
}
};
template
<
typename
DeviceType
,
typename
T
>
class
FusionElementwiseAddReluOp
:
public
framework
::
OperatorWithKernel
<
...
...
@@ -39,13 +56,38 @@ class FusionElementwiseAddReluOp
operators
::
ElementwiseAddReluKernel
<
DeviceType
,
T
>>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
,
ElementwiseAddReluParam
,
operators
::
ElementwiseAddReluKernel
<
DeviceType
,
T
>>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
protected:
};
#ifdef PADDLE_MOBILE_CPU
/*
#ifndef FUSION_ELEMENTWISE_ADD_RELU_REGISTER
static framework::FusionOpRegistrar fusion_elementwise_relu_registrar(
new FusioneElementwiseAddReluMatcher());
#define FUSION_ELEMENTWISE_ADD_RELU_REGISTER
#endif
*/
#endif
#ifdef PADDLE_MOBILE_MALI_GPU
/*
#ifndef FUSION_ELEMENTWISE_ADD_RELU_REGISTER
static framework::FusionOpRegistrar fusion_elementwise_relu_registrar(
new FusioneElementwiseAddReluMatcher());
#define FUSION_ELEMENTWISE_ADD_RELU_REGISTER
#endif
*/
#endif
#ifdef PADDLE_MOBILE_FPGA
#ifndef FUSION_ELEMENTWISE_ADD_RELU_REGISTER
static
framework
::
FusionOpRegistrar
fusion_elementwise_relu_registrar
(
new
FusioneElementwiseAddReluMatcher
());
#define FUSION_ELEMENTWISE_ADD_RELU_REGISTER
#endif
}
// namespace operators
}
// namespace paddle_mobile
...
...
@@ -53,10 +95,10 @@ class FusionElementwiseAddReluOp
USE_OP_CPU
(
fusion_elementwise_add_relu
);
#endif
#ifdef PADDLE_MOBILE_MALI_GPU
USE_OP_MALI_GPU
(
fusion_elementwise_add_relu
);
#endif
#ifdef PADDLE_MOBILE_FPGA
USE_OP_FPGA
(
fusion_elementwise_add_relu
);
#endif
#endif
#endif
src/operators/fusion_fc_op.h
浏览文件 @
e82bc1f8
...
...
@@ -67,8 +67,8 @@ class FusionFcOp
#ifdef PADDLE_MOBILE_CPU
#ifndef
CONV
_CPU_REGISTER
#define
CONV
_CPU_REGISTER
#ifndef
FUSION_FC
_CPU_REGISTER
#define
FUSION_FC
_CPU_REGISTER
static
framework
::
FusionOpRegistrar
fc_registrar
(
new
FusionFcMatcher
());
#endif
...
...
@@ -84,6 +84,10 @@ static framework::FusionOpRegistrar fc_registrar(new FusionFcMatcher());
#endif
#ifdef PADDLE_MOBILE_FPGA
#ifndef FUSION_FC_CPU_REGISTER
#define FUSION_FC_CPU_REGISTER
static
framework
::
FusionOpRegistrar
fc_registrar
(
new
FusionFcMatcher
());
#endif
#endif
}
// namespace operators
...
...
src/operators/fusion_fc_relu_op.h
浏览文件 @
e82bc1f8
...
...
@@ -18,7 +18,7 @@ limitations under the License. */
#include "framework/operator.h"
#include "framework/program/program-optimize/fusion_op_register.h"
#include "operators/kernel/f
usion_f
c_relu_kernel.h"
#include "operators/kernel/fc_relu_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
...
...
src/operators/kernel/elementwise_add_relu_kernel.h
浏览文件 @
e82bc1f8
...
...
@@ -17,7 +17,6 @@ limitations under the License. */
#pragma once
#include "framework/operator.h"
#include "operators/math/elementwise_op_function.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
...
...
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
浏览文件 @
e82bc1f8
...
...
@@ -14,7 +14,6 @@ limitations under the License. */
#ifdef FUSION_ELEMENTWISEADDRELU_OP
#include "operators/kernel/elementwise_add_relu_kernel.h"
#include "fpga/api/fpga_api.h"
namespace
paddle_mobile
{
namespace
operators
{
...
...
@@ -28,7 +27,7 @@ bool ElementwiseAddReluKernel<FPGA, float>::Init(
Tensor
*
out
=
param
->
Out
();
auto
input_x_ptr
=
input_x
->
data
<
float
>
();
auto
input_y_ptr
=
input_y
->
data
<
float
>
();
auto
out_ptr
=
out
->
data
<
float
>
();
auto
out_ptr
=
out
->
mutable_
data
<
float
>
();
fpga
::
EWAddArgs
ewaddArgs
;
ewaddArgs
.
relu_enabled
=
relu_enabled
;
...
...
@@ -40,16 +39,16 @@ bool ElementwiseAddReluKernel<FPGA, float>::Init(
input_x
->
fpga_args
().
scale_pointer
();
// ew has scale attribute??
ewaddArgs
.
image0
.
height
=
input_x
->
dims
()[
2
];
ewaddArgs
.
image0
.
width
=
input_x
->
dims
()[
3
];
ewaddArgs
.
image0
.
pad_height
=
1
;
ewaddArgs
.
image0
.
pad_width
=
1
;
ewaddArgs
.
image0
.
pad_height
=
0
;
ewaddArgs
.
image0
.
pad_width
=
0
;
ewaddArgs
.
image1
.
address
=
(
void
*
)
input_y_ptr
;
ewaddArgs
.
image1
.
channels
=
input_y
->
dims
()[
1
];
ewaddArgs
.
image1
.
scale_address
=
input_y
->
fpga_args
().
scale_pointer
();
// ew has scale attribute??
ewaddArgs
.
image1
.
height
=
input_y
->
dims
()[
2
];
ewaddArgs
.
image1
.
width
=
input_y
->
dims
()[
3
];
ewaddArgs
.
image1
.
pad_height
=
1
;
ewaddArgs
.
image1
.
pad_width
=
1
;
ewaddArgs
.
image1
.
pad_height
=
0
;
ewaddArgs
.
image1
.
pad_width
=
0
;
ewaddArgs
.
output
.
scale_address
=
out
->
fpga_args
().
scale_pointer
();
ewaddArgs
.
output
.
address
=
(
void
*
)
out_ptr
;
param
->
SetFpgaArgs
(
ewaddArgs
);
...
...
src/operators/kernel/fpga/fc_relu_kernel.cpp
浏览文件 @
e82bc1f8
...
...
@@ -21,7 +21,6 @@ namespace operators {
template
<
>
bool
FusionFcReluKernel
<
FPGA
,
float
>::
Init
(
FusionFcReluParam
*
param
)
{
bool
relu_enabled
=
true
;
bool
bn_enabled
=
false
;
const
Tensor
*
input_x
=
param
->
InputX
();
auto
input_x_ptr
=
input_x
->
data
<
float
>
();
const
Tensor
*
input_y
=
param
->
InputY
();
...
...
@@ -31,8 +30,8 @@ bool FusionFcReluKernel<FPGA, float>::Init(FusionFcReluParam *param) {
Tensor
*
out
=
param
->
Out
();
auto
out_ptr
=
out
->
mutable_data
<
float
>
();
PADDLE_MOBILE_ENFORCE
(
input_x
->
dims
()[
1
]
==
input_
z
->
dims
()[
0
],
"Image channel should be equal to
bias
number"
);
PADDLE_MOBILE_ENFORCE
(
input_x
->
dims
()[
1
]
==
input_
y
->
dims
()[
0
],
"Image channel should be equal to
weight
number"
);
int
channel
=
input_x
->
dims
()[
1
];
float
*
bs_ptr
=
(
float
*
)
fpga
::
fpga_malloc
(
2
*
channel
*
sizeof
(
float
));
for
(
int
i
=
0
;
i
<
channel
;
i
++
)
{
...
...
@@ -55,8 +54,8 @@ bool FusionFcReluKernel<FPGA, float>::Init(FusionFcReluParam *param) {
convArgs
.
image
.
channels
=
input_x
->
dims
()[
1
];
convArgs
.
image
.
height
=
input_x
->
dims
()[
2
];
convArgs
.
image
.
width
=
input_x
->
dims
()[
3
];
convArgs
.
image
.
pad_height
=
1
;
convArgs
.
image
.
pad_width
=
1
;
convArgs
.
image
.
pad_height
=
0
;
convArgs
.
image
.
pad_width
=
0
;
convArgs
.
image
.
scale_address
=
input_x
->
fpga_args
().
scale_pointer
();
// fc input has scale attribute??
convArgs
.
output
.
address
=
(
void
*
)
out_ptr
;
...
...
src/operators/kernel/fpga/fusion_fc_kernel.cpp
浏览文件 @
e82bc1f8
...
...
@@ -21,7 +21,6 @@ namespace operators {
template
<
>
bool
FusionFcKernel
<
FPGA
,
float
>::
Init
(
FusionFcParam
*
param
)
{
bool
relu_enabled
=
false
;
bool
bn_enabled
=
false
;
const
Tensor
*
input_x
=
param
->
InputX
();
auto
input_x_ptr
=
input_x
->
data
<
float
>
();
const
Tensor
*
input_y
=
param
->
InputY
();
...
...
@@ -31,8 +30,8 @@ bool FusionFcKernel<FPGA, float>::Init(FusionFcParam *param) {
Tensor
*
out
=
param
->
Out
();
auto
out_ptr
=
out
->
mutable_data
<
float
>
();
PADDLE_MOBILE_ENFORCE
(
input_x
->
dims
()[
1
]
==
input_
z
->
dims
()[
0
],
"Image channel should be equal to
bias
number"
);
PADDLE_MOBILE_ENFORCE
(
input_x
->
dims
()[
1
]
==
input_
y
->
dims
()[
0
],
"Image channel should be equal to
weight
number"
);
int
channel
=
input_x
->
dims
()[
1
];
float
*
bs_ptr
=
(
float
*
)
fpga
::
fpga_malloc
(
2
*
channel
*
sizeof
(
float
));
for
(
int
i
=
0
;
i
<
channel
;
i
++
)
{
...
...
@@ -55,8 +54,8 @@ bool FusionFcKernel<FPGA, float>::Init(FusionFcParam *param) {
convArgs
.
image
.
channels
=
input_x
->
dims
()[
1
];
convArgs
.
image
.
height
=
input_x
->
dims
()[
2
];
convArgs
.
image
.
width
=
input_x
->
dims
()[
3
];
convArgs
.
image
.
pad_height
=
1
;
convArgs
.
image
.
pad_width
=
1
;
convArgs
.
image
.
pad_height
=
0
;
convArgs
.
image
.
pad_width
=
0
;
convArgs
.
image
.
scale_address
=
input_x
->
fpga_args
().
scale_pointer
();
// fc input has scale attribute??
convArgs
.
output
.
address
=
(
void
*
)
out_ptr
;
...
...
src/operators/kernel/fpga/pool_kernel.cpp
浏览文件 @
e82bc1f8
...
...
@@ -14,7 +14,6 @@ limitations under the License. */
#ifdef POOL_OP
#include "operators/kernel/pool_kernel.h"
#include "fpga/api/fpga_api.h"
class
PoolingArgs
;
namespace
paddle_mobile
{
...
...
@@ -25,7 +24,7 @@ bool PoolKernel<FPGA, float>::Init(PoolParam *param) {
const
Tensor
*
input
=
param
->
Input
();
auto
input_ptr
=
input
->
data
<
float
>
();
Tensor
*
output
=
param
->
Output
();
auto
output_ptr
=
output
->
data
<
float
>
();
auto
output_ptr
=
output
->
mutable_
data
<
float
>
();
vector
<
int
>
ksize
=
param
->
Ksize
();
vector
<
int
>
strides
=
param
->
Strides
();
vector
<
int
>
paddings
=
param
->
Paddings
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录