Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a06b812d
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看板
提交
a06b812d
编写于
8月 03, 2018
作者:
qnqinan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add fpga ops and kernels
上级
e7b06b70
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
523 addition
and
41 deletion
+523
-41
src/operators/dropout_op.cpp
src/operators/dropout_op.cpp
+1
-0
src/operators/dropout_op.h
src/operators/dropout_op.h
+1
-0
src/operators/fusion_elementwise_add_relu_op.cpp
src/operators/fusion_elementwise_add_relu_op.cpp
+42
-0
src/operators/fusion_elementwise_add_relu_op.h
src/operators/fusion_elementwise_add_relu_op.h
+61
-0
src/operators/fusion_fc_op.cpp
src/operators/fusion_fc_op.cpp
+1
-0
src/operators/fusion_fc_op.h
src/operators/fusion_fc_op.h
+1
-0
src/operators/fusion_fc_relu_op.cpp
src/operators/fusion_fc_relu_op.cpp
+27
-28
src/operators/fusion_fc_relu_op.h
src/operators/fusion_fc_relu_op.h
+22
-13
src/operators/kernel/elementwise_add_relu_kernel.h
src/operators/kernel/elementwise_add_relu_kernel.h
+38
-0
src/operators/kernel/fc_relu_kernel.h
src/operators/kernel/fc_relu_kernel.h
+36
-0
src/operators/kernel/fpga/dropout_kernel.cpp
src/operators/kernel/fpga/dropout_kernel.cpp
+40
-0
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
+62
-0
src/operators/kernel/fpga/fc_relu_kernel.cpp
src/operators/kernel/fpga/fc_relu_kernel.cpp
+66
-0
src/operators/kernel/fpga/fusion_fc_kernel.cpp
src/operators/kernel/fpga/fusion_fc_kernel.cpp
+66
-0
src/operators/kernel/fpga/pool_kernel.cpp
src/operators/kernel/fpga/pool_kernel.cpp
+57
-0
src/operators/pool_op.cpp
src/operators/pool_op.cpp
+1
-0
src/operators/pool_op.h
src/operators/pool_op.h
+1
-0
未找到文件。
src/operators/dropout_op.cpp
浏览文件 @
a06b812d
...
...
@@ -33,6 +33,7 @@ REGISTER_OPERATOR_CPU(dropout, ops::DropoutOp);
#ifdef PADDLE_MOBILE_MALI_GPU
#endif
#ifdef PADDLE_MOBILE_FPGA
REGISTER_OPERATOR_FPGA
(
dropout
,
ops
::
DropoutOp
);
#endif
#endif
src/operators/dropout_op.h
浏览文件 @
a06b812d
...
...
@@ -56,6 +56,7 @@ USE_OP_CPU(dropout);
#ifdef PADDLE_MOBILE_MALI_GPU
#endif
#ifdef PADDLE_MOBILE_FPGA
USE_OP_FPGA
(
dropout
);
#endif
#endif
src/operators/fusion_elementwise_add_relu_op.cpp
0 → 100644
浏览文件 @
a06b812d
/* 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 FUSION_ELEMENTWISEADDRELU_OP
#include "fusion_elementwise_add_relu_op.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
Dtype
,
typename
T
>
void
FusionElementwiseAddReluOp
<
Dtype
,
T
>::
InferShape
()
const
{
auto
x_dim
=
this
->
param_
.
InputX
()
->
dims
();
this
->
param_
.
Out
()
->
Resize
(
x_dim
);
}
}
// namespace operators
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
#ifdef PADDLE_MOBILE_CPU
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
);
#endif
#ifdef PADDLE_MOBILE_FPGA
REGISTER_OPERATOR_FPGA
(
fusion_elementwise_add_relu
,
ops
::
FusionElementwiseAddReluOp
);
#endif
#endif
src/operators/fusion_elementwise_add_relu_op.h
0 → 100644
浏览文件 @
a06b812d
/* 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 FUSION_ELEMENTWISEADDRELU_OP
#pragma once
#include <string>
#include "framework/operator.h"
#include "kernel/elementwise_add_relu_kernel.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
std
::
string
;
template
<
typename
DeviceType
,
typename
T
>
class
FusionElementwiseAddReluOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
,
ElementwiseAddReluParam
,
operators
::
ElementwiseAddReluKernel
<
DeviceType
,
T
>>
{
public:
FusionElementwiseAddReluOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorWithKernel
<
DeviceType
,
ElementwiseAddReluParam
,
operators
::
ElementwiseAddReluKernel
<
DeviceType
,
T
>>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
,
ElementwiseAddReluParam
,
operators
::
ElementwiseAddReluKernel
<
DeviceType
,
T
>>::
OperatorWithKernel
;
void
InferShape
()
const
override
;
protected:
};
}
// namespace operators
}
// namespace paddle_mobile
#ifdef PADDLE_MOBILE_CPU
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
src/operators/fusion_fc_op.cpp
浏览文件 @
a06b812d
...
...
@@ -61,6 +61,7 @@ REGISTER_OPERATOR_CPU(fusion_fc, ops::FusionFcOp);
REGISTER_OPERATOR_MALI_GPU
(
fusion_fc
,
ops
::
FusionFcOp
);
#endif
#ifdef PADDLE_MOBILE_FPGA
REGISTER_OPERATOR_FPGA
(
fusion_fc
,
ops
::
FusionFcOp
);
#endif
#endif
src/operators/fusion_fc_op.h
浏览文件 @
a06b812d
...
...
@@ -96,6 +96,7 @@ USE_OP_CPU(fusion_fc);
USE_OP_MALI_GPU
(
fusion_fc
);
#endif
#ifdef PADDLE_MOBILE_FPGA
USE_OP_FPGA
(
fusion_fc
);
#endif
#endif
src/operators/fusion_fc_relu_op.cpp
浏览文件 @
a06b812d
...
...
@@ -16,41 +16,41 @@ limitations under the License. */
#include "operators/fusion_fc_relu_op.h"
namespace
paddle_mobile
{
namespace
operators
{
namespace
operators
{
template
<
typename
Dtype
,
typename
T
>
void
FusionFcReluOp
<
Dtype
,
T
>::
InferShape
()
const
{
auto
x_dims
=
this
->
param_
.
InputX
()
->
dims
();
auto
y_dims
=
this
->
param_
.
InputY
()
->
dims
();
int
x_num_col_dims
=
this
->
param_
.
XNumColDims
();
int
y_num_col_dims
=
this
->
param_
.
YNumColDims
();
template
<
typename
Dtype
,
typename
T
>
void
FusionFcReluOp
<
Dtype
,
T
>::
InferShape
()
const
{
auto
x_dims
=
this
->
param_
.
InputX
()
->
dims
();
auto
y_dims
=
this
->
param_
.
InputY
()
->
dims
();
int
x_num_col_dims
=
this
->
param_
.
XNumColDims
();
int
y_num_col_dims
=
this
->
param_
.
YNumColDims
();
assert
(
x_dims
.
size
()
>
x_num_col_dims
);
assert
(
y_dims
.
size
()
>
y_num_col_dims
);
assert
(
x_dims
.
size
()
>
x_num_col_dims
);
assert
(
y_dims
.
size
()
>
y_num_col_dims
);
/// (1,2,3,4) , x_num_col_dims = 2 -> (2,12)
auto
x_mat_dims
=
framework
::
flatten_to_2d
(
x_dims
,
x_num_col_dims
);
auto
y_mat_dims
=
framework
::
flatten_to_2d
(
y_dims
,
y_num_col_dims
);
/// (1,2,3,4) , x_num_col_dims = 2 -> (2,12)
auto
x_mat_dims
=
framework
::
flatten_to_2d
(
x_dims
,
x_num_col_dims
);
auto
y_mat_dims
=
framework
::
flatten_to_2d
(
y_dims
,
y_num_col_dims
);
assert
(
x_mat_dims
[
1
]
==
y_mat_dims
[
0
]);
assert
(
x_mat_dims
[
1
]
==
y_mat_dims
[
0
]);
std
::
vector
<
int64_t
>
output_dims
;
output_dims
.
reserve
(
static_cast
<
size_t
>
(
x_num_col_dims
+
y_dims
.
size
()
-
y_num_col_dims
));
std
::
vector
<
int64_t
>
output_dims
;
output_dims
.
reserve
(
static_cast
<
size_t
>
(
x_num_col_dims
+
y_dims
.
size
()
-
y_num_col_dims
));
for
(
int
i
=
0
;
i
<
x_num_col_dims
;
++
i
)
{
output_dims
.
push_back
(
x_dims
[
i
]);
}
for
(
int
i
=
0
;
i
<
x_num_col_dims
;
++
i
)
{
output_dims
.
push_back
(
x_dims
[
i
]);
}
for
(
int
i
=
y_num_col_dims
;
i
<
y_dims
.
size
();
++
i
)
{
output_dims
.
push_back
(
y_dims
[
i
]);
}
for
(
int
i
=
y_num_col_dims
;
i
<
y_dims
.
size
();
++
i
)
{
output_dims
.
push_back
(
y_dims
[
i
]);
}
framework
::
DDim
ddim
=
framework
::
make_ddim
(
output_dims
);
this
->
param_
.
Out
()
->
Resize
(
ddim
);
}
framework
::
DDim
ddim
=
framework
::
make_ddim
(
output_dims
);
this
->
param_
.
Out
()
->
Resize
(
ddim
);
}
}
// namespace operators
}
// namespace operators
}
// namespace paddle_mobile
namespace
ops
=
paddle_mobile
::
operators
;
...
...
@@ -61,8 +61,7 @@ REGISTER_OPERATOR_CPU(fusion_fc_relu, ops::FusionFcReluOp);
REGISTER_OPERATOR_MALI_GPU
(
fusion_fc_relu
,
ops
::
FusionFcReluOp
);
#endif
#ifdef PADDLE_MOBILE_FPGA
REGISTER_OPERATOR_FPGA
(
fusion_fc_relu
,
ops
::
FusionFcReluOp
);
#endif
#endif
src/operators/fusion_fc_relu_op.h
浏览文件 @
a06b812d
...
...
@@ -11,7 +11,7 @@ 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 FUSION_FC
_
RELU_OP
#ifdef FUSION_FCRELU_OP
#pragma once
#include <string>
#include <vector>
...
...
@@ -43,17 +43,18 @@ class FusionFcReluMatcher : public framework::FusionOpMatcher {
};
template
<
typename
DeviceType
,
typename
T
>
class
FusionFcReluOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
,
FusionFcReluParam
,
operators
::
FusionFcReluKernel
<
DeviceType
,
T
>>
{
class
FusionFcReluOp
:
public
framework
::
OperatorWithKernel
<
DeviceType
,
FusionFcReluParam
,
operators
::
FusionFcReluKernel
<
DeviceType
,
T
>>
{
public:
FusionFcReluOp
(
const
string
&
type
,
const
VariableNameMap
&
inputs
,
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorWithKernel
<
DeviceType
,
FusionFcReluParam
,
operators
::
FusionFcReluKernel
<
DeviceType
,
T
>>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
const
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
,
std
::
shared_ptr
<
framework
::
Scope
>
scope
)
:
framework
::
OperatorWithKernel
<
DeviceType
,
FusionFcReluParam
,
operators
::
FusionFcReluKernel
<
DeviceType
,
T
>>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
using
framework
::
OperatorWithKernel
<
DeviceType
,
FusionFcReluParam
,
...
...
@@ -67,7 +68,8 @@ class FusionFcReluOp
#ifndef FUSION_FC_RELU_REGISTER
#define FUSION_FC_RELU_REGISTER
static
framework
::
FusionOpRegistrar
fc_relu_registrar
(
new
FusionFcReluMatcher
());
static
framework
::
FusionOpRegistrar
fc_relu_registrar
(
new
FusionFcReluMatcher
());
#endif
#endif
...
...
@@ -76,12 +78,18 @@ static framework::FusionOpRegistrar fc_relu_registrar(new FusionFcReluMatcher())
#ifndef FUSION_FC_RELU_REGISTER
#define FUSION_FC_RELU_REGISTER
static
framework
::
FusionOpRegistrar
fc_relu_registrar
(
new
FusionFcReluMatcher
());
static
framework
::
FusionOpRegistrar
fc_relu_registrar
(
new
FusionFcReluMatcher
());
#endif
#endif
#ifdef PADDLE_MOBILE_FPGA
#ifndef FUSION_FC_RELU_REGISTER
#define FUSION_FC_RELU_REGISTER
static
framework
::
FusionOpRegistrar
fc_relu_registrar
(
new
FusionFcReluMatcher
());
#endif
#endif
}
// namespace operators
...
...
@@ -94,5 +102,6 @@ USE_OP_CPU(fusion_fc_relu);
USE_OP_MALI_GPU
(
fusion_fc_relu
);
#endif
#ifdef PADDLE_MOBILE_FPGA
USE_OP_FPGA
(
fusion_fc_relu
);
#endif
#endif
//
FUSION_FC_RELU_OP
#endif
//
FUSION_FC_RELU_OP
src/operators/kernel/elementwise_add_relu_kernel.h
0 → 100644
浏览文件 @
a06b812d
/* 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 FUSION_ELEMENTWISEADDRELU_OP
#pragma once
#include "framework/operator.h"
#include "operators/math/elementwise_op_function.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
using
namespace
framework
;
template
<
typename
DeviceType
,
typename
T
>
class
ElementwiseAddReluKernel
:
public
framework
::
OpKernelBase
<
DeviceType
,
ElementwiseAddReluParam
>
{
public:
void
Compute
(
const
ElementwiseAddReluParam
&
param
)
const
;
bool
Init
(
ElementwiseAddReluParam
*
param
);
};
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/kernel/fc_relu_kernel.h
0 → 100644
浏览文件 @
a06b812d
/* 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 FUSION_FCRELU_OP
#pragma once
#include "framework/operator.h"
#include "operators/math/math_function.h"
#include "operators/op_param.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
typename
DeviceType
,
typename
T
>
class
FusionFcReluKernel
:
public
framework
::
OpKernelBase
<
DeviceType
,
FusionFcReluParam
>
{
public:
void
Compute
(
const
FusionFcReluParam
&
param
)
const
;
bool
Init
(
FusionFcReluParam
*
param
);
};
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/kernel/fpga/dropout_kernel.cpp
0 → 100644
浏览文件 @
a06b812d
/* 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 DROPOUT_OP
#include "operators/kernel/dropout_kernel.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
bool
DropoutKernel
<
FPGA
,
float
>::
Init
(
DropoutParam
*
param
)
{
param
->
Out
()
->
ShareDataWith
(
*
param
->
InputX
());
return
true
;
}
template
<
>
void
DropoutKernel
<
FPGA
,
float
>::
Compute
(
const
DropoutParam
&
param
)
const
{
//auto *input_x = param.InputX();
//auto *out = param.Out();
//auto input_x_ptr = input_x->data<float>();
//auto out_ptr = out->mutable_data<float>();
//out_ptr = const_cast<float *>(input_x_ptr);
}
}
// namespace operators
}
// namespace paddle_mobile
#endif
src/operators/kernel/fpga/elementwise_add_relu_kernel.cpp
0 → 100644
浏览文件 @
a06b812d
/* 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 FUSION_ELEMENTWISEADDRELU_OP
#include "operators/kernel/elementwise_add_relu_kernel.h"
#include "fpga/api/fpga_api.h"
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
bool
ElementwiseAddReluKernel
<
FPGA
,
float
>::
Init
(
ElementwiseAddReluParam
*
param
)
{
bool
relu_enabled
=
true
;
const
Tensor
*
input_x
=
param
->
InputX
();
const
Tensor
*
input_y
=
param
->
InputY
();
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
>
();
fpga
::
EWAddArgs
ewaddArgs
;
ewaddArgs
.
relu_enabled
=
relu_enabled
;
ewaddArgs
.
const0
=
1
;
ewaddArgs
.
const1
=
1
;
ewaddArgs
.
image0
.
address
=
(
void
*
)
input_x_ptr
;
ewaddArgs
.
image0
.
channels
=
input_x
->
dims
()[
1
];
ewaddArgs
.
image0
.
scale_address
=
nullptr
;
//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
.
image1
.
address
=
(
void
*
)
input_y_ptr
;
ewaddArgs
.
image1
.
channels
=
input_y
->
dims
()[
1
];
ewaddArgs
.
image1
.
scale_address
=
nullptr
;
//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
.
output
.
scale_address
=
nullptr
;
ewaddArgs
.
output
.
address
=
(
void
*
)
out_ptr
;
param
->
SetFpgaArgs
(
ewaddArgs
);
return
true
;
}
template
<
>
void
ElementwiseAddReluKernel
<
FPGA
,
float
>::
Compute
(
const
ElementwiseAddReluParam
&
param
)
const
{
fpga
::
ComputeFpgaEWAdd
(
param
.
FpgaArgs
());
}
}
// namespace operators
}
// namespace paddle_mobile
#endif
\ No newline at end of file
src/operators/kernel/fpga/fc_relu_kernel.cpp
0 → 100644
浏览文件 @
a06b812d
/* 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 FUSION_FCRELU_OP
#include "operators/kernel/fc_relu_kernel.h"
#include "fpga/api/fpga_api.h"
namespace
paddle_mobile
{
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
();
auto
input_y_ptr
=
input_y
->
data
<
float
>
();
const
Tensor
*
input_z
=
param
->
InputZ
();
auto
input_z_ptr
=
input_z
->
data
<
float
>
();
Tensor
*
out
=
param
->
Out
();
auto
out_ptr
=
out
->
mutable_data
<
float
>
();
fpga
::
ConvArgs
convArgs
;
convArgs
.
relu_enabled
=
relu_enabled
;
convArgs
.
bias_address
=
(
void
*
)
input_z_ptr
;
convArgs
.
filter_address
=
(
void
*
)
input_y_ptr
;
convArgs
.
filter_num
=
out
->
dims
()[
1
];
convArgs
.
group_num
=
1
;
convArgs
.
bn
.
enabled
=
bn_enabled
;
convArgs
.
kernel
.
stride_w
=
1
;
convArgs
.
kernel
.
stride_h
=
1
;
convArgs
.
kernel
.
height
=
input_x
->
dims
()[
2
];
convArgs
.
kernel
.
width
=
input_x
->
dims
()[
3
];
convArgs
.
image
.
address
=
(
void
*
)
input_x_ptr
;
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
.
scale_address
=
nullptr
;
//fc input has scale attribute??
convArgs
.
output
.
address
=
(
void
*
)
out_ptr
;
convArgs
.
output
.
scale_address
=
nullptr
;
//fc output has scale attribute??
param
->
SetFpgaArgs
(
convArgs
);
return
true
;
}
template
<
>
void
FusionFcReluKernel
<
FPGA
,
float
>::
Compute
(
const
FusionFcReluParam
&
param
)
const
{
fpga
::
ComputeFpgaConv
(
param
.
FpgaArgs
());
};
}
// namespace operators
}
// namespace paddle_mobile
#endif
\ No newline at end of file
src/operators/kernel/fpga/fusion_fc_kernel.cpp
0 → 100644
浏览文件 @
a06b812d
/* 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 FUSION_FC_OP
#include "operators/kernel/fusion_fc_kernel.h"
namespace
paddle_mobile
{
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
();
auto
input_y_ptr
=
input_y
->
data
<
float
>
();
const
Tensor
*
input_z
=
param
->
InputZ
();
auto
input_z_ptr
=
input_z
->
data
<
float
>
();
Tensor
*
out
=
param
->
Out
();
auto
out_ptr
=
out
->
mutable_data
<
float
>
();
fpga
::
ConvArgs
convArgs
;
convArgs
.
relu_enabled
=
relu_enabled
;
convArgs
.
bias_address
=
(
void
*
)
input_z_ptr
;
convArgs
.
filter_address
=
(
void
*
)
input_y_ptr
;
convArgs
.
filter_num
=
out
->
dims
()[
1
];
convArgs
.
group_num
=
1
;
convArgs
.
bn
.
enabled
=
bn_enabled
;
convArgs
.
kernel
.
stride_w
=
1
;
convArgs
.
kernel
.
stride_h
=
1
;
convArgs
.
kernel
.
height
=
input_x
->
dims
()[
2
];
convArgs
.
kernel
.
width
=
input_x
->
dims
()[
3
];
convArgs
.
image
.
address
=
(
void
*
)
input_x_ptr
;
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
.
scale_address
=
nullptr
;
//fc input has scale attribute??
convArgs
.
output
.
address
=
(
void
*
)
out_ptr
;
convArgs
.
output
.
scale_address
=
nullptr
;
//fc output has scale attribute??
param
->
SetFpgaArgs
(
convArgs
);
return
true
;
}
template
<
>
void
FusionFcKernel
<
FPGA
,
float
>::
Compute
(
const
FusionFcParam
&
param
)
const
{
fpga
::
ComputeFpgaConv
(
param
.
FpgaArgs
());
}
}
// namespace operators
}
// namespace paddle_mobile
#endif
\ No newline at end of file
src/operators/kernel/fpga/pool_kernel.cpp
0 → 100644
浏览文件 @
a06b812d
/* 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 POOL_OP
#include "operators/kernel/pool_kernel.h"
#include "fpga/api/fpga_api.h"
class
PoolingArgs
;
namespace
paddle_mobile
{
namespace
operators
{
template
<
>
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
>
();
vector
<
int
>
ksize
=
param
->
Ksize
();
vector
<
int
>
strides
=
param
->
Strides
();
vector
<
int
>
paddings
=
param
->
Paddings
();
fpga
::
PoolingArgs
poolArgs
;
poolArgs
.
image
.
address
=
(
void
*
)
input_ptr
;
poolArgs
.
image
.
channels
=
input
->
dims
()[
1
];
poolArgs
.
image
.
height
=
input
->
dims
()[
2
];
poolArgs
.
image
.
width
=
input
->
dims
()[
3
];
poolArgs
.
image
.
pad_height
=
paddings
[
0
];
poolArgs
.
image
.
pad_width
=
paddings
[
1
];
poolArgs
.
output
.
address
=
output_ptr
;
poolArgs
.
kernel
.
height
=
ksize
[
0
];
poolArgs
.
kernel
.
width
=
ksize
[
1
];
poolArgs
.
kernel
.
stride_h
=
strides
[
0
];
poolArgs
.
kernel
.
stride_w
=
strides
[
1
];
param
->
SetFpgaArgs
(
poolArgs
);
return
true
;
}
template
<
>
void
PoolKernel
<
FPGA
,
float
>::
Compute
(
const
PoolParam
&
param
)
const
{
#ifdef PADDLE_MOBILE_FPGA
fpga
::
ComputeFpgaPool
(
param
.
FpgaArgs
());
#endif
}
}
// namespace operators
}
// namespace paddle_mobile
#endif
\ No newline at end of file
src/operators/pool_op.cpp
浏览文件 @
a06b812d
...
...
@@ -66,6 +66,7 @@ REGISTER_OPERATOR_CPU(pool2d, ops::PoolOp);
REGISTER_OPERATOR_MALI_GPU
(
pool2d
,
ops
::
PoolOp
);
#endif
#ifdef PADDLE_MOBILE_FPGA
REGISTER_OPERATOR_FPGA
(
pool2d
,
ops
::
PoolOp
);
#endif
#endif
src/operators/pool_op.h
浏览文件 @
a06b812d
...
...
@@ -55,6 +55,7 @@ USE_OP_CPU(pool2d);
USE_OP_MALI_GPU
(
pool2d
);
#endif
#ifdef PADDLE_MOBILE_FPGA
USE_OP_FPGA
(
pool2d
);
#endif
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录