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
878a7d09
Unverified
Commit
878a7d09
authored
Apr 07, 2020
by
Shucai Xiao
Committed by
GitHub
Apr 07, 2020
Browse files
fixed a bug in parse_slice (#489)
* fixed a bug in parse_slice * add a unit test * clang format
parent
e184395c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
15 deletions
+27
-15
src/onnx/onnx.cpp
src/onnx/onnx.cpp
+2
-15
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+15
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+10
-0
test/onnx/slice_max_end_test.onnx
test/onnx/slice_max_end_test.onnx
+0
-0
No files found.
src/onnx/onnx.cpp
View file @
878a7d09
...
@@ -797,7 +797,8 @@ struct onnx_parser
...
@@ -797,7 +797,8 @@ struct onnx_parser
}
}
else
if
(
contains
(
info
.
attributes
,
"ends"
))
else
if
(
contains
(
info
.
attributes
,
"ends"
))
{
{
op
.
ends
=
get_indices
(
info
.
attributes
.
at
(
"ends"
));
literal
s
=
parse_value
(
info
.
attributes
.
at
(
"ends"
));
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
op
.
ends
));
});
}
}
if
(
args
.
size
()
>=
2
)
if
(
args
.
size
()
>=
2
)
...
@@ -1966,20 +1967,6 @@ struct onnx_parser
...
@@ -1966,20 +1967,6 @@ struct onnx_parser
return
result
;
return
result
;
}
}
static
std
::
vector
<
int64_t
>
get_indices
(
const
onnx
::
AttributeProto
&
attr
)
{
std
::
vector
<
int64_t
>
result
;
literal
s
=
parse_value
(
attr
);
s
.
visit
([
&
](
auto
v
)
{
copy
(
v
,
std
::
back_inserter
(
result
));
});
// Clamp large indices to -1
std
::
replace_if
(
result
.
begin
(),
result
.
end
(),
[](
auto
x
)
{
return
x
>
int64_t
{
std
::
numeric_limits
<
std
::
int32_t
>::
max
()}
/
2
;
},
-
1
);
return
result
;
}
template
<
class
T
>
template
<
class
T
>
static
literal
from_repeated
(
shape
::
type_t
t
,
const
T
&
r
)
static
literal
from_repeated
(
shape
::
type_t
t
,
const
T
&
r
)
{
{
...
...
test/onnx/gen_onnx.py
View file @
878a7d09
...
@@ -1836,6 +1836,21 @@ def slice_5arg_test():
...
@@ -1836,6 +1836,21 @@ def slice_5arg_test():
return
([
arg_step
,
arg_axis
,
arg_end
,
arg_start
,
node
],
[
x
],
[
y
])
return
([
arg_step
,
arg_axis
,
arg_end
,
arg_start
,
node
],
[
x
],
[
y
])
@
onnx_test
def
slice_max_end_test
():
x
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT
,
[
10
,
20
])
y
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
FLOAT
,
[
9
,
17
])
node
=
onnx
.
helper
.
make_node
(
'Slice'
,
inputs
=
[
'0'
],
axes
=
[
0
,
1
],
starts
=
[
1
,
2
],
ends
=
[
3000000000
,
-
1
],
outputs
=
[
'1'
])
return
([
node
],
[
x
],
[
y
])
@
onnx_test
@
onnx_test
def
slice_test
():
def
slice_test
():
x
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT
,
[
3
,
2
])
x
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT
,
[
3
,
2
])
...
...
test/onnx/onnx_test.cpp
View file @
878a7d09
...
@@ -1392,6 +1392,16 @@ TEST_CASE(slice_5arg_test)
...
@@ -1392,6 +1392,16 @@ TEST_CASE(slice_5arg_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
slice_max_end_test
)
{
migraphx
::
program
p
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
10
,
20
}});
p
.
add_instruction
(
migraphx
::
op
::
slice
{{
0
,
1
},
{
1
,
2
},
{
3000000000
,
-
1
}},
l0
);
auto
prog
=
optimize_onnx
(
"slice_max_end_test.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
slice_test
)
TEST_CASE
(
slice_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
test/onnx/slice_max_end_test.onnx
0 → 100644
View file @
878a7d09
File added
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