Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
f8027a4c
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看板
提交
f8027a4c
编写于
8月 21, 2020
作者:
王
王明贵
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix sigmoid activation bug
上级
b964e890
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
30 deletion
+38
-30
mindspore/lite/nnacl/fp32/activation.c
mindspore/lite/nnacl/fp32/activation.c
+12
-1
mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc
mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc
+24
-25
mindspore/lite/src/runtime/kernel/arm/fp32/gather.h
mindspore/lite/src/runtime/kernel/arm/fp32/gather.h
+2
-4
未找到文件。
mindspore/lite/nnacl/fp32/activation.c
浏览文件 @
f8027a4c
...
...
@@ -43,8 +43,19 @@ int LRelu(const float *src, int length, float *dst, float alpha) {
}
int
Sigmoid
(
const
float
*
src
,
int
length
,
float
*
dst
)
{
const
float
upper_bound
=
16
.
619047164916992188
f
;
const
float
lower_bound
=
-
9
.
0
f
;
for
(
int
i
=
0
;
i
<
length
;
++
i
)
{
dst
[
i
]
=
1
.
0
f
/
(
1
.
0
f
+
exp
(
-
src
[
i
]));
float
input_val
=
src
[
i
];
float
result
;
if
(
input_val
>
upper_bound
)
{
result
=
1
.
0
f
;
}
else
if
(
input_val
<
lower_bound
)
{
result
=
exp
(
input_val
);
}
else
{
result
=
1
.
0
f
/
(
1
.
0
f
+
exp
(
-
input_val
));
}
dst
[
i
]
=
result
;
}
return
NNACL_OK
;
}
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc
浏览文件 @
f8027a4c
...
...
@@ -31,8 +31,6 @@ using mindspore::schema::PrimitiveType_Gather;
namespace
mindspore
::
kernel
{
int
GatherCPUKernel
::
Init
()
{
axis_
=
(
reinterpret_cast
<
GatherParameter
*>
(
op_parameter_
))
->
axis_
;
batchDims_
=
(
reinterpret_cast
<
GatherParameter
*>
(
op_parameter_
))
->
batchDims_
;
if
(
!
InferShapeDone
())
{
return
RET_OK
;
}
...
...
@@ -47,7 +45,7 @@ int GatherCPUKernel::DoGather(int task_id) {
auto
out_tensor
=
out_tensors_
.
at
(
0
);
auto
input_ptr
=
reinterpret_cast
<
float
*>
(
input_tensor
->
Data
());
auto
indices_ptr
=
reinterpret_cast
<
in
t
*>
(
indices_tensor
->
Data
());
auto
indices_ptr
=
reinterpret_cast
<
floa
t
*>
(
indices_tensor
->
Data
());
auto
output_ptr
=
reinterpret_cast
<
float
*>
(
out_tensor
->
Data
());
auto
input_int32
=
reinterpret_cast
<
int32_t
*>
(
input_tensor
->
Data
());
...
...
@@ -56,26 +54,25 @@ int GatherCPUKernel::DoGather(int task_id) {
auto
in_shape
=
input_tensor
->
shape
();
int
in_rank
=
in_shape
.
size
();
int
indices_element_size
=
indices_tensor
->
ElementsNum
();
auto
axis
=
(
reinterpret_cast
<
GatherParameter
*>
(
op_parameter_
))
->
axis_
;
const
int
limit
=
in_shape
[
axis
_
];
const
int
limit
=
in_shape
[
axis
];
for
(
int
i
=
0
;
i
<
indices_element_size
;
++
i
)
{
if
(
indices_ptr
[
i
]
>=
limit
)
{
MS_LOG
(
ERROR
)
<<
" indice data: "
<<
indices_ptr
[
i
]
<<
" is not in [ 0, "
<<
limit
-
1
<<
" ]"
;
indices_data_
[
i
]
=
static_cast
<
int
>
(
indices_ptr
[
i
]);
if
(
indices_data_
[
i
]
>=
limit
)
{
MS_LOG
(
ERROR
)
<<
" indice data: "
<<
indices_data_
[
i
]
<<
" is not in [ 0, "
<<
limit
-
1
<<
" ]"
;
return
RET_ERROR
;
}
}
int
outer_size
=
1
;
for
(
int
i
=
0
;
i
<
axis
_
;
++
i
)
{
int
outer_size
=
1
,
inner_size
=
1
;
for
(
int
i
=
0
;
i
<
axis
;
++
i
)
{
outer_size
*=
in_shape
[
i
];
}
int
inner_size
=
1
;
for
(
int
i
=
axis_
+
1
;
i
<
in_rank
;
++
i
)
{
for
(
int
i
=
axis
+
1
;
i
<
in_rank
;
++
i
)
{
inner_size
*=
in_shape
[
i
];
}
int
stride
=
UP_DIV
(
outer_size
,
thread_count_
);
int
stride
=
UP_DIV
(
outer_size
,
op_parameter_
->
thread_num_
);
int
count
=
MSMIN
(
stride
,
outer_size
-
stride
*
task_id
);
auto
thread_stride
=
stride
*
task_id
;
...
...
@@ -83,17 +80,13 @@ int GatherCPUKernel::DoGather(int task_id) {
if
(
input_tensor
->
data_type
()
==
kNumberTypeInt32
)
{
input_int32
+=
thread_stride
*
limit
;
output_int32
+=
thread_stride
*
indices_element_size
;
error_code
=
GatherInt32
(
input_int32
,
count
,
inner_size
,
limit
,
indices_
ptr
,
indices_element_size
,
output_int32
);
error_code
=
GatherInt32
(
input_int32
,
count
,
inner_size
,
limit
,
indices_
data_
,
indices_element_size
,
output_int32
);
}
else
{
input_ptr
+=
thread_stride
*
limit
;
output_ptr
+=
thread_stride
*
indices_element_size
;
error_code
=
Gather
(
input_ptr
,
count
,
inner_size
,
limit
,
indices_ptr
,
indices_element_size
,
output_ptr
);
}
if
(
error_code
!=
RET_OK
)
{
return
RET_ERROR
;
error_code
=
Gather
(
input_ptr
,
count
,
inner_size
,
limit
,
indices_data_
,
indices_element_size
,
output_ptr
);
}
return
RET_OK
;
return
error_code
;
}
int
GatherRun
(
int
task_id
,
LiteParallelGroupEnv
*
penv
,
void
*
cdata
)
{
...
...
@@ -101,9 +94,8 @@ int GatherRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) {
auto
error_code
=
gather_kernel
->
DoGather
(
task_id
);
if
(
error_code
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"GatherRun error task_id["
<<
task_id
<<
"] error_code["
<<
error_code
<<
"]"
;
return
RET_ERROR
;
}
return
RET_OK
;
return
error_code
;
}
int
GatherCPUKernel
::
Run
()
{
...
...
@@ -112,12 +104,19 @@ int GatherCPUKernel::Run() {
MS_LOG
(
ERROR
)
<<
"Prepare fail!ret: "
<<
prepare_ret
;
return
prepare_ret
;
}
int
error_code
=
LiteBackendParallelLaunch
(
GatherRun
,
this
,
thread_count_
);
auto
indices_tensor
=
in_tensors_
.
at
(
1
);
indices_data_
=
reinterpret_cast
<
int
*>
(
context_
->
allocator
->
Malloc
(
indices_tensor
->
ElementsNum
()
*
sizeof
(
int
)));
if
(
indices_data_
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"Memory allocation failed"
;
context_
->
allocator
->
Free
(
indices_data_
);
return
RET_ERROR
;
}
int
error_code
=
LiteBackendParallelLaunch
(
GatherRun
,
this
,
op_parameter_
->
thread_num_
);
if
(
error_code
!=
RET_OK
)
{
MS_LOG
(
ERROR
)
<<
"Gather function error error_code["
<<
error_code
<<
"]"
;
return
RET_ERROR
;
}
return
RET_OK
;
return
error_code
;
}
kernel
::
LiteKernel
*
CpuGatherFp32KernelCreator
(
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
...
...
mindspore/lite/src/runtime/kernel/arm/fp32/gather.h
浏览文件 @
f8027a4c
...
...
@@ -27,7 +27,7 @@ class GatherCPUKernel : public LiteKernel {
GatherCPUKernel
(
OpParameter
*
parameter
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
lite
::
tensor
::
Tensor
*>
&
outputs
,
const
lite
::
Context
*
ctx
,
const
mindspore
::
lite
::
PrimitiveC
*
primitive
)
:
LiteKernel
(
parameter
,
inputs
,
outputs
,
ctx
,
primitive
)
,
thread_count_
(
ctx
->
thread_num_
)
{}
:
LiteKernel
(
parameter
,
inputs
,
outputs
,
ctx
,
primitive
)
{}
~
GatherCPUKernel
()
override
=
default
;
int
Init
()
override
;
...
...
@@ -36,9 +36,7 @@ class GatherCPUKernel : public LiteKernel {
int
DoGather
(
int
task_id
);
private:
int
thread_count_
;
int
batchDims_
;
int
axis_
;
int
*
indices_data_
;
};
}
// namespace mindspore::kernel
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录