Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
c5633365
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看板
提交
c5633365
编写于
9月 02, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
9月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
!5643 [MS][LITE][Develop]optimize div
Merge pull request !5643 from chenjianping/lite_dev2
上级
9730e1f4
2f2ec654
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
93 addition
and
0 deletion
+93
-0
mindspore/lite/nnacl/fp32/arithmetic.c
mindspore/lite/nnacl/fp32/arithmetic.c
+59
-0
mindspore/lite/nnacl/fp32/arithmetic.h
mindspore/lite/nnacl/fp32/arithmetic.h
+3
-0
mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc
mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc
+16
-0
mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/arithmetic_fp32_tests.cc
...t/ut/src/runtime/kernel/arm/fp32/arithmetic_fp32_tests.cc
+15
-0
未找到文件。
mindspore/lite/nnacl/fp32/arithmetic.c
浏览文件 @
c5633365
...
...
@@ -470,6 +470,65 @@ int ElementOptAddRelu6(float *input0, float *input1, float *output, int element_
return
NNACL_OK
;
}
int
ElementOptDiv
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
)
{
if
(
param
->
in_elements_num0_
==
1
)
{
for
(
int
index
=
0
;
index
<
element_size
;
++
index
)
{
if
(
input1
[
index
]
==
0
)
{
return
NNACL_ERRCODE_DIVISOR_ZERO
;
}
output
[
index
]
=
input0
[
0
]
/
input1
[
index
];
}
}
else
{
if
(
input1
[
0
]
==
0
)
{
return
NNACL_ERRCODE_DIVISOR_ZERO
;
}
for
(
int
index
=
0
;
index
<
element_size
;
++
index
)
{
output
[
index
]
=
input0
[
index
]
/
input1
[
0
];
}
}
return
NNACL_OK
;
}
int
ElementOptDivRelu
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
)
{
if
(
param
->
in_elements_num0_
==
1
)
{
for
(
int
index
=
0
;
index
<
element_size
;
++
index
)
{
if
(
input1
[
index
]
==
0
)
{
return
NNACL_ERRCODE_DIVISOR_ZERO
;
}
output
[
index
]
=
input0
[
0
]
/
input1
[
index
];
output
[
index
]
=
output
[
index
]
>
0
?
output
[
index
]
:
0
;
}
}
else
{
if
(
input1
[
0
]
==
0
)
{
return
NNACL_ERRCODE_DIVISOR_ZERO
;
}
for
(
int
index
=
0
;
index
<
element_size
;
++
index
)
{
output
[
index
]
=
input0
[
index
]
/
input1
[
0
];
output
[
index
]
=
output
[
index
]
>
0
?
output
[
index
]
:
0
;
}
}
return
NNACL_OK
;
}
int
ElementOptDivRelu6
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
)
{
if
(
param
->
in_elements_num0_
==
1
)
{
for
(
int
index
=
0
;
index
<
element_size
;
++
index
)
{
if
(
input1
[
index
]
==
0
)
{
return
NNACL_ERRCODE_DIVISOR_ZERO
;
}
output
[
index
]
=
MSMIN
(
MSMAX
(
input0
[
0
]
/
input1
[
index
],
0
),
6
);
}
}
else
{
if
(
input1
[
0
]
==
0
)
{
return
NNACL_ERRCODE_DIVISOR_ZERO
;
}
for
(
int
index
=
0
;
index
<
element_size
;
++
index
)
{
output
[
index
]
=
MSMIN
(
MSMAX
(
input0
[
index
]
/
input1
[
0
],
0
),
6
);
}
}
return
NNACL_OK
;
}
int
ElementMul
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
)
{
int
block_mod
=
element_size
%
C4NUM
;
int
block_c4
=
element_size
-
block_mod
;
...
...
mindspore/lite/nnacl/fp32/arithmetic.h
浏览文件 @
c5633365
...
...
@@ -35,6 +35,9 @@ int ElementOptSubRelu6(float *input0, float *input1, float *output, int element_
int
ElementOptMul
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
);
int
ElementOptMulRelu
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
);
int
ElementOptMulRelu6
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
);
int
ElementOptDiv
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
);
int
ElementOptDivRelu
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
);
int
ElementOptDivRelu6
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
,
ArithmeticParameter
*
param
);
int
ElementMul
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
);
int
ElementMulRelu
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
);
int
ElementMulRelu6
(
float
*
input0
,
float
*
input1
,
float
*
output
,
int
element_size
);
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc
浏览文件 @
c5633365
...
...
@@ -94,6 +94,22 @@ int ArithmeticCPUKernel::ReSize() {
break
;
}
break
;
case
PrimitiveType_Div
:
switch
(
arithmeticParameter_
->
activation_type_
)
{
case
schema
::
ActivationType_RELU
:
arithmeticParameter_
->
broadcasting_
=
false
;
arithmetic_opt_run_
=
ElementOptDivRelu
;
break
;
case
schema
::
ActivationType_RELU6
:
arithmeticParameter_
->
broadcasting_
=
false
;
arithmetic_opt_run_
=
ElementOptDivRelu6
;
break
;
default:
arithmeticParameter_
->
broadcasting_
=
false
;
arithmetic_opt_run_
=
ElementOptDiv
;
break
;
}
break
;
default:
break
;
}
...
...
mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/arithmetic_fp32_tests.cc
浏览文件 @
c5633365
...
...
@@ -158,6 +158,21 @@ TEST_F(TestArithmeticTestFp32, DivTest) {
delete
div_param
;
}
TEST_F
(
TestArithmeticTestFp32
,
DivTest2
)
{
std
::
vector
<
float
>
in0
=
{
10
,
20
,
30
,
40
,
50
,
60
,
70
,
80
,
90
,
100
};
std
::
vector
<
float
>
in1
=
{
5
,
10
,
2
,
8
,
2
,
3
,
7
,
80
,
45
,
20
};
std
::
vector
<
float
>
correct_out
=
{
2
,
2
,
15
,
5
,
25
,
20
,
10
,
1
,
2
,
5
};
constexpr
int
kOutSize
=
10
;
float
out
[
kOutSize
];
ElementDiv
(
in0
.
data
(),
in1
.
data
(),
out
,
kOutSize
);
std
::
cout
<<
"out: "
;
for
(
int
i
=
0
;
i
<
kOutSize
;
++
i
)
{
std
::
cout
<<
out
[
i
]
<<
" "
;
}
std
::
cout
<<
"
\n
"
;
CompareOutputData
(
out
,
correct_out
.
data
(),
kOutSize
,
0.00001
);
}
TEST_F
(
TestArithmeticTestFp32
,
FloorDivTest
)
{
auto
fdiv_param
=
new
ArithmeticParameter
();
fdiv_param
->
ndim_
=
4
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录