Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
86cb0443
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看板
提交
86cb0443
编写于
7月 11, 2018
作者:
W
WangLiu
提交者:
GitHub
7月 11, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #553 from cocodark/develop
accelerate with openmp
上级
2557bd23
7df896bf
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
171 addition
and
131 deletion
+171
-131
CMakeLists.txt
CMakeLists.txt
+1
-1
src/io/executor.cpp
src/io/executor.cpp
+12
-0
src/io/executor.h
src/io/executor.h
+2
-0
src/operators/kernel/lrn_kernel.h
src/operators/kernel/lrn_kernel.h
+4
-1
src/operators/math/pool_3x3.cpp
src/operators/math/pool_3x3.cpp
+139
-121
src/operators/math/pool_3x3.h
src/operators/math/pool_3x3.h
+4
-1
src/operators/math/pooling.cpp
src/operators/math/pooling.cpp
+5
-4
test/net/test_googlenet.cpp
test/net/test_googlenet.cpp
+4
-3
未找到文件。
CMakeLists.txt
浏览文件 @
86cb0443
...
...
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
project
(
paddle-mobile
)
option
(
DEBUGING
"enable debug mode"
ON
)
option
(
USE_OPENMP
"openmp support"
O
FF
)
option
(
USE_OPENMP
"openmp support"
O
N
)
option
(
USE_EXCEPTION
"use std exception"
ON
)
option
(
LOG_PROFILE
"log profile"
ON
)
# select the platform to build
...
...
src/io/executor.cpp
浏览文件 @
86cb0443
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "io/executor.h"
#include <operators/math/gemm.h>
#include <algorithm>
#include <vector>
#include "common/enforce.h"
...
...
@@ -25,6 +26,9 @@ limitations under the License. */
#include "framework/program/var_desc.h"
#include "framework/scope.h"
#include "framework/tensor.h"
#ifdef _OPENMP
#include <omp.h>
#endif // _OPENMP
#ifdef PADDLE_EXECUTOR_MULTITHREAD
#include <queue>
#include <utility>
...
...
@@ -403,6 +407,14 @@ std::vector<typename Executor<Dtype, P>::Ptype> Executor<Dtype, P>::Predict(
return
result_vector
;
}
template
<
typename
Dtype
,
Precision
P
>
void
Executor
<
Dtype
,
P
>::
SetThreadNum
(
int
num
)
{
#ifdef _OPENMP
// omp_set_dynamic(0);
omp_set_num_threads
(
num
);
#endif
}
template
class
Executor
<
CPU
,
Precision
::
FP32
>;
template
class
Executor
<
FPGA
,
Precision
::
FP32
>;
template
class
Executor
<
GPU_MALI
,
Precision
::
FP32
>;
...
...
src/io/executor.h
浏览文件 @
86cb0443
...
...
@@ -58,6 +58,8 @@ class Executor {
std
::
vector
<
Ptype
>
Predict
(
const
std
::
vector
<
Ptype
>
&
input
,
const
std
::
vector
<
int64_t
>
&
dims
);
void
SetThreadNum
(
int
num
);
protected:
Executor
()
=
default
;
void
InitMemory
();
...
...
src/operators/kernel/lrn_kernel.h
浏览文件 @
86cb0443
...
...
@@ -13,7 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License. */
#ifdef LRN_OP
#ifdef _OPENMP
#include <omp.h>
#endif
#include "framework/operator.h"
#include "operators/op_param.h"
...
...
@@ -47,6 +49,7 @@ struct LRNFunctor {
std
::
fill
(
sqr_buffer_ptr
,
sqr_buffer_ptr
+
sqr_buffer
.
numel
(),
0.0
);
for
(
int
a
=
0
;
a
<
N
;
a
++
)
{
#pragma parallel for
for
(
int
b
=
0
;
b
<
C
;
b
++
)
{
for
(
int
index
=
start
;
index
<
end
;
index
++
)
{
int
channel
=
b
+
index
;
...
...
src/operators/math/pool_3x3.cpp
浏览文件 @
86cb0443
...
...
@@ -13,8 +13,11 @@ See the License for the specific language governing permissions and
limitations under the License. */
#ifdef POOL_OP
#include "operators/math/pool_3x3.h"
#ifdef _OPENMP
#include <omp.h>
#endif
#include "framework/tensor.h"
#include "pool_3x3.h"
#if __ARM_NEON
#include <arm_neon.h>
#endif // __ARM_NEON
...
...
@@ -40,46 +43,52 @@ void Pool3x3Avgs1p1(const Tensor *input, Tensor *output) {
const
int
w_out
=
output
->
dims
()[
3
];
const
int
outputdata_channel_stride
=
h_out
*
w_out
;
const
int
inputdata_channel_stride
=
h_in
*
w_in
;
const
int
input_batch_stride
=
output_channels
*
inputdata_channel_stride
;
const
int
output_batch_stride
=
output_channels
*
outputdata_channel_stride
;
float
*
out_data
=
output
->
data
<
float
>
();
const
float
*
input_data
=
input
->
data
<
float
>
();
const
float
coef
=
1.0
/
9.0
;
for
(
int
k
=
0
;
k
<
batch_size
;
++
k
)
{
#pragma omp parallel for
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
const
float
*
input_seg
=
input_data
+
c
*
inputdata_channel_stride
;
float
*
output_seg
=
out_data
+
c
*
outputdata_channel_stride
;
// four corner point
out
_data
[
0
]
=
(
input_data
[
0
]
+
input_data
[
1
]
+
input_data
[
w_in
]
+
input_data
[
w_in
+
1
])
*
out
put_seg
[
0
]
=
(
input_seg
[
0
]
+
input_seg
[
1
]
+
input_seg
[
w_in
]
+
input_seg
[
w_in
+
1
])
*
coef
;
out
_data
[
w_out
-
1
]
=
(
input_
data
[
w_in
-
2
]
+
input_data
[
w_in
-
1
]
+
input_
data
[
w_in
*
2
-
2
]
+
input_data
[
2
*
w_in
-
1
])
*
out
put_seg
[
w_out
-
1
]
=
(
input_
seg
[
w_in
-
2
]
+
input_seg
[
w_in
-
1
]
+
input_seg
[
w_in
*
2
-
2
]
+
input_
seg
[
2
*
w_in
-
1
])
*
coef
;
out
_data
[(
h_out
-
1
)
*
w_out
]
=
(
input_
data
[(
h_in
-
2
)
*
w_in
]
+
input_data
[(
h_in
-
2
)
*
w_in
+
1
]
+
input_
data
[(
h_in
-
1
)
*
w_in
]
+
input_data
[(
h_in
-
1
)
*
w_in
+
1
])
*
out
put_seg
[(
h_out
-
1
)
*
w_out
]
=
(
input_
seg
[(
h_in
-
2
)
*
w_in
]
+
input_seg
[(
h_in
-
2
)
*
w_in
+
1
]
+
input_
seg
[(
h_in
-
1
)
*
w_in
]
+
input_seg
[(
h_in
-
1
)
*
w_in
+
1
])
*
coef
;
out
_data
[
h_out
*
w_out
-
1
]
=
(
input_
data
[
h_in
*
w_in
-
1
]
+
input_data
[
h_in
*
w_in
-
2
]
+
input_
data
[(
h_in
-
1
)
*
w_in
-
1
]
+
input_
data
[(
h_in
-
1
)
*
w_in
-
2
])
*
out
put_seg
[
h_out
*
w_out
-
1
]
=
(
input_
seg
[
h_in
*
w_in
-
1
]
+
input_seg
[
h_in
*
w_in
-
2
]
+
input_
seg
[(
h_in
-
1
)
*
w_in
-
1
]
+
input_
seg
[(
h_in
-
1
)
*
w_in
-
2
])
*
coef
;
// left side & right side
for
(
int
i
=
1
;
i
<
h_in
-
1
;
++
i
)
{
out
_data
[
i
*
w_out
]
=
(
input_
data
[
i
*
w_in
-
w_in
]
+
input_data
[
i
*
w_in
-
w_in
+
1
]
+
input_
data
[
i
*
w_in
]
+
input_data
[
i
*
w_in
+
1
]
+
input_
data
[
i
*
w_in
+
w_in
]
+
input_data
[
i
*
w_in
+
w_in
+
1
])
*
out
put_seg
[
i
*
w_out
]
=
(
input_
seg
[
i
*
w_in
-
w_in
]
+
input_seg
[
i
*
w_in
-
w_in
+
1
]
+
input_
seg
[
i
*
w_in
]
+
input_seg
[
i
*
w_in
+
1
]
+
input_
seg
[
i
*
w_in
+
w_in
]
+
input_seg
[
i
*
w_in
+
w_in
+
1
])
*
coef
;
out
_data
[
i
*
w_out
+
w_out
-
1
]
=
(
input_
data
[
i
*
w_in
-
w_in
+
w_in
-
2
]
+
input_
data
[
i
*
w_in
-
w_in
+
1
+
w_in
-
2
]
+
input_
data
[
i
*
w_in
+
w_in
-
2
]
+
input_
data
[
i
*
w_in
+
1
+
w_in
-
2
]
+
input_
data
[
i
*
w_in
+
w_in
+
w_in
-
2
]
+
input_
data
[
i
*
w_in
+
w_in
+
1
+
w_in
-
2
])
*
out
put_seg
[
i
*
w_out
+
w_out
-
1
]
=
(
input_
seg
[
i
*
w_in
-
w_in
+
w_in
-
2
]
+
input_
seg
[
i
*
w_in
-
w_in
+
1
+
w_in
-
2
]
+
input_
seg
[
i
*
w_in
+
w_in
-
2
]
+
input_
seg
[
i
*
w_in
+
1
+
w_in
-
2
]
+
input_
seg
[
i
*
w_in
+
w_in
+
w_in
-
2
]
+
input_
seg
[
i
*
w_in
+
w_in
+
1
+
w_in
-
2
])
*
coef
;
}
// top 1 row & bottom 1 row
const
float
*
input_tmp
=
input_
data
;
const
float
*
input_tmp
=
input_
seg
;
float32x4_t
in0
,
in1
,
in2
,
in3
,
in4
,
in5
,
in6
,
in7
,
tmp0
,
tmp1
,
tmp2
,
tmp3
,
tmp4
,
tmp5
,
sum
,
out0
;
...
...
@@ -90,7 +99,7 @@ void Pool3x3Avgs1p1(const Tensor *input, Tensor *output) {
in4
=
vld1q_f32
(
input_tmp_end
);
in6
=
vld1q_f32
(
input_tmp_end
+
w_in
);
int
c_mid
=
w_out
-
2
;
auto
output_ptr
=
out
_data
+
1
;
auto
output_ptr
=
out
put_seg
+
1
;
for
(;
c_mid
>
3
;
c_mid
-=
4
)
{
in1
=
vld1q_f32
(
input_tmp
+
4
);
in3
=
vld1q_f32
(
input_tmp
+
w_in
+
4
);
...
...
@@ -135,8 +144,8 @@ void Pool3x3Avgs1p1(const Tensor *input, Tensor *output) {
in6
=
in7
;
}
// top right remain
float32x4_t
pad0
=
vdupq_n_f32
(
input_
data
[
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
data
[
2
*
w_in
-
1
]);
float32x4_t
pad0
=
vdupq_n_f32
(
input_
seg
[
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
seg
[
2
*
w_in
-
1
]);
tmp0
=
vextq_f32
(
in0
,
pad0
,
1
);
tmp1
=
vextq_f32
(
in0
,
pad0
,
2
);
...
...
@@ -163,8 +172,8 @@ void Pool3x3Avgs1p1(const Tensor *input, Tensor *output) {
}
// bottom_right remain
float32x4_t
pad2
=
vdupq_n_f32
(
input_
data
[(
h_in
-
1
)
*
w_in
-
1
]);
float32x4_t
pad3
=
vdupq_n_f32
(
input_
data
[
h_in
*
w_in
-
1
]);
float32x4_t
pad2
=
vdupq_n_f32
(
input_
seg
[(
h_in
-
1
)
*
w_in
-
1
]);
float32x4_t
pad3
=
vdupq_n_f32
(
input_
seg
[
h_in
*
w_in
-
1
]);
tmp0
=
vextq_f32
(
in4
,
pad2
,
1
);
tmp1
=
vextq_f32
(
in4
,
pad2
,
2
);
...
...
@@ -191,8 +200,8 @@ void Pool3x3Avgs1p1(const Tensor *input, Tensor *output) {
}
// mid
for
(
int
j
=
0
;
j
<
h_out
-
2
;
++
j
)
{
output_ptr
=
out
_data
+
w_out
*
(
j
+
1
)
+
1
;
input_tmp
=
input_
data
+
j
*
w_in
;
output_ptr
=
out
put_seg
+
w_out
*
(
j
+
1
)
+
1
;
input_tmp
=
input_
seg
+
j
*
w_in
;
in0
=
vld1q_f32
(
input_tmp
);
in2
=
vld1q_f32
(
input_tmp
+
w_in
);
...
...
@@ -228,9 +237,9 @@ void Pool3x3Avgs1p1(const Tensor *input, Tensor *output) {
in4
=
in5
;
}
// mid remain
float32x4_t
pad0
=
vdupq_n_f32
(
input_
data
[(
j
+
1
)
*
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
data
[(
j
+
2
)
*
w_in
-
1
]);
float32x4_t
pad2
=
vdupq_n_f32
(
input_
data
[(
j
+
2
)
*
w_in
-
1
]);
float32x4_t
pad0
=
vdupq_n_f32
(
input_
seg
[(
j
+
1
)
*
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
seg
[(
j
+
2
)
*
w_in
-
1
]);
float32x4_t
pad2
=
vdupq_n_f32
(
input_
seg
[(
j
+
2
)
*
w_in
-
1
]);
tmp0
=
vextq_f32
(
in0
,
pad0
,
1
);
tmp1
=
vextq_f32
(
in0
,
pad0
,
2
);
...
...
@@ -261,9 +270,11 @@ void Pool3x3Avgs1p1(const Tensor *input, Tensor *output) {
}
}
}
input_data
+=
inputdata_channel_stride
;
out_data
+=
outputdata_channel_stride
;
//
input_data += inputdata_channel_stride;
//
out_data += outputdata_channel_stride;
}
input_data
+=
input_batch_stride
;
out_data
+=
output_batch_stride
;
}
#endif
}
...
...
@@ -282,44 +293,50 @@ void Pool3x3Maxs1p1(const Tensor *input, Tensor *output) {
const
int
w_out
=
output
->
dims
()[
3
];
const
int
outputdata_channel_stride
=
h_out
*
w_out
;
const
int
inputdata_channel_stride
=
h_in
*
w_in
;
const
int
input_batch_stride
=
output_channels
*
inputdata_channel_stride
;
const
int
output_batch_stride
=
output_channels
*
outputdata_channel_stride
;
float
*
out_data
=
output
->
data
<
float
>
();
const
float
*
input_data
=
input
->
data
<
float
>
();
for
(
int
k
=
0
;
k
<
batch_size
;
++
k
)
{
#pragma omp parallel for
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
const
float
*
input_seg
=
input_data
+
c
*
inputdata_channel_stride
;
float
*
output_seg
=
out_data
+
c
*
outputdata_channel_stride
;
// four corner point
out
_data
[
0
]
=
std
::
max
(
std
::
max
(
input_data
[
0
],
input_data
[
1
]),
std
::
max
(
input_data
[
w_in
],
input_data
[
w_in
+
1
]));
out
_data
[
w_out
-
1
]
=
std
::
max
(
std
::
max
(
input_data
[
w_in
-
2
],
input_data
[
w_in
-
1
]),
std
::
max
(
input_data
[
w_in
*
2
-
2
],
input_data
[
2
*
w_in
-
1
]));
out
_data
[(
h_out
-
1
)
*
w_out
]
=
std
::
max
(
std
::
max
(
input_
data
[(
h_in
-
2
)
*
w_in
],
input_
data
[(
h_in
-
2
)
*
w_in
+
1
]),
std
::
max
(
input_
data
[(
h_in
-
1
)
*
w_in
],
input_
data
[(
h_in
-
1
)
*
w_in
+
1
]));
out
_data
[
h_out
*
w_out
-
1
]
=
std
::
max
(
std
::
max
(
input_
data
[(
h_in
-
1
)
*
w_in
-
1
],
input_
data
[(
h_in
-
1
)
*
w_in
-
2
]),
std
::
max
(
input_
data
[
h_in
*
w_in
-
1
],
input_data
[
h_in
*
w_in
-
2
]));
out
put_seg
[
0
]
=
std
::
max
(
std
::
max
(
input_seg
[
0
],
input_seg
[
1
]),
std
::
max
(
input_seg
[
w_in
],
input_seg
[
w_in
+
1
]));
out
put_seg
[
w_out
-
1
]
=
std
::
max
(
std
::
max
(
input_seg
[
w_in
-
2
],
input_seg
[
w_in
-
1
]),
std
::
max
(
input_seg
[
w_in
*
2
-
2
],
input_seg
[
2
*
w_in
-
1
]));
out
put_seg
[(
h_out
-
1
)
*
w_out
]
=
std
::
max
(
std
::
max
(
input_
seg
[(
h_in
-
2
)
*
w_in
],
input_
seg
[(
h_in
-
2
)
*
w_in
+
1
]),
std
::
max
(
input_
seg
[(
h_in
-
1
)
*
w_in
],
input_
seg
[(
h_in
-
1
)
*
w_in
+
1
]));
out
put_seg
[
h_out
*
w_out
-
1
]
=
std
::
max
(
std
::
max
(
input_
seg
[(
h_in
-
1
)
*
w_in
-
1
],
input_
seg
[(
h_in
-
1
)
*
w_in
-
2
]),
std
::
max
(
input_
seg
[
h_in
*
w_in
-
1
],
input_seg
[
h_in
*
w_in
-
2
]));
// left side & right side
for
(
int
i
=
1
;
i
<
h_in
-
1
;
++
i
)
{
float
max1
=
std
::
max
(
input_data
[
i
*
w_in
-
w_in
],
input_data
[
i
*
w_in
-
w_in
+
1
]);
float
max2
=
std
::
max
(
input_data
[
i
*
w_in
],
input_data
[
i
*
w_in
+
1
]);
float
max3
=
std
::
max
(
input_data
[
i
*
w_in
+
w_in
],
input_data
[
i
*
w_in
+
w_in
+
1
]);
out_data
[
i
*
w_out
]
=
std
::
max
(
std
::
max
(
max1
,
max2
),
max3
);
max1
=
std
::
max
(
input_data
[
i
*
w_in
-
w_in
+
w_in
-
2
],
input_data
[
i
*
w_in
-
w_in
+
1
+
w_in
-
2
]);
max2
=
std
::
max
(
input_data
[
i
*
w_in
+
w_in
-
2
],
input_data
[
i
*
w_in
+
1
+
w_in
-
2
]);
max3
=
std
::
max
(
input_data
[
i
*
w_in
+
w_in
+
w_in
-
2
],
input_data
[
i
*
w_in
+
w_in
+
1
+
w_in
-
2
]);
out_data
[
i
*
w_out
+
w_out
-
1
]
=
std
::
max
(
std
::
max
(
max1
,
max2
),
max3
);
float
max1
=
std
::
max
(
input_seg
[
i
*
w_in
-
w_in
],
input_seg
[
i
*
w_in
-
w_in
+
1
]);
float
max2
=
std
::
max
(
input_seg
[
i
*
w_in
],
input_seg
[
i
*
w_in
+
1
]);
float
max3
=
std
::
max
(
input_seg
[
i
*
w_in
+
w_in
],
input_seg
[
i
*
w_in
+
w_in
+
1
]);
output_seg
[
i
*
w_out
]
=
std
::
max
(
std
::
max
(
max1
,
max2
),
max3
);
max1
=
std
::
max
(
input_seg
[
i
*
w_in
-
w_in
+
w_in
-
2
],
input_seg
[
i
*
w_in
-
w_in
+
1
+
w_in
-
2
]);
max2
=
std
::
max
(
input_seg
[
i
*
w_in
+
w_in
-
2
],
input_seg
[
i
*
w_in
+
1
+
w_in
-
2
]);
max3
=
std
::
max
(
input_seg
[
i
*
w_in
+
w_in
+
w_in
-
2
],
input_seg
[
i
*
w_in
+
w_in
+
1
+
w_in
-
2
]);
output_seg
[
i
*
w_out
+
w_out
-
1
]
=
std
::
max
(
std
::
max
(
max1
,
max2
),
max3
);
}
// top 1 row & bottom 1 row
const
float
*
input_tmp
=
input_
data
;
const
float
*
input_tmp
=
input_
seg
;
float32x4_t
in0
,
in1
,
in2
,
in3
,
in4
,
in5
,
in6
,
in7
,
tmp0
,
tmp1
,
tmp2
,
tmp3
,
tmp4
,
tmp5
,
max
;
...
...
@@ -329,7 +346,7 @@ void Pool3x3Maxs1p1(const Tensor *input, Tensor *output) {
in4
=
vld1q_f32
(
input_tmp_end
);
in6
=
vld1q_f32
(
input_tmp_end
+
w_in
);
int
c_mid
=
w_out
-
2
;
auto
output_ptr
=
out
_data
+
1
;
auto
output_ptr
=
out
put_seg
+
1
;
for
(;
c_mid
>
3
;
c_mid
-=
4
)
{
in1
=
vld1q_f32
(
input_tmp
+
4
);
in3
=
vld1q_f32
(
input_tmp
+
w_in
+
4
);
...
...
@@ -373,8 +390,8 @@ void Pool3x3Maxs1p1(const Tensor *input, Tensor *output) {
in6
=
in7
;
}
// top right remain
float32x4_t
pad0
=
vdupq_n_f32
(
input_
data
[
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
data
[
2
*
w_in
-
1
]);
float32x4_t
pad0
=
vdupq_n_f32
(
input_
seg
[
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
seg
[
2
*
w_in
-
1
]);
tmp0
=
vextq_f32
(
in0
,
pad0
,
1
);
tmp1
=
vextq_f32
(
in0
,
pad0
,
2
);
...
...
@@ -400,8 +417,8 @@ void Pool3x3Maxs1p1(const Tensor *input, Tensor *output) {
}
// bottom_right remain
float32x4_t
pad2
=
vdupq_n_f32
(
input_
data
[(
h_in
-
1
)
*
w_in
-
1
]);
float32x4_t
pad3
=
vdupq_n_f32
(
input_
data
[
h_in
*
w_in
-
1
]);
float32x4_t
pad2
=
vdupq_n_f32
(
input_
seg
[(
h_in
-
1
)
*
w_in
-
1
]);
float32x4_t
pad3
=
vdupq_n_f32
(
input_
seg
[
h_in
*
w_in
-
1
]);
tmp0
=
vextq_f32
(
in4
,
pad2
,
1
);
tmp1
=
vextq_f32
(
in4
,
pad2
,
2
);
...
...
@@ -427,8 +444,8 @@ void Pool3x3Maxs1p1(const Tensor *input, Tensor *output) {
}
// mid
for
(
int
j
=
0
;
j
<
h_out
-
2
;
++
j
)
{
output_ptr
=
out
_data
+
(
j
+
1
)
*
w_out
+
1
;
input_tmp
=
input_
data
+
j
*
w_in
;
output_ptr
=
out
put_seg
+
(
j
+
1
)
*
w_out
+
1
;
input_tmp
=
input_
seg
+
j
*
w_in
;
in0
=
vld1q_f32
(
input_tmp
);
in2
=
vld1q_f32
(
input_tmp
+
w_in
);
...
...
@@ -463,9 +480,9 @@ void Pool3x3Maxs1p1(const Tensor *input, Tensor *output) {
in4
=
in5
;
}
// mid remain
float32x4_t
pad0
=
vdupq_n_f32
(
input_
data
[(
j
+
1
)
*
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
data
[(
j
+
2
)
*
w_in
-
1
]);
float32x4_t
pad2
=
vdupq_n_f32
(
input_
data
[(
j
+
3
)
*
w_in
-
1
]);
float32x4_t
pad0
=
vdupq_n_f32
(
input_
seg
[(
j
+
1
)
*
w_in
-
1
]);
float32x4_t
pad1
=
vdupq_n_f32
(
input_
seg
[(
j
+
2
)
*
w_in
-
1
]);
float32x4_t
pad2
=
vdupq_n_f32
(
input_
seg
[(
j
+
3
)
*
w_in
-
1
]);
tmp0
=
vextq_f32
(
in0
,
pad0
,
1
);
tmp1
=
vextq_f32
(
in0
,
pad0
,
2
);
...
...
@@ -495,9 +512,11 @@ void Pool3x3Maxs1p1(const Tensor *input, Tensor *output) {
}
}
}
input_data
+=
inputdata_channel_stride
;
out_data
+=
outputdata_channel_stride
;
//
input_data += inputdata_channel_stride;
//
out_data += outputdata_channel_stride;
}
input_data
+=
input_batch_stride
;
out_data
+=
output_batch_stride
;
}
#endif
}
...
...
@@ -515,11 +534,11 @@ void Pool3x3Max(vector<int> strides, vector<int> paddings, const Tensor *input,
const
int
output_height
=
output
->
dims
()[
2
];
const
int
output_width
=
output
->
dims
()[
3
];
const
int
_kernel_size
=
3
;
const
int
stride
_height
=
strides
[
0
];
const
int
stride_width
=
strides
[
1
];
const
int
padding
_height
=
paddings
[
0
];
const
int
padding_width
=
paddings
[
1
];
//
const int _kernel_size = 3;
const
int
stride
=
strides
[
0
];
//
const int stride_width = strides[1];
const
int
padding
=
paddings
[
0
];
//
const int padding_width = paddings[1];
const
float
negative_max
=
-
INT_MAX
;
const
int
input_channel_stride
=
input_height
*
input_width
;
const
int
output_channel_stride
=
output_height
*
output_width
;
...
...
@@ -529,36 +548,39 @@ void Pool3x3Max(vector<int> strides, vector<int> paddings, const Tensor *input,
const
int
input_batch_stride
=
output_channels
*
input_channel_stride
;
const
int
output_batch_stride
=
output_channels
*
output_channel_stride
;
const
float
*
pos1
,
*
pos2
,
*
pos3
,
*
output_ptr
;
const
float
*
pos1
,
*
output_ptr
;
int
hstart
,
wstart
,
hend
,
wend
;
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
#pragma omp parallel for
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
const
float
*
input_seg
=
input_data
+
c
*
input_channel_stride
;
float
*
output_seg
=
output_data
+
c
*
output_channel_stride
;
for
(
int
ph
=
0
;
ph
<
output_height
;
ph
++
)
{
for
(
int
pw
=
0
;
pw
<
output_width
;
pw
++
)
{
hstart
=
ph
*
stride_height
-
padding_height
;
wstart
=
pw
*
stride_width
-
padding_width
;
hend
=
min
(
hstart
+
_kernel_size
,
input_height
+
padding_height
);
wend
=
min
(
wstart
+
_kernel_size
,
input_width
+
padding_width
);
int
hstart
=
ph
*
stride
-
padding
;
int
wstart
=
pw
*
stride
-
padding
;
int
hend
=
min
(
hstart
+
3
,
input_height
+
padding
);
int
wend
=
min
(
wstart
+
3
,
input_width
+
padding
);
hstart
=
max
(
hstart
,
0
);
wstart
=
max
(
wstart
,
0
);
hend
=
min
(
hend
,
input_height
);
wend
=
min
(
wend
,
input_width
);
pos1
=
input_data
+
hstart
*
input_width
+
wstart
;
pos2
=
input_data
+
(
hstart
+
1
)
*
input_width
+
wstart
;
pos3
=
input_data
+
(
hstart
+
2
)
*
input_width
+
wstart
;
output_ptr
=
output_
data
+
ph
*
output_width
+
pw
;
const
float
*
pos1
=
input_seg
+
hstart
*
input_width
+
wstart
;
const
float
*
pos2
=
input_seg
+
(
hstart
+
1
)
*
input_width
+
wstart
;
const
float
*
pos3
=
input_seg
+
(
hstart
+
2
)
*
input_width
+
wstart
;
output_ptr
=
output_
seg
+
ph
*
output_width
+
pw
;
if
(
hend
-
hstart
!=
3
||
wend
-
wstart
!=
3
)
{
float
max_value
=
-
INT_MAX
;
for
(
int
h
=
hstart
;
h
<
hend
;
h
++
)
{
for
(
int
w
=
wstart
;
w
<
wend
;
w
++
)
{
float
value
=
input_
data
[
h
*
input_width
+
w
];
float
value
=
input_
seg
[
h
*
input_width
+
w
];
if
(
value
>
max_value
)
{
max_value
=
value
;
}
}
}
output_
data
[
ph
*
output_width
+
pw
]
=
max_value
;
output_
seg
[
ph
*
output_width
+
pw
]
=
max_value
;
}
else
{
#if defined(ARMV7)
asm
volatile
(
...
...
@@ -572,27 +594,25 @@ void Pool3x3Max(vector<int> strides, vector<int> paddings, const Tensor *input,
"vpmax.f32 d7, d6, d6
\n\t
"
"vst1.32 {d7[0]},[%[output_ptr]]
\n\t
"
:
:
[
input_
data
]
"r"
(
input_data
),
[
pos1
]
"r"
(
pos1
),
:
[
input_
seg
]
"r"
(
input_seg
),
[
pos1
]
"r"
(
pos1
),
[
pos2
]
"r"
(
pos2
),
[
pos3
]
"r"
(
pos3
),
[
output_ptr
]
"r"
(
output_ptr
),
[
negative_max
]
"r"
(
negative_max
)
:
"memory"
,
"q1"
,
"q2"
,
"q3"
,
"q4"
);
#else
const
float32x4_t
data1
=
vld1q_f32
(
pos1
);
const
float32x4_t
data2
=
vld1q_f32
(
pos
2
);
const
float32x4_t
data3
=
vld1q_f32
(
pos
3
);
const
float32x4_t
data2
=
vld1q_f32
(
pos
1
+
input_width
);
const
float32x4_t
data3
=
vld1q_f32
(
pos
1
+
2
*
input_width
);
const
float32x4_t
max_data
=
vmaxq_f32
(
vmaxq_f32
(
data1
,
data
3
),
data2
);
vmaxq_f32
(
vmaxq_f32
(
data1
,
data
2
),
data3
);
float32x2_t
res
=
vpmax_f32
(
vget_high_f32
(
vsetq_lane_f32
(
-
INT_MAX
,
max_data
,
3
)),
vget_low_f32
(
max_data
));
res
=
vpmax_f32
(
res
,
res
);
output_
data
[
ph
*
output_width
+
pw
]
=
vget_lane_f32
(
res
,
0
);
output_
seg
[
ph
*
output_width
+
pw
]
=
vget_lane_f32
(
res
,
0
);
#endif
}
}
}
input_data
+=
input_channel_stride
;
output_data
+=
output_channel_stride
;
}
input_data
+=
input_batch_stride
;
output_data
+=
output_batch_stride
;
...
...
@@ -613,11 +633,8 @@ void Pool3x3Avg(vector<int> strides, vector<int> paddings, const Tensor *input,
const
int
output_height
=
output
->
dims
()[
2
];
const
int
output_width
=
output
->
dims
()[
3
];
const
int
_kernel_size
=
3
;
const
int
stride_height
=
strides
[
0
];
const
int
stride_width
=
strides
[
1
];
const
int
padding_height
=
paddings
[
0
];
const
int
padding_width
=
paddings
[
1
];
const
int
stride
=
strides
[
0
];
const
int
padding
=
paddings
[
0
];
const
int
input_channel_stride
=
input_height
*
input_width
;
const
int
output_channel_stride
=
output_height
*
output_width
;
...
...
@@ -631,30 +648,33 @@ void Pool3x3Avg(vector<int> strides, vector<int> paddings, const Tensor *input,
const
int
input_batch_stride
=
output_channels
*
input_channel_stride
;
const
int
output_batch_stride
=
output_channels
*
output_channel_stride
;
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
#pragma omp parallel for
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
const
float
*
input_seg
=
input_data
+
c
*
input_channel_stride
;
float
*
output_seg
=
output_data
+
c
*
output_channel_stride
;
for
(
int
ph
=
0
;
ph
<
output_height
;
ph
++
)
{
for
(
int
pw
=
0
;
pw
<
output_width
;
pw
++
)
{
int
hstart
=
ph
*
stride
_height
-
padding_height
;
int
wstart
=
pw
*
stride
_width
-
padding_width
;
int
hend
=
min
(
hstart
+
_kernel_size
,
input_height
+
padding_height
);
int
wend
=
min
(
wstart
+
_kernel_size
,
input_width
+
padding_width
);
int
hstart
=
ph
*
stride
-
padding
;
int
wstart
=
pw
*
stride
-
padding
;
int
hend
=
min
(
hstart
+
3
,
input_height
+
padding
);
int
wend
=
min
(
wstart
+
3
,
input_width
+
padding
);
hstart
=
max
(
hstart
,
0
);
wstart
=
max
(
wstart
,
0
);
hend
=
min
(
hend
,
input_height
);
wend
=
min
(
wend
,
input_width
);
const
float
*
pos1
=
input_
data
+
hstart
*
input_width
+
wstart
;
const
float
*
pos2
=
input_
data
+
(
hstart
+
1
)
*
input_width
+
wstart
;
const
float
*
pos3
=
input_
data
+
(
hstart
+
2
)
*
input_width
+
wstart
;
const
float
*
output_ptr
=
output_data
+
ph
*
output_width
+
pw
;
const
float
*
pos1
=
input_
seg
+
hstart
*
input_width
+
wstart
;
const
float
*
pos2
=
input_
seg
+
(
hstart
+
1
)
*
input_width
+
wstart
;
const
float
*
pos3
=
input_
seg
+
(
hstart
+
2
)
*
input_width
+
wstart
;
float
*
output_ptr
=
output_seg
+
ph
*
output_width
+
pw
;
if
(
hend
-
hstart
!=
3
||
wend
-
wstart
!=
3
)
{
float
sum
=
0
;
for
(
int
h
=
hstart
;
h
<
hend
;
h
++
)
{
for
(
int
w
=
wstart
;
w
<
wend
;
w
++
)
{
sum
+=
input_
data
[
h
*
input_width
+
w
];
sum
+=
input_
seg
[
h
*
input_width
+
w
];
}
}
output_
data
[
ph
*
output_width
+
pw
]
=
sum
/
9.0
;
output_
seg
[
ph
*
output_width
+
pw
]
=
sum
/
9.0
;
}
else
{
#if defined(ARMV7)
...
...
@@ -671,7 +691,7 @@ void Pool3x3Avg(vector<int> strides, vector<int> paddings, const Tensor *input,
"vmul.f32 d6,d7
\n\t
"
"vst1.32 {d6[0]},[%[output_ptr]]
\n\t
"
:
:
[
input_
data
]
"r"
(
input_data
),
[
pos1
]
"r"
(
pos1
),
:
[
input_
seg
]
"r"
(
input_seg
),
[
pos1
]
"r"
(
pos1
),
[
pos2
]
"r"
(
pos2
),
[
pos3
]
"r"
(
pos3
),
[
output_ptr
]
"r"
(
output_ptr
),
[
zero
]
"r"
(
zero
),
[
nine_ptr
]
"r"
(
nine_ptr
)
...
...
@@ -686,13 +706,11 @@ void Pool3x3Avg(vector<int> strides, vector<int> paddings, const Tensor *input,
vpadd_f32
(
vget_high_f32
(
vsetq_lane_f32
(
0
,
sum_data
,
3
)),
vget_low_f32
(
sum_data
));
res
=
vpadd_f32
(
res
,
res
);
output_
data
[
ph
*
output_width
+
pw
]
=
vget_lane_f32
(
res
,
0
)
/
9.0
;
output_
seg
[
ph
*
output_width
+
pw
]
=
vget_lane_f32
(
res
,
0
)
/
9.0
;
#endif
}
}
}
input_data
+=
input_channel_stride
;
output_data
+=
output_channel_stride
;
}
input_data
+=
input_batch_stride
;
output_data
+=
output_batch_stride
;
...
...
src/operators/math/pool_3x3.h
浏览文件 @
86cb0443
...
...
@@ -15,10 +15,13 @@ limitations under the License. */
#ifdef POOL_OP
#pragma once
#ifdef _OPENMP
#include <omp.h>
#endif
#include <algorithm>
#include <vector>
#include "framework/tensor.h"
#if
def
__ARM_NEON
#if __ARM_NEON
#include <arm_neon.h>
#endif // __ARM_NEON
...
...
src/operators/math/pooling.cpp
浏览文件 @
86cb0443
...
...
@@ -14,10 +14,11 @@ limitations under the License. */
#ifdef POOL_OP
#include "operators/math/pooling.h"
#include <algorithm>
#include <vector>
#include "pooling.h"
#include "common/types.h"
#ifdef _OPENMP
#include <omp.h>
#endif
namespace
paddle_mobile
{
namespace
operators
{
...
...
@@ -59,7 +60,7 @@ class PoolFunctor<CPU, PoolProcess, T> {
T
*
output_data
=
output
->
mutable_data
<
T
>
();
for
(
int
i
=
0
;
i
<
batch_size
;
i
++
)
{
//
#pragma omp parallel for
#pragma omp parallel for
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
for
(
int
ph
=
0
;
ph
<
output_height
;
++
ph
)
{
int
hstart
=
ph
*
stride_height
-
padding_height
;
...
...
test/net/test_googlenet.cpp
浏览文件 @
86cb0443
...
...
@@ -26,16 +26,17 @@ int main() {
auto
time2
=
time
();
DLOG
<<
"load cost :"
<<
time_diff
(
time1
,
time2
)
<<
"ms
\n
"
;
paddle_mobile
::
Executor
<
paddle_mobile
::
CPU
>
executor
(
program
,
1
,
optimize
);
executor
.
SetThreadNum
(
4
);
std
::
vector
<
float
>
input
;
std
::
vector
<
int64_t
>
dims
{
1
,
3
,
224
,
224
};
GetInput
<
float
>
(
g_test_image_1x3x224x224
,
&
input
,
dims
);
auto
time3
=
time
();
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
int
count
=
1
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
executor
.
Predict
(
input
,
dims
);
}
auto
time4
=
time
();
DLOG
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
<<
"ms
\n
"
;
DLOG
<<
"predict cost :"
<<
time_diff
(
time3
,
time4
)
/
count
<<
"ms
\n
"
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录