Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
93db029b
Commit
93db029b
authored
Feb 24, 2019
by
Shucai Xiao
Browse files
new CPU implementation of the gather operator.
parent
69c19fcc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
30 deletions
+28
-30
src/include/migraphx/operators.hpp
src/include/migraphx/operators.hpp
+28
-30
No files found.
src/include/migraphx/operators.hpp
View file @
93db029b
...
...
@@ -766,7 +766,7 @@ struct gather
}
// for scalar output
if
(
lens
.
empty
()
)
if
(
lens
.
size
()
==
0
)
{
return
{
type
,
{
1
},
{
0
}};
}
...
...
@@ -778,40 +778,38 @@ struct gather
{
argument
result
{
output_shape
};
// negative axis means counting dimensions from back
auto
data_shape
=
args
[
0
].
get_shape
();
int
axis_index
=
(
axis
<
0
)
?
(
data_shape
.
lens
().
size
()
+
axis
)
:
axis
;
int
axis_index
=
(
axis
<
0
)
?
(
args
[
0
].
get_shape
().
lens
().
size
()
+
axis
)
:
axis
;
// max dimension in axis
visit_all
(
result
,
args
[
0
])([
&
](
auto
output
,
auto
data
)
{
std
::
vector
<
std
::
size_t
>
vec_indices
;
args
[
1
].
visit
(
[
&
](
auto
indices
)
{
vec_indices
.
assign
(
indices
.
begin
(),
indices
.
end
());
});
if
(
output_shape
.
scalar
())
{
output
[
0
]
=
data
[
vec_indices
.
front
()];
}
else
{
shape_for_each
(
output_shape
,
[
&
](
const
auto
&
out_idx
)
{
auto
data_idx
=
out_idx
;
if
(
args
[
1
].
get_shape
().
scalar
())
{
data_idx
.
insert
(
data_idx
.
begin
()
+
axis_index
,
vec_indices
.
front
());
}
else
{
args
[
1
].
visit
([
&
](
auto
ind
)
{
args
[
1
].
visit
([
&
](
auto
indices
)
{
if
(
output_shape
.
scalar
())
{
output
[
0
]
=
data
[
indices
.
front
()];
}
else
{
shape_for_each
(
output
.
get_shape
(),
[
&
](
const
auto
&
out_idx
)
{
auto
data_idx
=
out_idx
;
std
::
size_t
index
{};
if
(
!
indices
.
get_shape
().
scalar
())
{
auto
start_it
=
data_idx
.
begin
()
+
axis_index
;
auto
end_it
=
data_idx
.
end
()
+
axis_index
+
args
[
1
].
get_shape
().
lens
().
size
();
auto
end_it
=
data_idx
.
begin
()
+
axis_index
+
indices
.
get_shape
().
lens
().
size
();
std
::
vector
<
std
::
size_t
>
ind_idx
(
start_it
,
end_it
);
auto
ind_it
=
data_idx
.
erase
(
start_it
,
end_it
);
data_idx
.
insert
(
ind_it
,
ind
(
ind_idx
.
begin
(),
ind_idx
.
end
()));
});
}
output
(
out_idx
.
begin
(),
out_idx
.
end
())
=
data
(
data_idx
.
begin
(),
data_idx
.
end
());
});
}
data_idx
.
erase
(
start_it
,
end_it
);
index
=
indices
(
ind_idx
.
begin
(),
ind_idx
.
end
());
}
else
{
index
=
indices
.
front
();
}
data_idx
.
insert
(
data_idx
.
begin
()
+
axis_index
,
index
);
output
(
out_idx
.
begin
(),
out_idx
.
end
())
=
data
(
data_idx
.
begin
(),
data_idx
.
end
());
});
}
});
});
return
result
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment