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
0d5a6cd0
Commit
0d5a6cd0
authored
Jul 17, 2019
by
Khalique
Browse files
add slice and test
parent
03f5c679
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
0 deletions
+45
-0
src/tf/tf.cpp
src/tf/tf.cpp
+25
-0
test/tf/slice_test.pb
test/tf/slice_test.pb
+0
-0
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+20
-0
No files found.
src/tf/tf.cpp
View file @
0d5a6cd0
...
@@ -176,6 +176,7 @@ struct tf_parser
...
@@ -176,6 +176,7 @@ struct tf_parser
add_mem_op
(
"Pack"
,
&
tf_parser
::
parse_pack
,
false
);
add_mem_op
(
"Pack"
,
&
tf_parser
::
parse_pack
,
false
);
add_mem_op
(
"Pad"
,
&
tf_parser
::
parse_pad
);
add_mem_op
(
"Pad"
,
&
tf_parser
::
parse_pad
);
add_mem_op
(
"Reshape"
,
&
tf_parser
::
parse_reshape
,
false
);
add_mem_op
(
"Reshape"
,
&
tf_parser
::
parse_reshape
,
false
);
add_mem_op
(
"Slice"
,
&
tf_parser
::
parse_slice
,
false
);
add_mem_op
(
"Softmax"
,
&
tf_parser
::
parse_softmax
);
add_mem_op
(
"Softmax"
,
&
tf_parser
::
parse_softmax
);
add_mem_op
(
"Squeeze"
,
&
tf_parser
::
parse_squeeze
,
false
);
add_mem_op
(
"Squeeze"
,
&
tf_parser
::
parse_squeeze
,
false
);
add_mem_op
(
"StridedSlice"
,
&
tf_parser
::
parse_stridedslice
);
add_mem_op
(
"StridedSlice"
,
&
tf_parser
::
parse_stridedslice
);
...
@@ -735,6 +736,30 @@ struct tf_parser
...
@@ -735,6 +736,30 @@ struct tf_parser
return
prog
.
add_instruction
(
op
,
make_contiguous
(
args
[
0
]));
return
prog
.
add_instruction
(
op
,
make_contiguous
(
args
[
0
]));
}
}
instruction_ref
parse_slice
(
const
std
::
string
&
,
const
attribute_map
&
,
std
::
vector
<
instruction_ref
>
args
)
{
op
::
slice
op
;
auto
starts
=
args
[
1
]
->
eval
().
get
<
int32_t
>
().
to_vector
();
auto
size
=
args
[
2
]
->
eval
().
get
<
int32_t
>
().
to_vector
();
auto
axes
=
args
[
0
]
->
get_shape
().
lens
();
size_t
num_axes
=
axes
.
size
();
op
.
starts
=
std
::
vector
<
int64_t
>
(
starts
.
begin
(),
starts
.
end
());
op
.
ends
=
std
::
vector
<
int64_t
>
(
num_axes
);
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_axes
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
for
(
size_t
i
=
0
;
i
<
num_axes
;
i
++
)
{
if
(
size
[
i
]
==
-
1
)
op
.
ends
[
i
]
=
axes
[
i
];
else
op
.
ends
[
i
]
=
starts
[
i
]
+
size
[
i
];
}
return
prog
.
add_instruction
(
op
,
make_contiguous
(
args
[
0
]));
}
instruction_ref
parse_stridedslice
(
const
std
::
string
&
,
instruction_ref
parse_stridedslice
(
const
std
::
string
&
,
const
attribute_map
&
attributes
,
const
attribute_map
&
attributes
,
std
::
vector
<
instruction_ref
>
args
)
std
::
vector
<
instruction_ref
>
args
)
...
...
test/tf/slice_test.pb
0 → 100644
View file @
0d5a6cd0
File added
test/tf/tf_test.cpp
View file @
0d5a6cd0
...
@@ -351,6 +351,26 @@ TEST_CASE(reshape_test)
...
@@ -351,6 +351,26 @@ TEST_CASE(reshape_test)
EXPECT
(
p
==
prog
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
slice_test
)
{
migraphx
::
program
p
;
std
::
size_t
num_axes
=
2
;
auto
l0
=
p
.
add_parameter
(
"0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
5
,
10
}});
migraphx
::
shape
s0
{
migraphx
::
shape
::
int32_type
,
{
num_axes
}};
p
.
add_literal
(
migraphx
::
literal
{
s0
,
{
1
,
0
}});
p
.
add_literal
(
migraphx
::
literal
{
s0
,
{
2
,
-
1
}});
migraphx
::
op
::
slice
op
;
op
.
starts
=
{
1
,
0
};
op
.
ends
=
{
3
,
10
};
op
.
axes
=
std
::
vector
<
int64_t
>
(
num_axes
);
std
::
iota
(
op
.
axes
.
begin
(),
op
.
axes
.
end
(),
0
);
p
.
add_instruction
(
op
,
l0
);
auto
prog
=
optimize_tf
(
"slice_test.pb"
,
false
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
softmax_test
)
TEST_CASE
(
softmax_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
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