Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_77200941
mindspore
提交
b367da88
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,发现更多精彩内容 >>
提交
b367da88
编写于
8月 20, 2020
作者:
H
huanghui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix ScatterNdUpdate cpu kernel
上级
6763b63c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
36 addition
and
32 deletion
+36
-32
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc
...ckend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc
+11
-18
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.h
...ackend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.h
+1
-1
mindspore/ccsrc/backend/kernel_compiler/cpu/unique_with_pad_cpu_kernel.h
.../backend/kernel_compiler/cpu/unique_with_pad_cpu_kernel.h
+2
-2
mindspore/core/ir/anf.cc
mindspore/core/ir/anf.cc
+13
-2
tests/st/ops/cpu/test_scatter_nd_update_op.py
tests/st/ops/cpu/test_scatter_nd_update_op.py
+9
-9
未找到文件。
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.cc
浏览文件 @
b367da88
...
...
@@ -25,9 +25,6 @@ void ScatterNdUpdateCPUKernel::InitKernel(const CNodePtr &kernel_node) {
auto
shape
=
AnfAlgo
::
GetPrevNodeOutputInferShape
(
kernel_node
,
0
);
auto
indices_shape
=
AnfAlgo
::
GetPrevNodeOutputInferShape
(
kernel_node
,
1
);
auto
updates_shape
=
AnfAlgo
::
GetPrevNodeOutputInferShape
(
kernel_node
,
2
);
if
(
indices_shape
.
size
()
<
2
)
{
MS_LOG
(
EXCEPTION
)
<<
"Indices' dimension less than 2"
;
}
auto
indices_unit_rank
=
indices_shape
.
back
();
if
(
indices_unit_rank
>
shape
.
size
())
{
MS_LOG
(
EXCEPTION
)
<<
"Value of last dimension of indices is greater than shape rank"
;
...
...
@@ -66,11 +63,11 @@ void ScatterNdUpdateCPUKernel::InitKernel(const CNodePtr &kernel_node) {
bool
ScatterNdUpdateCPUKernel
::
Launch
(
const
std
::
vector
<
kernel
::
AddressPtr
>
&
inputs
,
const
std
::
vector
<
kernel
::
AddressPtr
>
&
/*workspace*/
,
const
std
::
vector
<
kernel
::
AddressPtr
>
&
outputs
)
{
const
std
::
vector
<
kernel
::
AddressPtr
>
&
/*outputs*/
)
{
if
(
dtype_
==
kNumberTypeFloat16
)
{
LaunchKernel
<
float16
>
(
inputs
,
outputs
);
LaunchKernel
<
float16
>
(
inputs
);
}
else
if
(
dtype_
==
kNumberTypeFloat32
)
{
LaunchKernel
<
float
>
(
inputs
,
outputs
);
LaunchKernel
<
float
>
(
inputs
);
}
else
{
MS_LOG
(
ERROR
)
<<
"Only support float16, float32"
;
return
false
;
...
...
@@ -79,30 +76,26 @@ bool ScatterNdUpdateCPUKernel::Launch(const std::vector<kernel::AddressPtr> &inp
}
template
<
typename
T
>
void
ScatterNdUpdateCPUKernel
::
LaunchKernel
(
const
std
::
vector
<
AddressPtr
>
&
inputs
,
const
std
::
vector
<
AddressPtr
>
&
outputs
)
{
void
ScatterNdUpdateCPUKernel
::
LaunchKernel
(
const
std
::
vector
<
AddressPtr
>
&
inputs
)
{
auto
x
=
reinterpret_cast
<
T
*>
(
inputs
[
0
]
->
addr
);
auto
indices
=
reinterpret_cast
<
int
*>
(
inputs
[
1
]
->
addr
);
auto
updates
=
reinterpret_cast
<
T
*>
(
inputs
[
2
]
->
addr
);
auto
y
=
reinterpret_cast
<
T
*>
(
outputs
[
0
]
->
addr
);
for
(
int
i
=
0
;
i
<
num_units_
;
++
i
)
{
int
offset
=
0
;
for
(
int
j
=
0
;
j
<
indices_unit_rank_
;
++
j
)
{
offset
+=
indices
[
i
*
indices_unit_rank_
+
j
]
*
out_strides_
[
j
]
*
unit_size_
;
auto
index
=
indices
[
i
*
indices_unit_rank_
+
j
];
if
(
index
<
0
)
{
MS_LOG
(
EXCEPTION
)
<<
"Error, Indices exist element which less than 0. element="
<<
index
;
}
offset
+=
index
*
out_strides_
[
j
]
*
unit_size_
;
}
output_unit_offsets_
[
i
]
=
offset
;
}
auto
mem_bits
=
outputs
[
0
]
->
size
;
auto
ret
=
memcpy_s
(
y
,
mem_bits
,
x
,
mem_bits
);
if
(
ret
!=
0
)
{
MS_LOG
(
EXCEPTION
)
<<
"memcpy_s error, errorno"
<<
ret
;
}
for
(
int
i
=
0
;
i
<
num_units_
;
i
++
)
{
ret
=
memcpy_s
(
y
+
output_unit_offsets_
[
i
],
unit_size_
*
sizeof
(
T
),
updates
+
unit_size_
*
i
,
unit_size_
*
sizeof
(
T
));
auto
ret
=
memcpy_s
(
x
+
output_unit_offsets_
[
i
],
unit_size_
*
sizeof
(
T
),
updates
+
unit_size_
*
i
,
unit_size_
*
sizeof
(
T
));
if
(
ret
!=
0
)
{
MS_LOG
(
EXCEPTION
)
<<
"memcpy_s error, errorno"
<<
ret
;
}
...
...
mindspore/ccsrc/backend/kernel_compiler/cpu/scatter_nd_update_cpu_kernel.h
浏览文件 @
b367da88
...
...
@@ -35,7 +35,7 @@ class ScatterNdUpdateCPUKernel : public CPUKernel {
const
std
::
vector
<
AddressPtr
>
&
outputs
)
override
;
template
<
typename
T
>
void
LaunchKernel
(
const
std
::
vector
<
AddressPtr
>
&
inputs
,
const
std
::
vector
<
AddressPtr
>
&
outputs
);
void
LaunchKernel
(
const
std
::
vector
<
AddressPtr
>
&
inputs
);
private:
void
Check
(
const
CNodePtr
&
kernel_node
);
...
...
mindspore/ccsrc/backend/kernel_compiler/cpu/unique_with_pad_cpu_kernel.h
浏览文件 @
b367da88
...
...
@@ -39,8 +39,8 @@ class UniqueWithPadCPUKernel : public CPUKernel {
private:
void
CheckParam
(
const
CNodePtr
&
kernel_node
);
int64_t
n_
;
TypeId
dtype_
;
int64_t
n_
{
0
}
;
TypeId
dtype_
{
0
}
;
};
MS_REG_CPU_KERNEL
(
UniqueWithPad
,
...
...
mindspore/core/ir/anf.cc
浏览文件 @
b367da88
...
...
@@ -224,6 +224,14 @@ std::string GetMaketupleNodeTarget(const CNodePtr &cnode) {
std
::
string
default_target
=
context_ptr
->
device_target
();
return
default_target
;
}
std
::
string
GetTupleGetItemTarget
(
const
CNodePtr
&
cnode
,
const
PrimitivePtr
&
primitive
)
{
MS_EXCEPTION_IF_NULL
(
cnode
);
MS_EXCEPTION_IF_NULL
(
primitive
);
auto
input_target
=
GetCNodeTarget
(
cnode
->
input
(
1
));
primitive
->
set_attr
(
"primitive_target"
,
MakeValue
(
input_target
));
return
input_target
;
}
}
// namespace
std
::
string
GetCNodeTarget
(
const
AnfNodePtr
&
node
)
{
...
...
@@ -256,8 +264,8 @@ std::string GetCNodeTarget(const AnfNodePtr &node) {
if
(
IsPrimitive
(
attr_input
,
prim
::
kPrimImageSummary
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimScalarSummary
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimTensorSummary
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimHistogramSummary
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimStateSetItem
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimDepend
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrim
TupleGetItem
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimControlDepend
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrim
Return
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrim
Partial
))
{
IsPrimitive
(
attr_input
,
prim
::
kPrim
ControlDepend
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimReturn
)
||
IsPrimitive
(
attr_input
,
prim
::
kPrimPartial
))
{
primitive
->
EraseAttr
(
"primitive_target"
);
return
default_target
;
}
...
...
@@ -273,6 +281,9 @@ std::string GetCNodeTarget(const AnfNodePtr &node) {
if
(
IsPrimitiveCNode
(
node
,
prim
::
kPrimMakeTuple
))
{
return
GetMaketupleNodeTarget
(
cnode
);
}
if
(
IsPrimitiveCNode
(
node
,
prim
::
kPrimTupleGetItem
))
{
return
GetTupleGetItemTarget
(
cnode
,
primitive
);
}
return
default_target
;
}
}
// namespace mindspore
tests/st/ops/cpu/test_scatter_nd_update_op.py
浏览文件 @
b367da88
...
...
@@ -64,10 +64,10 @@ def test_op1():
update
=
Tensor
(
np
.
array
([
1.0
,
2.2
]),
mstype
.
float32
)
scatter_nd_update
=
ScatterNdUpdate1
()
output
=
scatter_nd_update
(
indices
,
update
)
print
(
"
output:
\n
"
,
out
put
)
scatter_nd_update
(
indices
,
update
)
print
(
"
x:
\n
"
,
scatter_nd_update
.
x
.
default_in
put
)
expect
=
[[
1.0
,
0.3
,
3.6
],
[
0.4
,
2.2
,
-
3.2
]]
assert
np
.
allclose
(
out
put
.
asnumpy
(),
np
.
array
(
expect
,
np
.
float
))
assert
np
.
allclose
(
scatter_nd_update
.
x
.
default_in
put
.
asnumpy
(),
np
.
array
(
expect
,
np
.
float
))
@
pytest
.
mark
.
level0
...
...
@@ -78,10 +78,10 @@ def test_op2():
update
=
Tensor
(
np
.
array
([
9
,
10
,
11
,
12
]),
mstype
.
float32
)
scatter_nd_update
=
ScatterNdUpdate2
()
output
=
scatter_nd_update
(
indices
,
update
)
print
(
"
output:
\n
"
,
out
put
)
scatter_nd_update
(
indices
,
update
)
print
(
"
x:
\n
"
,
scatter_nd_update
.
x
.
default_in
put
)
expect
=
[
1
,
11
,
3
,
10
,
9
,
6
,
7
,
12
]
assert
np
.
allclose
(
out
put
.
asnumpy
(),
np
.
array
(
expect
,
dtype
=
float
))
assert
np
.
allclose
(
scatter_nd_update
.
x
.
default_in
put
.
asnumpy
(),
np
.
array
(
expect
,
dtype
=
float
))
@
pytest
.
mark
.
level0
...
...
@@ -95,10 +95,10 @@ def test_op3():
[
7
,
7
,
7
,
7
],
[
8
,
8
,
8
,
8
]]]),
mstype
.
float32
)
scatter_nd_update
=
ScatterNdUpdate3
()
output
=
scatter_nd_update
(
indices
,
update
)
print
(
"
output:
\n
"
,
out
put
)
scatter_nd_update
(
indices
,
update
)
print
(
"
x:
\n
"
,
scatter_nd_update
.
x
.
default_in
put
)
expect
=
[[[
5
,
5
,
5
,
5
],
[
6
,
6
,
6
,
6
],
[
7
,
7
,
7
,
7
],
[
8
,
8
,
8
,
8
]],
[[
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
]],
[[
5
,
5
,
5
,
5
],
[
6
,
6
,
6
,
6
],
[
7
,
7
,
7
,
7
],
[
8
,
8
,
8
,
8
]],
[[
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
]]]
assert
np
.
allclose
(
out
put
.
asnumpy
(),
np
.
array
(
expect
,
dtype
=
float
))
assert
np
.
allclose
(
scatter_nd_update
.
x
.
default_in
put
.
asnumpy
(),
np
.
array
(
expect
,
dtype
=
float
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录