Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
c16566fa
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
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,发现更多精彩内容 >>
提交
c16566fa
编写于
8月 27, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
!5324 Fix the bug of matmul_int8's pre-process
Merge pull request !5324 from zhanyuan/dev
上级
b346f0b3
203a4d2e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
31 addition
and
14 deletion
+31
-14
mindspore/lite/nnacl/int8/matmul_int8.c
mindspore/lite/nnacl/int8/matmul_int8.c
+13
-6
mindspore/lite/nnacl/int8/matmul_int8.h
mindspore/lite/nnacl/int8/matmul_int8.h
+3
-2
mindspore/lite/nnacl/op_base.h
mindspore/lite/nnacl/op_base.h
+5
-0
mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc
...e/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc
+2
-2
mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc
mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc
+6
-3
mindspore/lite/tools/converter/quantizer/aware_quantizer.cc
mindspore/lite/tools/converter/quantizer/aware_quantizer.cc
+2
-1
未找到文件。
mindspore/lite/nnacl/int8/matmul_int8.c
浏览文件 @
c16566fa
...
...
@@ -225,12 +225,15 @@ void RowMajor2Col16x4Major(int8_t *src, int row, int col, int8_t *dst, int row_1
}
// dst: weight_zp * input_row_sums
void
CalcInputSums
(
int8_t
*
input
,
int
row
,
int
col
,
int
weight_zp
,
int
*
dst
)
{
void
CalcInputSums
(
int8_t
*
input
,
int
row
,
int
col
,
int
weight_zp
,
int
*
dst
,
DataOrder
order
)
{
for
(
int
r
=
0
;
r
<
row
;
++
r
)
{
int
sum
=
0
;
for
(
int
c
=
0
;
c
<
col
;
++
c
)
{
int
src_idx
=
r
*
col
+
c
;
sum
+=
input
[
src_idx
];
if
(
order
==
RowMajor
)
{
sum
+=
input
[
r
*
col
+
c
];
}
else
{
sum
+=
input
[
c
*
row
+
r
];
}
}
sum
*=
weight_zp
;
dst
[
r
]
=
sum
;
...
...
@@ -238,12 +241,16 @@ void CalcInputSums(int8_t *input, int row, int col, int weight_zp, int *dst) {
}
// dst: bias + depth*input_zp*weight_zp - input_zp*weight_col_sums
void
CalcWeightBiasSums
(
int8_t
*
weight
,
int
row
,
int
col
,
int
input_zp
,
int
weight_zp
,
int
*
bias
,
int
*
dst
)
{
void
CalcWeightBiasSums
(
int8_t
*
weight
,
int
row
,
int
col
,
int
input_zp
,
int
weight_zp
,
int
*
bias
,
int
*
dst
,
DataOrder
order
)
{
for
(
int
c
=
0
;
c
<
col
;
++
c
)
{
int
sum
=
0
;
for
(
int
r
=
0
;
r
<
row
;
++
r
)
{
int
src_idx
=
r
*
col
+
c
;
sum
+=
weight
[
src_idx
];
if
(
order
==
RowMajor
)
{
sum
+=
weight
[
r
*
col
+
c
];
}
else
{
sum
+=
weight
[
c
*
row
+
r
];
}
}
dst
[
c
]
=
row
*
input_zp
*
weight_zp
-
input_zp
*
sum
;
if
(
bias
)
{
...
...
mindspore/lite/nnacl/int8/matmul_int8.h
浏览文件 @
c16566fa
...
...
@@ -37,8 +37,9 @@ void RowMajor2Row16x4MajorInt8(void *src_ptr, void *dst_ptr, int row, int col);
void
RowMajor2Row4x16Major
(
int8_t
*
src
,
int
row
,
int
col
,
int8_t
*
dst
,
int
col_16
);
void
RowMajor2Col16x4Major
(
int8_t
*
src
,
int
row
,
int
col
,
int8_t
*
dst
,
int
row_16
);
void
CalcInputSums
(
int8_t
*
a
,
int
row
,
int
col
,
int
b_zp
,
int
*
dst
);
void
CalcWeightBiasSums
(
int8_t
*
b
,
int
row
,
int
col
,
int
a_zp
,
int
b_zp
,
int
*
bias
,
int
*
dst
);
void
CalcInputSums
(
int8_t
*
input
,
int
row
,
int
col
,
int
weight_zp
,
int
*
dst
,
DataOrder
order
);
void
CalcWeightBiasSums
(
int8_t
*
weight
,
int
row
,
int
col
,
int
input_zp
,
int
weight_zp
,
int
*
bias
,
int
*
dst
,
DataOrder
order
);
void
MatmulInt8
(
const
int8_t
*
a
,
const
int8_t
*
b
,
int8_t
*
dst
,
const
int
*
a_sums
,
const
int
*
bias
,
int
act_min
,
int
act_max
,
int
out_zp
,
int
multiplier
,
int
left_shift
,
int
right_shift
,
int
row
,
int
col
,
int
deep16
,
int
stride
);
...
...
mindspore/lite/nnacl/op_base.h
浏览文件 @
c16566fa
...
...
@@ -55,6 +55,11 @@ typedef enum LiteDataType {
kDataTypeInt8
,
}
LiteDataType
;
typedef
enum
DataOrder
{
RowMajor
,
ColMajor
,
}
DataOrder
;
typedef
struct
OpParameter
{
char
name_
[
100
];
int
type_
;
...
...
mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc
浏览文件 @
c16566fa
...
...
@@ -90,7 +90,7 @@ int FullconnectionInt8CPUKernel::ReSize() {
quant_params_
.
output
.
zp_
,
quant_params_
.
output
.
scale_
,
&
quant_params_
.
out_act_min
,
&
quant_params_
.
out_act_max
);
CalcWeightBiasSums
(
weight_data
,
fc_param_
->
deep_
,
fc_param_
->
col_
,
quant_params_
.
input
.
zp_
,
quant_params_
.
weight
.
zp_
,
bias_ptr_
,
weight_bias_sums_
);
bias_ptr_
,
weight_bias_sums_
,
ColMajor
);
return
RET_OK
;
}
...
...
@@ -136,7 +136,7 @@ int FullconnectionInt8CPUKernel::Run() {
}
auto
input_ptr
=
reinterpret_cast
<
int8_t
*>
(
in_tensors_
[
0
]
->
Data
());
RowMajor2Row4x16Major
(
input_ptr
,
fc_param_
->
row_
,
fc_param_
->
deep_
,
a_r4x16_ptr_
,
d16_
);
CalcInputSums
(
input_ptr
,
fc_param_
->
row_
,
fc_param_
->
deep_
,
quant_params_
.
weight
.
zp_
,
input_sums_
);
CalcInputSums
(
input_ptr
,
fc_param_
->
row_
,
fc_param_
->
deep_
,
quant_params_
.
weight
.
zp_
,
input_sums_
,
RowMajor
);
ParallelLaunch
(
THREAD_POOL_DEFAULT
,
FcInt8Run
,
this
,
thread_count_
);
return
RET_OK
;
}
...
...
mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc
浏览文件 @
c16566fa
...
...
@@ -140,18 +140,21 @@ int MatmulInt8CPUKernel::Run() {
if
(
params_
->
a_transpose_
)
{
RowMajor2Col16x4Major
(
cur_a_ptr
,
params_
->
deep_
,
params_
->
row_
,
a_r4x16_ptr_
,
d16_
);
CalcInputSums
(
cur_a_ptr
,
params_
->
row_
,
params_
->
deep_
,
quant_params_
.
weight
.
zp_
,
input_sums_
,
ColMajor
);
}
else
{
RowMajor2Row4x16Major
(
cur_a_ptr
,
params_
->
row_
,
params_
->
deep_
,
a_r4x16_ptr_
,
d16_
);
CalcInputSums
(
cur_a_ptr
,
params_
->
row_
,
params_
->
deep_
,
quant_params_
.
weight
.
zp_
,
input_sums_
,
RowMajor
);
}
if
(
params_
->
b_transpose_
)
{
RowMajor2Row4x16Major
(
cur_b_ptr
,
params_
->
col_
,
params_
->
deep_
,
b_c16x4_ptr_
,
d16_
);
CalcWeightBiasSums
(
cur_b_ptr
,
params_
->
deep_
,
params_
->
col_
,
quant_params_
.
input
.
zp_
,
quant_params_
.
weight
.
zp_
,
NULL
,
weight_bias_sums_
,
ColMajor
);
}
else
{
RowMajor2Col16x4Major
(
cur_b_ptr
,
params_
->
deep_
,
params_
->
col_
,
b_c16x4_ptr_
,
d16_
);
CalcWeightBiasSums
(
cur_b_ptr
,
params_
->
deep_
,
params_
->
col_
,
quant_params_
.
input
.
zp_
,
quant_params_
.
weight
.
zp_
,
NULL
,
weight_bias_sums_
,
RowMajor
);
}
c_ptr_
=
c_ptr
+
i
*
c_stride
;
auto
&
q
=
quant_params_
;
CalcInputSums
(
cur_a_ptr
,
params_
->
row_
,
params_
->
deep_
,
q
.
weight
.
zp_
,
input_sums_
);
CalcWeightBiasSums
(
cur_b_ptr
,
params_
->
deep_
,
params_
->
col_
,
q
.
input
.
zp_
,
q
.
weight
.
zp_
,
NULL
,
weight_bias_sums_
);
ret
=
ParallelLaunch
(
THREAD_POOL_DEFAULT
,
MatmulInt8Run
,
this
,
thread_count_
);
if
(
ret
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"MatmulInt8Run error: ["
<<
ret
<<
"]"
;
...
...
mindspore/lite/tools/converter/quantizer/aware_quantizer.cc
浏览文件 @
c16566fa
...
...
@@ -226,7 +226,8 @@ STATUS AwareQuantizer::DoQuantize() {
}
STATUS
status
;
if
(
GetCNodeTType
(
*
node
)
==
schema
::
PrimitiveType_Conv2D
||
GetCNodeTType
(
*
node
)
==
schema
::
PrimitiveType_DepthwiseConv2D
)
{
GetCNodeTType
(
*
node
)
==
schema
::
PrimitiveType_DepthwiseConv2D
||
GetCNodeTType
(
*
node
)
==
schema
::
PrimitiveType_FullConnection
)
{
auto
inputIndexes
=
node
->
inputIndex
;
if
(
inputIndexes
.
size
()
<
2
)
{
MS_LOG
(
ERROR
)
<<
node
->
name
.
c_str
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录