Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_77200941
mindspore
提交
cd9505f5
M
mindspore
项目概览
2301_77200941
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cd9505f5
编写于
8月 28, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
!5359 [MS][LITE]optimize int8 pooling
Merge pull request !5359 from fuzhiye/tmp
上级
29070d60
d0aa719a
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
313 addition
and
166 deletion
+313
-166
mindspore/lite/nnacl/int8/conv_int8.c
mindspore/lite/nnacl/int8/conv_int8.c
+2
-1
mindspore/lite/nnacl/int8/pooling_int8.c
mindspore/lite/nnacl/int8/pooling_int8.c
+270
-128
mindspore/lite/nnacl/int8/pooling_int8.h
mindspore/lite/nnacl/int8/pooling_int8.h
+2
-0
mindspore/lite/nnacl/pooling_parameter.h
mindspore/lite/nnacl/pooling_parameter.h
+9
-6
mindspore/lite/src/populate_parameter.cc
mindspore/lite/src/populate_parameter.cc
+6
-12
mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc
mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc
+6
-0
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc
+1
-1
mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc
mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc
+1
-1
mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc
...ore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc
+1
-1
mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc
mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc
+7
-3
mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc
mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc
+2
-2
mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/pooling_grad_fp32_tests.cc
...c/runtime/kernel/arm/fp32_grad/pooling_grad_fp32_tests.cc
+4
-7
mindspore/lite/test/ut/src/runtime/kernel/opencl/avg_pooling_tests.cc
...te/test/ut/src/runtime/kernel/opencl/avg_pooling_tests.cc
+1
-2
mindspore/lite/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
...te/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
+1
-2
未找到文件。
mindspore/lite/nnacl/int8/conv_int8.c
浏览文件 @
cd9505f5
...
...
@@ -264,7 +264,8 @@ void ConvInt8(int8_t *input_data, int8_t *packed_input, int8_t *packed_weight, c
int
output_tile_count
=
UP_DIV
(
output_count
,
tile_n
);
int
ic4
=
UP_DIV
(
in_channel
,
C4NUM
);
int
kernel_plane
=
kernel_h
*
kernel_w
;
int
unit_size
=
kernel_plane
*
ic4
*
C4NUM
;
int
plane_block
=
UP_DIV
(
kernel_plane
,
C4NUM
);
int
unit_size
=
plane_block
*
C4NUM
*
ic4
*
C4NUM
;
int
packed_input_size
=
output_tile_count
*
tile_n
*
unit_size
;
int
input_sum_offset
;
if
(
conv_param
->
conv_quant_arg_
.
per_channel_
&
FILTER_PER_CHANNEL
)
{
...
...
mindspore/lite/nnacl/int8/pooling_int8.c
浏览文件 @
cd9505f5
此差异已折叠。
点击以展开。
mindspore/lite/nnacl/int8/pooling_int8.h
浏览文件 @
cd9505f5
...
...
@@ -32,6 +32,8 @@ void AvgPoolingOptInt8(const int8_t *input_ptr, int8_t *output_ptr, PoolingParam
void
MaxPoolingInt8
(
const
int8_t
*
input_ptr
,
int8_t
*
output_ptr
,
PoolingParameter
*
pooling_param
,
int
task_id
);
void
MaxPoolingWithQuantInt8
(
const
int8_t
*
input_ptr
,
int8_t
*
output_ptr
,
PoolingParameter
*
pooling_param
,
int
task_id
);
void
MaxPoolingOptInt8
(
const
int8_t
*
input_ptr
,
int8_t
*
output_ptr
,
PoolingParameter
*
pooling_param
,
int
task_id
);
#ifdef __cplusplus
}
...
...
mindspore/lite/nnacl/pooling_parameter.h
浏览文件 @
cd9505f5
...
...
@@ -19,14 +19,16 @@
#include "nnacl/op_base.h"
#include "nnacl/quantization/quantize.h"
typedef
enum
PoolMode
{
PoolMode_No
,
PoolMode_MaxPool
,
PoolMode_AvgPool
}
PoolMode
;
typedef
enum
RoundMode
{
RoundMode_No
,
RoundMode_Ceil
,
RoundMode_Floor
}
RoundMode
;
typedef
struct
PoolingParameter
{
OpParameter
op_parameter_
;
PoolMode
pool_mode_
;
RoundMode
round_mode_
;
ActType
act_type_
;
QuantArg
**
quant_args_
;
bool
global_
;
bool
max_pooling_
;
bool
avg_pooling_
;
bool
round_ceil_
;
bool
round_floor_
;
int
window_w_
;
int
window_h_
;
int
input_w_
;
...
...
@@ -44,7 +46,8 @@ typedef struct PoolingParameter {
int
stride_w_
;
int
stride_h_
;
int
thread_num_
;
ActType
act_type_
;
bool
global_
;
bool
quantize_
;
}
PoolingParameter
;
#endif // MINDSPORE_LITE_NNACL_POOLING_PARAMETER_H_
mindspore/lite/src/populate_parameter.cc
浏览文件 @
cd9505f5
...
...
@@ -294,32 +294,26 @@ OpParameter *PopulatePoolingParameter(const mindspore::lite::PrimitiveC *primiti
auto
pool_mode
=
pooling_primitive
->
GetPoolingMode
();
switch
(
pool_mode
)
{
case
schema
::
PoolMode_MAX_POOLING
:
pooling_param
->
max_pooling_
=
true
;
pooling_param
->
avg_pooling_
=
false
;
pooling_param
->
pool_mode_
=
PoolMode_MaxPool
;
break
;
case
schema
::
PoolMode_MEAN_POOLING
:
pooling_param
->
max_pooling_
=
false
;
pooling_param
->
avg_pooling_
=
true
;
pooling_param
->
pool_mode_
=
PoolMode_AvgPool
;
break
;
default:
pooling_param
->
max_pooling_
=
false
;
pooling_param
->
avg_pooling_
=
false
;
pooling_param
->
pool_mode_
=
PoolMode_No
;
break
;
}
auto
round_mode
=
pooling_primitive
->
GetRoundMode
();
switch
(
round_mode
)
{
case
schema
::
RoundMode_FLOOR
:
pooling_param
->
round_floor_
=
true
;
pooling_param
->
round_ceil_
=
false
;
pooling_param
->
round_mode_
=
RoundMode_Floor
;
break
;
case
schema
::
RoundMode_CEIL
:
pooling_param
->
round_floor_
=
false
;
pooling_param
->
round_ceil_
=
true
;
pooling_param
->
round_mode_
=
RoundMode_Ceil
;
break
;
default:
pooling_param
->
round_floor_
=
false
;
pooling_param
->
round_ceil_
=
false
;
pooling_param
->
round_mode_
=
RoundMode_No
;
break
;
}
...
...
mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc
浏览文件 @
cd9505f5
...
...
@@ -42,6 +42,12 @@ int PoolingBaseCPUKernel::SetQuantParam() {
pooling_quant_arg_
[
1
][
0
].
scale_
=
out_quant_arg
.
front
().
scale
;
pooling_quant_arg_
[
1
][
0
].
zp_
=
out_quant_arg
.
front
().
zeroPoint
;
pooling_param_
->
quant_args_
=
pooling_quant_arg_
;
if
(
pooling_quant_arg_
[
0
][
0
].
scale_
==
pooling_quant_arg_
[
1
][
0
].
scale_
&&
pooling_quant_arg_
[
0
][
0
].
zp_
==
pooling_quant_arg_
[
1
][
0
].
zp_
)
{
pooling_param_
->
quantize_
=
false
;
}
else
{
pooling_param_
->
quantize_
=
true
;
}
return
RET_OK
;
}
...
...
mindspore/lite/src/runtime/kernel/arm/fp16/pooling_fp16.cc
浏览文件 @
cd9505f5
...
...
@@ -53,7 +53,7 @@ int PoolingFp16CPUKernel::ReSize() {
}
int
PoolingFp16CPUKernel
::
RunImpl
(
int
task_id
)
{
if
(
pooling_param_
->
max_pooling_
)
{
if
(
pooling_param_
->
pool_mode_
==
PoolMode_MaxPool
)
{
MaxPoolingFp16
(
fp16_input_
,
fp16_output_
,
pooling_param_
,
task_id
);
}
else
{
AvgPoolingFp16
(
fp16_input_
,
fp16_output_
,
pooling_param_
,
task_id
);
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc
浏览文件 @
cd9505f5
...
...
@@ -52,7 +52,7 @@ int PoolingCPUKernel::ReSize() {
int
PoolingCPUKernel
::
RunImpl
(
int
task_id
)
{
auto
input_ptr
=
reinterpret_cast
<
float
*>
(
in_tensors_
.
at
(
kInputIndex
)
->
Data
());
auto
output_ptr
=
reinterpret_cast
<
float
*>
(
out_tensors_
.
at
(
kOutputIndex
)
->
Data
());
if
(
pooling_param_
->
max_pooling_
)
{
if
(
pooling_param_
->
pool_mode_
==
PoolMode_MaxPool
)
{
switch
(
pooling_param_
->
act_type_
)
{
case
ActType_Relu
:
MaxPoolingRelu
(
input_ptr
,
output_ptr
,
pooling_param_
,
task_id
);
...
...
mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc
浏览文件 @
cd9505f5
...
...
@@ -163,7 +163,7 @@ int PoolingGradCPUKernel::Run() {
auto
input_ptr
=
reinterpret_cast
<
float
*>
(
inputs_
.
at
(
0
)
->
Data
());
auto
output_ptr
=
reinterpret_cast
<
float
*>
(
outputs_
.
at
(
0
)
->
Data
());
if
(
pool_param
->
max_pooling_
)
{
if
(
pool_param
->
pool_mode_
==
PoolMode_MaxPool
)
{
auto
ind
=
reinterpret_cast
<
int
*>
(
inputs_
.
at
(
1
)
->
Data
());
MaxPoolingGrad
(
input_ptr
,
ind
,
output_ptr
,
pool_param
);
}
else
{
...
...
mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc
浏览文件 @
cd9505f5
...
...
@@ -61,10 +61,14 @@ int PoolingInt8CPUKernel::ReSize() {
int
PoolingInt8CPUKernel
::
RunImpl
(
int
task_id
)
{
auto
input_data
=
reinterpret_cast
<
int8_t
*>
(
in_tensors_
.
at
(
kInputIndex
)
->
Data
());
auto
output_data
=
reinterpret_cast
<
int8_t
*>
(
out_tensors_
.
at
(
kOutputIndex
)
->
Data
());
if
(
pooling_param_
->
max_pooling_
)
{
MaxPoolingInt8
(
input_data
,
output_data
,
pooling_param_
,
task_id
);
if
(
pooling_param_
->
pool_mode_
==
PoolMode_MaxPool
)
{
if
(
pooling_param_
->
quantize_
)
{
MaxPoolingWithQuantInt8
(
input_data
,
output_data
,
pooling_param_
,
task_id
);
}
else
{
MaxPoolingOptInt8
(
input_data
,
output_data
,
pooling_param_
,
task_id
);
}
}
else
{
AvgPoolingInt8
(
input_data
,
output_data
,
pooling_param_
,
task_id
);
AvgPooling
Opt
Int8
(
input_data
,
output_data
,
pooling_param_
,
task_id
);
}
return
RET_OK
;
}
...
...
mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc
浏览文件 @
cd9505f5
...
...
@@ -43,13 +43,13 @@ int PoolingOpenCLKernel::Init() {
std
::
string
source
;
std
::
string
program_name
;
#endif
if
(
parameter_
->
max_pooling_
)
{
if
(
parameter_
->
pool_mode_
==
PoolMode_MaxPool
)
{
kernel_name
=
"MaxPooling2d"
;
#ifndef PROGRAM_WITH_IL
source
=
max_pool2d_source
;
program_name
=
"MaxPooling2d"
;
#endif
}
else
if
(
parameter_
->
avg_pooling_
)
{
}
else
if
(
parameter_
->
pool_mode_
==
PoolMode_AvgPool
)
{
kernel_name
=
"AvgPooling2d"
;
#ifndef PROGRAM_WITH_IL
source
=
avg_pool2d_source
;
...
...
mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/pooling_grad_fp32_tests.cc
浏览文件 @
cd9505f5
...
...
@@ -26,7 +26,7 @@
#include "nnacl/fp32_grad/pooling_grad.h"
namespace
mindspore
{
class
TestPoolingGradFp32
:
public
mindspore
::
CommonTest
{
class
TestPoolingGradFp32
:
public
mindspore
::
CommonTest
{
public:
TestPoolingGradFp32
()
{}
};
...
...
@@ -161,8 +161,7 @@ TEST_F(TestPoolingGradFp32, MaxPoolingGradFp32) {
auto
pooling_param
=
new
PoolingParameter
();
InitPoolingParamFP32
(
pooling_param
);
pooling_param
->
output_channel_
=
3
;
pooling_param
->
avg_pooling_
=
false
;
pooling_param
->
max_pooling_
=
true
;
pooling_param
->
pool_mode_
=
PoolMode_MaxPool
;
// runtime part
printf
(
"Calculating runtime cost...
\n
"
);
uint64_t
time_avg
=
0
;
...
...
@@ -215,8 +214,7 @@ TEST_F(TestPoolingGradFp32, MaxPoolingKernelGradFp32) {
// prepare stage
auto maxpool = new PoolingParameter();
InitPoolingParamFP32(maxpool);
maxpool->avg_pooling_ = false;
maxpool->max_pooling_ = true;
maxpool->pool_mode_ = PoolMode_MaxPool;
maxpool->input_h_ = 30;
maxpool->input_w_ = 30;
maxpool->input_channel_ = 3;
...
...
@@ -268,8 +266,7 @@ TEST_F(TestPoolingGradFp32, MaxPoolingKernelGradFp32) {
auto pooling_param = new PoolingParameter();
InitPoolingParamFP32(pooling_param);
pooling_param->avg_pooling_ = false;
pooling_param->max_pooling_ = true;
pooling_param->pool_mode_ = PoolMode_MaxPool;
pooling_param->input_h_ = 10;
pooling_param->input_w_ = 10;
pooling_param->input_channel_ = 3;
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/avg_pooling_tests.cc
浏览文件 @
cd9505f5
...
...
@@ -48,8 +48,7 @@ void InitAvgPoolingParam(PoolingParameter *param) {
param
->
pad_l_
=
0
;
param
->
pad_r_
=
0
;
param
->
max_pooling_
=
false
;
param
->
avg_pooling_
=
true
;
param
->
pool_mode_
=
PoolMode_AvgPool
;
}
TEST_F
(
TestAvgPoolingOpenCL
,
AvgPoolFp32
)
{
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
浏览文件 @
cd9505f5
...
...
@@ -35,8 +35,7 @@ void InitParameter(PoolingParameter *param) {
param
->
pad_d_
=
0
;
param
->
pad_l_
=
0
;
param
->
pad_r_
=
0
;
param
->
avg_pooling_
=
false
;
param
->
max_pooling_
=
true
;
param
->
pool_mode_
=
PoolMode_MaxPool
;
}
TEST_F
(
TestMaxPoolingOpenCL
,
MaxPool_1_32_512_96
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录