Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
3df6aa7e
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看板
提交
3df6aa7e
编写于
11月 14, 2019
作者:
C
chenjiaoAngel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update padding type int other devices, test=develop
上级
48ac4ca5
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
41 addition
and
29 deletion
+41
-29
lite/backends/fpga/KD/pes/pooling_pe.hpp
lite/backends/fpga/KD/pes/pooling_pe.hpp
+6
-4
lite/kernels/cuda/pool_compute.cu
lite/kernels/cuda/pool_compute.cu
+3
-2
lite/kernels/cuda/pool_compute_test.cc
lite/kernels/cuda/pool_compute_test.cc
+9
-6
lite/kernels/npu/bridges/pool_op.cc
lite/kernels/npu/bridges/pool_op.cc
+2
-1
lite/kernels/npu/bridges/pool_op_test.cc
lite/kernels/npu/bridges/pool_op_test.cc
+5
-3
lite/kernels/opencl/pool_compute.cc
lite/kernels/opencl/pool_compute.cc
+1
-1
lite/kernels/opencl/pool_compute_test.cc
lite/kernels/opencl/pool_compute_test.cc
+2
-1
lite/kernels/x86/pool_compute.h
lite/kernels/x86/pool_compute.h
+2
-3
lite/kernels/x86/pool_compute_test.cc
lite/kernels/x86/pool_compute_test.cc
+1
-1
lite/kernels/xpu/bridges/pool_op.cc
lite/kernels/xpu/bridges/pool_op.cc
+4
-3
lite/kernels/xpu/bridges/pool_op_test.cc
lite/kernels/xpu/bridges/pool_op_test.cc
+5
-3
lite/operators/pool_op.cc
lite/operators/pool_op.cc
+1
-1
未找到文件。
lite/backends/fpga/KD/pes/pooling_pe.hpp
浏览文件 @
3df6aa7e
...
...
@@ -45,13 +45,14 @@ class PoolingPE : public PE {
PoolingArgs
args
=
{
0
};
args
.
mode
=
param_
.
type
;
auto
paddings
=
*
param_
.
paddings
;
args
.
kernel_reciprocal
=
fp32_2_fp16
(
1.0
f
/
(
k_width
*
k_height
));
args
.
image
.
address
=
input
->
data
<
float16
>
();
args
.
image
.
channels
=
input
->
shape
().
channel
();
args
.
image
.
height
=
input
->
shape
().
height
();
args
.
image
.
width
=
input
->
shape
().
width
();
args
.
image
.
pad_height
=
pa
ram_
.
pa
ddings
[
0
];
args
.
image
.
pad_width
=
pa
ram_
.
pa
ddings
[
2
];
args
.
image
.
pad_height
=
paddings
[
0
];
args
.
image
.
pad_width
=
paddings
[
2
];
args
.
image
.
scale_address
=
input
->
scale
();
args
.
output
.
address
=
output
->
mutableData
<
float16
>
();
args
.
output
.
scale_address
=
output
->
scale
();
...
...
@@ -76,12 +77,13 @@ class PoolingPE : public PE {
float
*
image_addr
=
float_input
.
mutableData
<
float
>
(
FP32
,
input
->
shape
());
float_input
.
copyFrom
(
input
);
float16
*
data_out
=
output
->
data
<
float16
>
();
auto
paddings
=
*
param_
.
paddings
;
int
image_height
=
input
->
shape
().
height
();
int
image_width
=
input
->
shape
().
width
();
int
image_channels
=
input
->
shape
().
channel
();
int
image_pad_h
=
pa
ram_
.
pa
ddings
[
0
];
int
image_pad_w
=
pa
ram_
.
pa
ddings
[
2
];
int
image_pad_h
=
paddings
[
0
];
int
image_pad_w
=
paddings
[
2
];
int
kernel_height
=
param_
.
kernelSize
[
1
];
int
kernel_width
=
param_
.
kernelSize
[
0
];
int
kernel_step_h
=
param_
.
strides
[
0
];
...
...
lite/kernels/cuda/pool_compute.cu
浏览文件 @
3df6aa7e
...
...
@@ -256,6 +256,7 @@ void PoolCompute::Run() {
bool
adaptive
=
param
.
adaptive
;
auto
x_dims
=
param
.
x
->
dims
();
auto
out_dims
=
param
.
output
->
dims
();
auto
paddings
=
*
param
.
paddings
;
const
int
in_h
=
x_dims
[
2
];
const
int
in_w
=
x_dims
[
3
];
const
int
out_h
=
out_dims
[
2
];
...
...
@@ -266,8 +267,8 @@ void PoolCompute::Run() {
const
int
win_w
=
param
.
ksize
[
1
];
const
int
stride_h
=
param
.
strides
[
0
];
const
int
stride_w
=
param
.
strides
[
1
];
const
int
pad_h
=
pa
ram
.
pa
ddings
[
0
];
const
int
pad_w
=
pa
ram
.
pa
ddings
[
2
];
const
int
pad_h
=
paddings
[
0
];
const
int
pad_w
=
paddings
[
2
];
const
int
total_threads
=
out_dims
.
production
();
const
int
threads
=
512
;
const
int
blocks
=
(
total_threads
+
threads
-
1
)
/
threads
;
...
...
lite/kernels/cuda/pool_compute_test.cc
浏览文件 @
3df6aa7e
...
...
@@ -51,9 +51,10 @@ static std::vector<int64_t> compute_output_shape(operators::PoolParam* param_) {
std
::
vector
<
int
>&
ksize
=
param_
->
ksize
;
if
(
param_
->
global_pooling
)
{
ksize
.
resize
(
static_cast
<
size_t
>
(
x_dims
.
size
())
-
2
);
auto
paddings
=
*
param_
->
paddings
;
for
(
size_t
i
=
0
;
i
<
ksize
.
size
();
++
i
)
{
pa
ram_
->
pa
ddings
[
2
*
i
]
=
0
;
pa
ram_
->
pa
ddings
[
2
*
i
+
1
]
=
0
;
paddings
[
2
*
i
]
=
0
;
paddings
[
2
*
i
+
1
]
=
0
;
ksize
[
i
]
=
static_cast
<
int
>
(
x_dims
[
i
+
2
]);
}
}
...
...
@@ -66,8 +67,8 @@ static std::vector<int64_t> compute_output_shape(operators::PoolParam* param_) {
for
(
size_t
i
=
0
;
i
<
param_
->
ksize
.
size
();
++
i
)
{
output_shape
.
push_back
(
PoolOutputSize
(
x_dims
[
i
+
2
],
param_
->
ksize
[
i
],
pa
ram_
->
pa
ddings
[
2
*
i
],
pa
ram_
->
pa
ddings
[
2
*
i
+
1
],
paddings
[
2
*
i
],
paddings
[
2
*
i
+
1
],
param_
->
strides
[
i
],
param_
->
ceil_mode
));
}
...
...
@@ -84,7 +85,7 @@ static void pool_compute_ref(const operators::PoolParam& param) {
std
::
vector
<
int
>
ksize
=
param
.
ksize
;
std
::
vector
<
int
>
strides
=
param
.
strides
;
std
::
vector
<
int
>
paddings
=
param
.
paddings
;
std
::
vector
<
int
>
paddings
=
*
param
.
paddings
;
std
::
string
pooling_type
=
param
.
pooling_type
;
bool
global_pooling
=
param
.
global_pooling
;
...
...
@@ -235,7 +236,9 @@ TEST(pool_cuda, compute) {
}
param
.
global_pooling
=
global_pooling
;
param
.
strides
=
{
stride
,
stride
};
param
.
paddings
=
{
pad
,
pad
,
pad
,
pad
};
std
::
vector
<
int
>
paddings
=
{
pad
,
pad
,
pad
,
pad
};
param
.
paddings
=
std
::
make_shared
<
std
::
vector
<
int
>>
(
paddings
);
param
.
exclusive
=
exclusive
;
param
.
ceil_mode
=
ceil_mode
;
param
.
adaptive
=
false
;
...
...
lite/kernels/npu/bridges/pool_op.cc
浏览文件 @
3df6aa7e
...
...
@@ -47,7 +47,8 @@ node_map_type PoolConverter(const std::shared_ptr<lite::OpLite> pool_op,
auto
ksize
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"ksize"
);
auto
npu_window
=
ge
::
AttrValue
::
LIST_INT
(
ksize
.
begin
(),
ksize
.
end
());
auto
padding
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
);
auto
padding
=
*
(
op_info
->
GetAttr
<
std
::
shared_ptr
<
std
::
vector
<
int
>>>
(
"paddings"
));
bool
pads_equal
=
(
padding
[
0
]
==
padding
[
1
])
&&
(
padding
[
2
]
==
padding
[
3
]);
if
(
!
pads_equal
)
{
LOG
(
FATAL
)
...
...
lite/kernels/npu/bridges/pool_op_test.cc
浏览文件 @
3df6aa7e
...
...
@@ -39,7 +39,8 @@ void pool_ref(const std::shared_ptr<operators::PoolOpLite> op) {
std
::
vector
<
int
>
ksize
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
paddings
=
*
(
op_info
->
GetAttr
<
std
::
shared_ptr
<
std
::
vector
<
int
>>>
(
"paddings"
));
bool
exclusive
=
op_info
->
GetAttr
<
bool
>
(
"exclusive"
);
std
::
string
pooling_type
=
op_info
->
GetAttr
<
std
::
string
>
(
"pooling_type"
);
bool
global_pooling
=
op_info
->
GetAttr
<
bool
>
(
"global_pooling"
);
...
...
@@ -163,8 +164,9 @@ void test_pool(int bs,
opdesc
.
SetAttr
(
"global_pooling"
,
global_pooling
);
opdesc
.
SetAttr
(
"exclusive"
,
exclusive
);
opdesc
.
SetAttr
(
"strides"
,
std
::
vector
<
int
>
({
stride
,
stride
}));
opdesc
.
SetAttr
(
"paddings"
,
std
::
vector
<
int
>
({
padding
,
padding
,
padding
,
padding
}));
opdesc
.
SetAttr
(
"paddings"
,
std
::
shared_ptr
<
std
::
vector
<
int
>>
({
padding
,
padding
,
padding
,
padding
}));
// create and convert op to NPU model, then run it on NPU
auto
op
=
CreateOp
<
operators
::
PoolOpLite
>
(
opdesc
,
&
scope
);
...
...
lite/kernels/opencl/pool_compute.cc
浏览文件 @
3df6aa7e
...
...
@@ -44,7 +44,7 @@ class PoolCompute
const
auto
&
out_dims
=
param
.
output
->
dims
();
const
std
::
string
pooling_type
=
param
.
pooling_type
;
const
bool
global_pooling
=
param
.
global_pooling
;
std
::
vector
<
int
>
paddings
=
param
.
paddings
;
std
::
vector
<
int
>
paddings
=
*
param
.
paddings
;
std
::
vector
<
int
>
strides
=
param
.
strides
;
std
::
vector
<
int
>
ksize
=
param
.
ksize
;
if
(
global_pooling
)
{
...
...
lite/kernels/opencl/pool_compute_test.cc
浏览文件 @
3df6aa7e
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#include <gtest/gtest.h>
#include <memory>
#include <random>
#include "lite/backends/opencl/target_wrapper.h"
#include "lite/core/op_registry.h"
...
...
@@ -88,7 +89,7 @@ TEST(pool2d, compute) {
param
.
output
=
&
out
;
param
.
global_pooling
=
true
;
param
.
pooling_type
=
"avg"
;
param
.
paddings
=
std
::
vector
<
int
>
{
0
,
0
,
0
,
0
}
;
param
.
paddings
=
std
::
make_shared
<
std
::
vector
<
int
>>
({
0
,
0
,
0
,
0
})
;
param
.
strides
=
std
::
vector
<
int
>
{
1
,
1
};
param
.
ksize
=
std
::
vector
<
int
>
{
7
,
7
};
...
...
lite/kernels/x86/pool_compute.h
浏览文件 @
3df6aa7e
...
...
@@ -35,7 +35,6 @@ class PoolCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
auto
&
param
=
*
param_
.
get_mutable
<
param_t
>
();
if
(
param
.
global_pooling
)
{
for
(
size_t
i
=
0
;
i
<
param
.
ksize
.
size
();
++
i
)
{
param
.
paddings
[
i
]
=
0
;
param
.
ksize
[
i
]
=
static_cast
<
int
>
(
param
.
x
->
dims
()[
i
+
2
]);
}
}
...
...
@@ -52,7 +51,7 @@ class PoolCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
param
.
x
,
param
.
ksize
,
param
.
strides
,
param
.
paddings
,
*
param
.
paddings
,
pool_process
,
true
,
false
,
...
...
@@ -68,7 +67,7 @@ class PoolCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
param
.
x
,
param
.
ksize
,
param
.
strides
,
param
.
paddings
,
*
param
.
paddings
,
pool_process
,
param
.
exclusive
,
param
.
adaptive
,
...
...
lite/kernels/x86/pool_compute_test.cc
浏览文件 @
3df6aa7e
...
...
@@ -60,7 +60,7 @@ TEST(pool2d_x86, run_test) {
param
.
x
=
&
x
;
param
.
output
=
&
out
;
param
.
strides
=
{
2
,
2
};
param
.
paddings
=
{
0
,
0
,
0
,
0
}
;
param
.
paddings
=
std
::
make_shared
<
std
::
vector
<
int
>>
({
0
,
0
,
0
,
0
})
;
param
.
ksize
=
{
2
,
2
};
param
.
pooling_type
=
"max"
;
std
::
unique_ptr
<
KernelContext
>
ctx
(
new
KernelContext
);
...
...
lite/kernels/xpu/bridges/pool_op.cc
浏览文件 @
3df6aa7e
...
...
@@ -38,7 +38,8 @@ node_map_type PoolConverter(const std::shared_ptr<lite::OpLite> op,
auto
x_var_name
=
op_info
->
Input
(
"X"
).
front
();
auto
pooling_type
=
op_info
->
GetAttr
<
std
::
string
>
(
"pooling_type"
);
auto
ceil_mode
=
op_info
->
GetAttr
<
bool
>
(
"ceil_mode"
);
auto
paddings
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
);
auto
paddings
=
op_info
->
GetAttr
<
std
::
shared_ptr
<
std
::
vector
<
int
>>>
(
"paddings"
);
auto
global_pooling
=
op_info
->
GetAttr
<
bool
>
(
"global_pooling"
);
auto
ksize
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"ksize"
);
auto
strides
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"strides"
);
...
...
@@ -57,7 +58,7 @@ node_map_type PoolConverter(const std::shared_ptr<lite::OpLite> op,
graph_ctx
->
builder
->
CreateMaxPool2D
(
*
input_nodes
.
at
(
x_var_name
),
lite
::
xpu
::
CvtShape
(
ksize
),
lite
::
xpu
::
CvtShape
(
strides
),
lite
::
xpu
::
CvtShape
(
paddings
),
lite
::
xpu
::
CvtShape
(
*
paddings
),
"NCHW"
,
ceil_mode
));
}
...
...
@@ -72,7 +73,7 @@ node_map_type PoolConverter(const std::shared_ptr<lite::OpLite> op,
graph_ctx
->
builder
->
CreateAvgPool2D
(
*
input_nodes
.
at
(
x_var_name
),
lite
::
xpu
::
CvtShape
(
ksize
),
lite
::
xpu
::
CvtShape
(
strides
),
lite
::
xpu
::
CvtShape
(
paddings
),
lite
::
xpu
::
CvtShape
(
*
paddings
),
"NCHW"
,
ceil_mode
,
!
exclusive
));
...
...
lite/kernels/xpu/bridges/pool_op_test.cc
浏览文件 @
3df6aa7e
...
...
@@ -38,7 +38,8 @@ void pool_ref(const std::shared_ptr<operators::PoolOpLite> op) {
std
::
vector
<
int
>
ksize
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"ksize"
);
std
::
vector
<
int
>
strides
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"strides"
);
std
::
vector
<
int
>
paddings
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
paddings
=
*
(
op_info
->
GetAttr
<
std
::
shared_ptr
<
std
::
vector
<
int
>>>
(
"paddings"
));
bool
exclusive
=
op_info
->
GetAttr
<
bool
>
(
"exclusive"
);
std
::
string
pooling_type
=
op_info
->
GetAttr
<
std
::
string
>
(
"pooling_type"
);
bool
global_pooling
=
op_info
->
GetAttr
<
bool
>
(
"global_pooling"
);
...
...
@@ -162,8 +163,9 @@ void test_pool(int bs,
opdesc
.
SetAttr
(
"global_pooling"
,
global_pooling
);
opdesc
.
SetAttr
(
"exclusive"
,
exclusive
);
opdesc
.
SetAttr
(
"strides"
,
std
::
vector
<
int
>
({
stride
,
stride
}));
opdesc
.
SetAttr
(
"paddings"
,
std
::
vector
<
int
>
({
padding
,
padding
,
padding
,
padding
}));
opdesc
.
SetAttr
(
"paddings"
,
std
::
shared_ptr
<
std
::
vector
<
int
>>
({
padding
,
padding
,
padding
,
padding
}));
opdesc
.
SetAttr
(
"ceil_mode"
,
ceil_mode
);
// create and convert op to XPU model, then run it on XPU
...
...
lite/operators/pool_op.cc
浏览文件 @
3df6aa7e
...
...
@@ -35,7 +35,7 @@ bool PoolOpLite::CheckShape() const {
CHECK_OR_FALSE
(
x_dims
.
size
()
-
ksize
.
size
()
==
2U
);
// Strides size and pooling size should be the same.
CHECK_OR_FALSE
(
ksize
.
size
()
==
strides
.
size
());
// Paddings size
and pooling size should be the same
.
// Paddings size
must be 4
.
CHECK_OR_FALSE
(
paddings
.
size
()
==
4L
);
return
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录