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
75c75d77
Commit
75c75d77
authored
Jul 02, 2019
by
Shucai Xiao
Browse files
add onnx test examples for the reduce_sum operator
parent
b0a47138
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
0 deletions
+83
-0
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+34
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+32
-0
test/onnx/reducesum_test1.onnx
test/onnx/reducesum_test1.onnx
+0
-0
test/onnx/reducesum_test2.onnx
test/onnx/reducesum_test2.onnx
+0
-0
test/onnx/reducesum_test3.onnx
test/onnx/reducesum_test3.onnx
+17
-0
No files found.
src/onnx/onnx.cpp
View file @
75c75d77
...
...
@@ -95,6 +95,7 @@ struct onnx_parser
add_mem_op
(
"GRU"
,
&
onnx_parser
::
parse_gru
);
add_mem_op
(
"LSTM"
,
&
onnx_parser
::
parse_lstm
);
add_mem_op
(
"Pad"
,
&
onnx_parser
::
parse_pad
);
add_mem_op
(
"ReduceSum"
,
&
onnx_parser
::
parse_reduce_sum
);
// init the activation function map
init_actv_func
();
...
...
@@ -1278,6 +1279,39 @@ struct onnx_parser
return
{
hidden_states
,
last_output
,
last_cell_output
};
}
instruction_ref
parse_reduce_sum
(
const
std
::
string
&
,
attribute_map
attributes
,
std
::
vector
<
instruction_ref
>
args
)
{
std
::
size_t
n_dim
=
args
.
front
()
->
get_shape
().
lens
().
size
();
// default to reduce over all dimensions
std
::
vector
<
std
::
size_t
>
axes
(
n_dim
);
std
::
iota
(
axes
.
begin
(),
axes
.
end
(),
0
);
if
(
contains
(
attributes
,
"axes"
))
{
axes
.
clear
();
auto
&&
attr_axes
=
attributes
[
"axes"
].
ints
();
axes
=
std
::
vector
<
std
::
size_t
>
(
attr_axes
.
begin
(),
attr_axes
.
end
());
}
int
keep_dims
=
1
;
if
(
contains
(
attributes
,
"keepdims"
))
{
keep_dims
=
parse_value
(
attributes
.
at
(
"keepdims"
)).
at
<
int
>
();
}
if
(
keep_dims
==
1
)
{
return
prog
.
add_instruction
(
op
::
reduce_sum
{
axes
},
std
::
move
(
args
));
}
else
{
auto
ins
=
prog
.
add_instruction
(
op
::
reduce_sum
{
axes
},
std
::
move
(
args
));
std
::
vector
<
int64_t
>
squeeze_axes
{
axes
.
begin
(),
axes
.
end
()};
return
prog
.
add_instruction
(
op
::
squeeze
{
squeeze_axes
},
ins
);
}
}
void
parse_from
(
std
::
istream
&
is
)
{
onnx
::
ModelProto
model
;
...
...
test/onnx/onnx_test.cpp
View file @
75c75d77
...
...
@@ -816,6 +816,38 @@ TEST_CASE(no_pad_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
reducesum_test1
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
,
6
}});
auto
l1
=
p
.
add_instruction
(
migraphx
::
op
::
reduce_sum
{{
2
}},
l0
);
p
.
add_instruction
(
migraphx
::
op
::
squeeze
{{
2
}},
l1
);
auto
prog
=
migraphx
::
parse_onnx
(
"reducesum_test1.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
reducesum_test2
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
,
6
}});
auto
l1
=
p
.
add_instruction
(
migraphx
::
op
::
reduce_sum
{{
2
,
3
}},
l0
);
p
.
add_instruction
(
migraphx
::
op
::
squeeze
{{
2
,
3
}},
l1
);
auto
prog
=
migraphx
::
parse_onnx
(
"reducesum_test2.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
reducesum_test3
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
,
6
}});
p
.
add_instruction
(
migraphx
::
op
::
reduce_sum
{{
2
,
3
}},
l0
);
auto
prog
=
migraphx
::
parse_onnx
(
"reducesum_test3.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
clip_test
)
{
migraphx
::
program
p
;
...
...
test/onnx/reducesum_test1.onnx
0 → 100644
View file @
75c75d77
File added
test/onnx/reducesum_test2.onnx
0 → 100644
View file @
75c75d77
File added
test/onnx/reducesum_test3.onnx
0 → 100644
View file @
75c75d77
reducesum-example:}
1
xy" ReduceSum*
axes@@*
keepdimstest_reducesumZ
x
b
y
B
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