Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
73bac0f2
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看板
提交
73bac0f2
编写于
5月 25, 2020
作者:
C
chenjiaoAngel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix conflict, test=develop
上级
40482334
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
254 addition
and
572 deletion
+254
-572
lite/backends/arm/math/pooling.cc
lite/backends/arm/math/pooling.cc
+169
-171
lite/backends/arm/math/pooling.h
lite/backends/arm/math/pooling.h
+42
-42
lite/backends/fpga/KD/pes/pooling_pe.hpp
lite/backends/fpga/KD/pes/pooling_pe.hpp
+1
-2
lite/kernels/arm/pool_compute.cc
lite/kernels/arm/pool_compute.cc
+42
-42
lite/kernels/npu/bridges/pool_op.cc
lite/kernels/npu/bridges/pool_op.cc
+0
-14
lite/kernels/xpu/bridges/pool_op_test.cc
lite/kernels/xpu/bridges/pool_op_test.cc
+0
-268
lite/operators/pool_op.cc
lite/operators/pool_op.cc
+0
-33
未找到文件。
lite/backends/arm/math/pooling.cc
浏览文件 @
73bac0f2
此差异已折叠。
点击以展开。
lite/backends/arm/math/pooling.h
浏览文件 @
73bac0f2
...
...
@@ -77,54 +77,54 @@ void pooling1x1s2p0_max(const float* din,
int
pad_right
);
void
pooling2x2s2p0_max
(
const
float
*
din
,
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
int
pad_bottom
,
int
pad_right
);
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
int
pad_bottom
,
int
pad_right
);
void
pooling2x2s2p0_avg
(
const
float
*
din
,
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
bool
exclusive
,
int
pad_bottom
,
int
pad_right
);
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
bool
exclusive
,
int
pad_bottom
,
int
pad_right
);
void
pooling2x2s2p1_max
(
const
float
*
din
,
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
int
pad_bottom
,
int
pad_right
);
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
int
pad_bottom
,
int
pad_right
);
void
pooling2x2s2p1_avg
(
const
float
*
din
,
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
bool
exclusive
,
int
pad_bottom
,
int
pad_right
);
float
*
dout
,
int
num
,
int
chout
,
int
hout
,
int
wout
,
int
chin
,
int
hin
,
int
win
,
bool
exclusive
,
int
pad_bottom
,
int
pad_right
);
void
pooling3x3s1p1_max
(
const
float
*
din
,
float
*
dout
,
...
...
lite/backends/fpga/KD/pes/pooling_pe.hpp
浏览文件 @
73bac0f2
...
...
@@ -70,8 +70,7 @@ class PoolingPE : public PE {
param_
.
poolingArgs
=
args
;
// use_cpu_ = output->shape().width() == 1 && output->shape().height() == 1
// &&
// (k_width > 7 || k_height > 7);
// && (k_width > 7 || k_height > 7);
use_cpu_
=
output
->
shape
().
width
()
==
1
&&
output
->
shape
().
height
()
==
1
&&
(
k_width
>
255
||
k_height
>
255
);
// use_cpu_ = param_.type == AVERAGE;
...
...
lite/kernels/arm/pool_compute.cc
浏览文件 @
73bac0f2
...
...
@@ -109,60 +109,60 @@ void PoolCompute::Run() {
kps_equal
)
{
if
(
pooling_type
==
"max"
)
{
lite
::
arm
::
math
::
pooling2x2s2p0_max
(
din
,
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
paddings
[
1
],
paddings
[
3
]);
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
paddings
[
1
],
paddings
[
3
]);
return
;
}
else
if
(
pooling_type
==
"avg"
)
{
lite
::
arm
::
math
::
pooling2x2s2p0_avg
(
din
,
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
exclusive
,
paddings
[
1
],
paddings
[
3
]);
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
exclusive
,
paddings
[
1
],
paddings
[
3
]);
return
;
}
}
else
if
(
ksize
[
0
]
==
2
&&
strides
[
0
]
==
2
&&
paddings
[
0
]
==
1
&&
kps_equal
)
{
if
(
pooling_type
==
"max"
)
{
lite
::
arm
::
math
::
pooling2x2s2p1_max
(
din
,
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
paddings
[
1
],
paddings
[
3
]);
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
paddings
[
1
],
paddings
[
3
]);
return
;
}
else
if
(
pooling_type
==
"avg"
)
{
lite
::
arm
::
math
::
pooling2x2s2p1_avg
(
din
,
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
exclusive
,
paddings
[
1
],
paddings
[
3
]);
dout
,
out_dims
[
0
],
out_dims
[
1
],
out_dims
[
2
],
out_dims
[
3
],
in_dims
[
1
],
in_dims
[
2
],
in_dims
[
3
],
exclusive
,
paddings
[
1
],
paddings
[
3
]);
return
;
}
}
else
if
(
ksize
[
0
]
==
3
&&
strides
[
0
]
==
1
&&
paddings
[
0
]
==
1
&&
...
...
lite/kernels/npu/bridges/pool_op.cc
浏览文件 @
73bac0f2
...
...
@@ -64,20 +64,6 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) {
return
FAILED
;
}
auto
padding
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
);
bool
pads_equal
=
(
padding
[
0
]
==
padding
[
1
])
&&
(
padding
[
2
]
==
padding
[
3
]);
if
(
!
pads_equal
)
{
LOG
(
FATAL
)
<<
"padding requires pad_left == pad_right, pad_top == pad_bottom"
;
}
auto
npu_pad
=
ge
::
AttrValue
::
LIST_INT
{
padding
[
0
],
padding
[
1
],
padding
[
2
],
padding
[
3
]};
auto
strides
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"strides"
);
auto
npu_stride
=
ge
::
AttrValue
::
LIST_INT
(
strides
.
begin
(),
strides
.
end
());
int
npu_ceil_mode
=
0
;
if
(
op_info
->
HasAttr
(
"ceil_mode"
))
{
npu_ceil_mode
=
op_info
->
GetAttr
<
bool
>
(
"ceil_mode"
)
?
1
:
0
;
// pad mode
int
pad_mode
=
0
;
std
::
string
padding_algorithm
(
""
);
...
...
lite/kernels/xpu/bridges/pool_op_test.cc
已删除
100644 → 0
浏览文件 @
40482334
// Copyright (c) 2019 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.
#include "lite/operators/pool_op.h"
#include <gtest/gtest.h>
#include "lite/core/op_registry.h"
#include "lite/kernels/xpu/bridges/registry.h"
#include "lite/kernels/xpu/bridges/test_helper.h"
namespace
paddle
{
namespace
lite
{
namespace
kernels
{
namespace
xpu
{
namespace
bridges
{
void
pool_ref
(
const
std
::
shared_ptr
<
operators
::
PoolOpLite
>
op
)
{
Scope
*
scope
=
op
->
scope
();
const
OpInfo
*
op_info
=
op
->
op_info
();
auto
x
=
scope
->
FindVar
(
op_info
->
Input
(
"X"
).
front
())
->
GetMutable
<
Tensor
>
();
auto
out
=
scope
->
FindVar
(
op_info
->
Output
(
"Out"
).
front
())
->
GetMutable
<
Tensor
>
();
auto
&
in_dims
=
x
->
dims
();
auto
&
out_dims
=
out
->
dims
();
const
float
*
src_ptr
=
x
->
data
<
const
float
>
();
float
*
dst_ptr
=
out
->
mutable_data
<
float
>
();
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"
);
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"
);
int
in_n
=
in_dims
[
0
];
int
in_c
=
in_dims
[
1
];
int
in_h
=
in_dims
[
2
];
int
in_w
=
in_dims
[
3
];
int
size_in_n
=
in_c
*
in_h
*
in_w
;
int
size_in_c
=
in_h
*
in_w
;
int
out_h
=
out_dims
[
2
];
int
out_w
=
out_dims
[
3
];
int
size_out_n
=
in_c
*
out_h
*
out_w
;
int
size_out_c
=
out_h
*
out_w
;
int
window_h
=
ksize
[
0
];
int
window_w
=
ksize
[
1
];
int
stride_h
=
strides
[
0
];
int
stride_w
=
strides
[
1
];
int
pad_h
=
paddings
[
0
];
int
pad_w
=
paddings
[
2
];
if
(
global_pooling
==
true
)
{
for
(
int
n
=
0
;
n
<
in_n
;
++
n
)
{
for
(
int
c
=
0
;
c
<
in_c
;
++
c
)
{
const
float
*
src
=
src_ptr
+
n
*
size_in_n
+
c
*
size_in_c
;
float
res
=
src
[
0
];
if
(
pooling_type
==
"max"
)
{
for
(
int
i
=
1
;
i
<
size_in_c
;
++
i
)
{
float
cur_val
=
src
[
i
];
res
=
cur_val
>
res
?
cur_val
:
res
;
}
}
else
if
(
pooling_type
==
"avg"
)
{
for
(
int
i
=
1
;
i
<
size_in_c
;
++
i
)
{
float
cur_val
=
src
[
i
];
res
+=
cur_val
;
}
res
/=
size_in_c
;
}
dst_ptr
[
n
*
size_out_n
+
c
]
=
res
;
}
}
}
else
{
for
(
int
n
=
0
;
n
<
in_n
;
++
n
)
{
for
(
int
c
=
0
;
c
<
in_c
;
++
c
)
{
for
(
int
h
=
0
;
h
<
out_h
;
++
h
)
{
int
sh
=
h
*
stride_h
;
int
eh
=
sh
+
window_h
;
sh
=
(
sh
-
pad_h
)
<
0
?
0
:
sh
-
pad_h
;
eh
=
(
eh
-
pad_h
)
>
in_h
?
in_h
:
eh
-
pad_h
;
for
(
int
w
=
0
;
w
<
out_w
;
++
w
)
{
int
sw
=
w
*
stride_w
;
int
ew
=
sw
+
window_w
;
sw
=
(
sw
-
pad_w
)
<
0
?
0
:
sw
-
pad_w
;
ew
=
(
ew
-
pad_w
)
>
in_w
?
in_w
:
ew
-
pad_w
;
int
pooling_size
=
(
ew
-
sw
)
*
(
eh
-
sh
);
if
(
pooling_size
==
0
)
continue
;
float
res
=
0.
f
;
for
(
int
kh
=
sh
;
kh
<
eh
;
++
kh
)
{
for
(
int
kw
=
sw
;
kw
<
ew
;
++
kw
)
{
int
src_idx
=
n
*
size_in_n
+
c
*
size_in_c
+
kh
*
in_w
+
kw
;
if
(
kh
==
sh
&&
kw
==
sw
)
{
res
=
src_ptr
[
src_idx
];
}
else
{
if
(
pooling_type
==
"max"
)
{
res
=
res
>=
src_ptr
[
src_idx
]
?
res
:
src_ptr
[
src_idx
];
}
if
(
pooling_type
==
"avg"
)
{
res
+=
src_ptr
[
src_idx
];
}
}
}
}
if
(
pooling_type
==
"avg"
)
{
if
(
exclusive
)
{
res
/=
pooling_size
;
}
else
{
res
/=
window_h
*
window_w
;
}
}
dst_ptr
[
n
*
size_out_n
+
c
*
size_out_c
+
h
*
out_w
+
w
]
=
res
;
}
}
}
}
}
}
void
test_pool
(
int
bs
,
int
ic
,
int
ih
,
int
iw
,
std
::
string
pooling_type
,
bool
ceil_mode
,
bool
global_pooling
,
bool
exclusive
,
int
ksize
,
int
stride
,
int
padding
)
{
// prepare input&output variables
Scope
scope
;
std
::
string
x_var_name
=
"x"
;
std
::
string
out_var_name
=
"out"
;
std
::
string
out_ref_var_name
=
"out_ref"
;
auto
*
x
=
scope
.
Var
(
x_var_name
)
->
GetMutable
<
Tensor
>
();
auto
*
out
=
scope
.
Var
(
out_var_name
)
->
GetMutable
<
Tensor
>
();
auto
*
out_ref
=
scope
.
Var
(
out_ref_var_name
)
->
GetMutable
<
Tensor
>
();
x
->
Resize
({
bs
,
ic
,
ih
,
iw
});
// initialize input&output data
FillTensor
<
float
>
(
x
);
// initialize op desc
cpp
::
OpDesc
opdesc
;
opdesc
.
SetType
(
"pool2d"
);
opdesc
.
SetInput
(
"X"
,
{
x_var_name
});
opdesc
.
SetOutput
(
"Out"
,
{
out_var_name
});
opdesc
.
SetAttr
(
"pooling_type"
,
pooling_type
);
opdesc
.
SetAttr
(
"ksize"
,
std
::
vector
<
int
>
({
ksize
,
ksize
}));
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
(
"ceil_mode"
,
ceil_mode
);
// create and convert op to XPU model, then run it on XPU
auto
op
=
CreateOp
<
operators
::
PoolOpLite
>
(
opdesc
,
&
scope
);
LauchOp
(
op
,
{
x_var_name
},
{
out_var_name
});
out_ref
->
CopyDataFrom
(
*
out
);
// execute reference implementation and save to output tensor
pool_ref
(
op
);
// compare results
auto
*
out_data
=
out
->
mutable_data
<
float
>
();
auto
*
out_ref_data
=
out_ref
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
out
->
dims
().
production
();
i
++
)
{
EXPECT_NEAR
(
out_data
[
i
],
out_ref_data
[
i
],
1e-5
);
}
}
TEST
(
XPUBridges
,
pool
)
{
for
(
auto
pooling_type
:
{
"max"
,
"avg"
})
{
for
(
auto
bs
:
{
1
,
3
})
{
for
(
auto
ic
:
{
2
})
{
for
(
auto
ih
:
{
3
})
{
for
(
auto
iw
:
{
4
})
{
test_pool
(
bs
,
ic
,
ih
,
iw
,
pooling_type
,
true
,
true
,
true
,
0
,
1
,
0
);
}
}
}
}
}
for
(
auto
pooling_type
:
{
"max"
})
{
for
(
auto
ceil_mode
:
{
true
,
false
})
{
for
(
auto
ksize
:
{
2
,
3
})
{
for
(
auto
stride
:
{
1
,
2
})
{
for
(
auto
padding
:
{
0
,
1
})
{
for
(
auto
bs
:
{
1
,
3
})
{
for
(
auto
ic
:
{
2
})
{
for
(
auto
ih
:
{
3
})
{
for
(
auto
iw
:
{
4
})
{
test_pool
(
bs
,
ic
,
ih
,
iw
,
pooling_type
,
ceil_mode
,
false
,
true
,
ksize
,
stride
,
padding
);
}
}
}
}
}
}
}
}
}
for
(
auto
pooling_type
:
{
"avg"
})
{
for
(
auto
ceil_mode
:
{
true
,
false
})
{
for
(
auto
exclusive
:
{
true
,
false
})
{
for
(
auto
ksize
:
{
2
,
3
})
{
for
(
auto
stride
:
{
1
,
2
})
{
for
(
auto
padding
:
{
0
,
1
})
{
for
(
auto
bs
:
{
1
,
3
})
{
for
(
auto
ic
:
{
2
})
{
for
(
auto
ih
:
{
3
})
{
for
(
auto
iw
:
{
4
})
{
test_pool
(
bs
,
ic
,
ih
,
iw
,
pooling_type
,
ceil_mode
,
false
,
exclusive
,
ksize
,
stride
,
padding
);
}
}
}
}
}
}
}
}
}
}
}
}
// namespace bridges
}
// namespace xpu
}
// namespace kernels
}
// namespace lite
}
// namespace paddle
USE_LITE_OP
(
pool2d
);
USE_XPU_BRIDGE
(
pool2d
);
lite/operators/pool_op.cc
浏览文件 @
73bac0f2
...
...
@@ -41,39 +41,6 @@ bool PoolOpLite::CheckShape() const {
return
true
;
}
inline
void
UpdatePadding
(
std
::
vector
<
int
>*
paddings
,
const
bool
global_pooling
,
const
bool
adaptive
,
const
std
::
string
padding_algorithm
,
const
lite
::
DDim
data_dims
,
const
std
::
vector
<
int
>&
strides
,
const
std
::
vector
<
int
>&
ksize
)
{
// when padding_algorithm is "VALID" or "SAME"
if
(
padding_algorithm
==
"SAME"
)
{
for
(
int
i
=
0
;
i
<
strides
.
size
();
++
i
)
{
int
out_size
=
(
data_dims
[
i
+
2
]
+
strides
[
i
]
-
1
)
/
strides
[
i
];
int
pad_sum
=
std
::
max
((
out_size
-
1
)
*
strides
[
i
]
+
ksize
[
i
]
-
data_dims
[
i
+
2
],
(
int64_t
)
0
);
int
pad_0
=
pad_sum
/
2
;
int
pad_1
=
pad_sum
-
pad_0
;
*
(
paddings
->
begin
()
+
i
*
2
)
=
pad_0
;
*
(
paddings
->
begin
()
+
i
*
2
+
1
)
=
pad_1
;
}
}
else
if
(
padding_algorithm
==
"VALID"
)
{
for
(
auto
it
=
paddings
->
begin
();
it
!=
paddings
->
end
();
it
++
)
{
*
it
=
0
;
}
}
// if global_pooling == true or adaptive == true, padding will be ignore
if
(
global_pooling
||
adaptive
)
{
for
(
auto
it
=
paddings
->
begin
();
it
!=
paddings
->
end
();
it
++
)
{
*
it
=
0
;
}
}
}
int
PoolOutputSize
(
int
input_size
,
int
filter_size
,
int
pad_left
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录