Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
0f75ab64
M
mindspore
项目概览
magicwindyyd
/
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看板
提交
0f75ab64
编写于
8月 18, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 18, 2020
浏览文件
操作
浏览文件
下载
差异文件
!4602 [MS][LITE] fullconnection matmul A B matrix const node bug
Merge pull request !4602 from ling/fc
上级
5bd500bd
7aab3f07
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
96 addition
and
13 deletion
+96
-13
mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc
mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc
+42
-3
mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.h
mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.h
+5
-0
mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc
mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc
+43
-10
mindspore/lite/src/runtime/kernel/arm/fp32/matmul.h
mindspore/lite/src/runtime/kernel/arm/fp32/matmul.h
+4
-0
mindspore/lite/src/runtime/kernel/arm/nnacl/matmul_parameter.h
...pore/lite/src/runtime/kernel/arm/nnacl/matmul_parameter.h
+2
-0
未找到文件。
mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc
浏览文件 @
0f75ab64
...
...
@@ -23,6 +23,11 @@ using mindspore::lite::RET_OK;
namespace
mindspore
::
kernel
{
FullconnectionCPUKernel
::~
FullconnectionCPUKernel
()
{
FreeBuf
();
return
;
}
void
FullconnectionCPUKernel
::
FreeBuf
()
{
if
(
a_c8_ptr_
!=
nullptr
)
{
free
(
a_c8_ptr_
);
a_c8_ptr_
=
nullptr
;
...
...
@@ -41,7 +46,11 @@ FullconnectionCPUKernel::~FullconnectionCPUKernel() {
}
}
int
FullconnectionCPUKernel
::
ReSize
()
{
return
RET_OK
;
}
int
FullconnectionCPUKernel
::
ReSize
()
{
FreeBuf
();
Init
();
return
RET_OK
;
}
int
FullconnectionCPUKernel
::
Init
()
{
if
(
context_
->
infer_shape_interrupt_
&&
!
context_
->
running_
)
{
...
...
@@ -75,16 +84,44 @@ int FullconnectionCPUKernel::Init() {
return
RET_MEMORY_FAILED
;
}
memset
(
b_r8_ptr_
,
0
,
fc_param_
->
col_8_
*
fc_param_
->
deep_
*
sizeof
(
float
));
RowMajor2Col8Major
(
reinterpret_cast
<
float
*>
(
in_tensors_
[
1
]
->
Data
()),
b_r8_ptr_
,
fc_param_
->
col_
,
fc_param_
->
deep_
);
c_r8x8_ptr_
=
reinterpret_cast
<
float
*>
(
malloc
(
fc_param_
->
row_8_
*
fc_param_
->
col_8_
*
sizeof
(
float
)));
if
(
c_r8x8_ptr_
==
nullptr
)
{
return
RET_MEMORY_FAILED
;
}
memset
(
c_r8x8_ptr_
,
0
,
fc_param_
->
row_8_
*
fc_param_
->
col_8_
*
sizeof
(
float
));
fc_param_
->
a_const_
=
false
;
fc_param_
->
b_const_
=
false
;
InitMatrixA
(
reinterpret_cast
<
float
*>
(
in_tensors_
[
0
]
->
Data
()),
a_c8_ptr_
);
InitMatrixB
(
reinterpret_cast
<
float
*>
(
in_tensors_
[
1
]
->
Data
()),
b_r8_ptr_
);
return
RET_OK
;
}
void
FullconnectionCPUKernel
::
InitMatrixA
(
float
*
src_ptr
,
float
*
dst_ptr
)
{
if
(
fc_param_
->
a_const_
==
true
)
{
return
;
}
if
(
src_ptr
==
nullptr
)
{
return
;
}
fc_param_
->
a_const_
=
true
;
RowMajor2Col8Major
(
src_ptr
,
a_c8_ptr_
,
fc_param_
->
row_
,
fc_param_
->
deep_
);
return
;
}
void
FullconnectionCPUKernel
::
InitMatrixB
(
float
*
src_ptr
,
float
*
dst_ptr
)
{
if
(
fc_param_
->
b_const_
==
true
)
{
return
;
}
if
(
src_ptr
==
nullptr
)
{
return
;
}
fc_param_
->
b_const_
=
true
;
RowMajor2Col8Major
(
src_ptr
,
dst_ptr
,
fc_param_
->
col_
,
fc_param_
->
deep_
);
return
;
}
int
FcFp32MatmulRun
(
int
task_id
,
LiteParallelGroupEnv
*
penv
,
void
*
cdata
)
{
auto
fc
=
reinterpret_cast
<
FullconnectionCPUKernel
*>
(
cdata
);
auto
error_code
=
fc
->
DoMatmul
(
task_id
);
...
...
@@ -115,9 +152,11 @@ int FullconnectionCPUKernel::Run() {
return
prepare_ret
;
}
auto
a_ptr
=
reinterpret_cast
<
float
*>
(
in_tensors_
.
at
(
0
)
->
Data
());
auto
b_ptr
=
reinterpret_cast
<
float
*>
(
in_tensors_
.
at
(
1
)
->
Data
());
auto
output_ptr
=
reinterpret_cast
<
float
*>
(
out_tensors_
.
at
(
0
)
->
Data
());
RowMajor2Col8Major
(
a_ptr
,
a_c8_ptr_
,
fc_param_
->
row_
,
fc_param_
->
deep_
);
InitMatrixA
(
a_ptr
,
a_c8_ptr_
);
InitMatrixB
(
b_ptr
,
b_r8_ptr_
);
LiteBackendParallelLaunch
(
FcFp32MatmulRun
,
this
,
thread_count_
);
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.h
浏览文件 @
0f75ab64
...
...
@@ -40,6 +40,11 @@ class FullconnectionCPUKernel : public FullconnectionBaseCPUKernel {
public:
int
DoMatmul
(
int
task_id
);
void
FreeBuf
();
private:
void
InitMatrixA
(
float
*
src_ptr
,
float
*
dst_ptr
);
void
InitMatrixB
(
float
*
src_ptr
,
float
*
dst_ptr
);
private:
float
*
a_c8_ptr_
;
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc
浏览文件 @
0f75ab64
...
...
@@ -78,6 +78,11 @@ int MatmulCPUKernel::Init() {
}
memset
(
c_r8x8_ptr_
,
0
,
params_
->
row_8_
*
params_
->
col_8_
*
sizeof
(
float
));
params_
->
a_const_
=
false
;
params_
->
b_const_
=
false
;
InitMatrixA
(
reinterpret_cast
<
float
*>
(
in_tensors_
[
0
]
->
Data
()),
a_c8_ptr_
);
InitMatrixB
(
reinterpret_cast
<
float
*>
(
in_tensors_
[
1
]
->
Data
()),
b_r8_ptr_
);
if
(
in_tensors_
.
size
()
==
3
)
{
bias_ptr_
=
reinterpret_cast
<
float
*>
(
malloc
(
params_
->
col_8_
*
sizeof
(
float
)));
memset
(
bias_ptr_
,
0
,
params_
->
col_8_
*
sizeof
(
float
));
...
...
@@ -89,6 +94,40 @@ int MatmulCPUKernel::Init() {
return
RET_OK
;
}
void
MatmulCPUKernel
::
InitMatrixA
(
float
*
src_ptr
,
float
*
dst_ptr
)
{
if
(
params_
->
a_const_
==
true
)
{
return
;
}
if
(
src_ptr
==
nullptr
)
{
return
;
}
params_
->
a_const_
=
true
;
if
(
params_
->
a_transpose_
)
{
RowMajor2Row8Major
(
src_ptr
,
dst_ptr
,
params_
->
deep_
,
params_
->
row_
);
}
else
{
RowMajor2Col8Major
(
src_ptr
,
a_c8_ptr_
,
params_
->
row_
,
params_
->
deep_
);
}
return
;
}
void
MatmulCPUKernel
::
InitMatrixB
(
float
*
src_ptr
,
float
*
dst_ptr
)
{
if
(
params_
->
b_const_
==
true
)
{
return
;
}
if
(
src_ptr
==
nullptr
)
{
return
;
}
params_
->
b_const_
=
true
;
if
(
params_
->
b_transpose_
)
{
RowMajor2Col8Major
(
src_ptr
,
dst_ptr
,
params_
->
col_
,
params_
->
deep_
);
}
else
{
RowMajor2Row8Major
(
src_ptr
,
dst_ptr
,
params_
->
deep_
,
params_
->
col_
);
}
return
;
}
int
MatmulCPUKernel
::
RunImpl
(
int
task_id
)
{
int
cur_oc
=
MSMIN
(
thread_stride_
,
UP_DIV
(
params_
->
col_8_
,
8
)
-
task_id
*
thread_stride_
);
if
(
cur_oc
<=
0
)
{
...
...
@@ -131,16 +170,10 @@ int MatmulCPUKernel::Run() {
auto
cur_a_ptr
=
a_ptr
+
i
*
a_stride
;
auto
cur_b_ptr
=
b_ptr
+
i
*
b_stride
;
auto
cur_c_ptr
=
c_ptr
+
i
*
c_stride
;
if
(
params_
->
a_transpose_
)
{
RowMajor2Row8Major
(
cur_a_ptr
,
a_c8_ptr_
,
params_
->
deep_
,
params_
->
row_
);
}
else
{
RowMajor2Col8Major
(
cur_a_ptr
,
a_c8_ptr_
,
params_
->
row_
,
params_
->
deep_
);
}
if
(
params_
->
b_transpose_
)
{
RowMajor2Col8Major
(
cur_b_ptr
,
b_r8_ptr_
,
params_
->
col_
,
params_
->
deep_
);
}
else
{
RowMajor2Row8Major
(
cur_b_ptr
,
b_r8_ptr_
,
params_
->
deep_
,
params_
->
col_
);
}
InitMatrixA
(
cur_a_ptr
,
a_c8_ptr_
);
InitMatrixB
(
cur_b_ptr
,
b_r8_ptr_
);
LiteBackendParallelLaunch
(
MatmulFloatRun
,
this
,
thread_count_
);
Row8x8Major2RowMajor
(
c_r8x8_ptr_
,
cur_c_ptr
,
params_
->
row_
,
params_
->
col_
,
params_
->
col_
);
}
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/matmul.h
浏览文件 @
0f75ab64
...
...
@@ -35,6 +35,10 @@ class MatmulCPUKernel : public MatmulBaseCPUKernel {
int
Run
()
override
;
int
RunImpl
(
int
task_id
);
private:
void
InitMatrixA
(
float
*
src_ptr
,
float
*
dst_ptr
);
void
InitMatrixB
(
float
*
src_ptr
,
float
*
dst_ptr
);
private:
float
*
a_c8_ptr_
;
float
*
b_r8_ptr_
;
...
...
mindspore/lite/src/runtime/kernel/arm/nnacl/matmul_parameter.h
浏览文件 @
0f75ab64
...
...
@@ -33,6 +33,8 @@ typedef struct MatMulParameter {
int
batch
;
bool
a_transpose_
;
/* false : row-major */
bool
b_transpose_
;
/* true : col-major */
bool
a_const_
;
bool
b_const_
;
ActType
act_type_
;
}
MatMulParameter
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录