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
52f44f87
Commit
52f44f87
authored
Aug 12, 2018
by
Paul
Browse files
Formatting
parent
d2a38cd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
src/simplify_reshapes.cpp
src/simplify_reshapes.cpp
+10
-10
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+5
-5
No files found.
src/simplify_reshapes.cpp
View file @
52f44f87
...
@@ -10,12 +10,10 @@ namespace migraph {
...
@@ -10,12 +10,10 @@ namespace migraph {
bool
is_reshaper
(
const
std
::
string
&
name
)
bool
is_reshaper
(
const
std
::
string
&
name
)
{
{
static
const
std
::
unordered_set
<
std
::
string
>
names
=
{
static
const
std
::
unordered_set
<
std
::
string
>
names
=
{
"reshape"
,
"reshape"
,
"transpose"
,
"transpose"
,
// "broadcast",
// "broadcast",
"contiguous"
};
"contiguous"
};
return
contains
(
names
,
name
);
return
contains
(
names
,
name
);
}
}
...
@@ -31,7 +29,7 @@ void simplify_reshapes::apply(program& p) const
...
@@ -31,7 +29,7 @@ void simplify_reshapes::apply(program& p) const
continue
;
continue
;
// Gather reshapes
// Gather reshapes
std
::
vector
<
instruction_ref
>
reshapes
{
ins
};
std
::
vector
<
instruction_ref
>
reshapes
{
ins
};
while
(
is_reshaper
(
reshapes
.
back
()
->
op
.
name
()))
while
(
is_reshaper
(
reshapes
.
back
()
->
op
.
name
()))
{
{
assert
(
!
reshapes
.
back
()
->
arguments
.
empty
());
assert
(
!
reshapes
.
back
()
->
arguments
.
empty
());
assert
(
p
.
has_instruction
(
reshapes
.
back
()
->
arguments
.
front
()));
assert
(
p
.
has_instruction
(
reshapes
.
back
()
->
arguments
.
front
()));
...
@@ -39,17 +37,19 @@ void simplify_reshapes::apply(program& p) const
...
@@ -39,17 +37,19 @@ void simplify_reshapes::apply(program& p) const
}
}
std
::
pair
<
instruction_ref
,
instruction_ref
>
r
{
p
.
end
(),
p
.
end
()};
std
::
pair
<
instruction_ref
,
instruction_ref
>
r
{
p
.
end
(),
p
.
end
()};
for
(
auto
start
:
iterator_for
(
reshapes
))
for
(
auto
start
:
iterator_for
(
reshapes
))
{
{
auto
last
=
std
::
find_if
(
reshapes
.
rbegin
(),
reshapes
.
rend
(),
[
&
](
auto
&&
i
)
{
auto
last
=
std
::
find_if
(
reshapes
.
rbegin
(),
reshapes
.
rend
(),
[
&
](
auto
&&
i
)
{
return
i
->
result
==
(
*
start
)
->
result
and
i
!=
(
*
start
);
return
i
->
result
==
(
*
start
)
->
result
and
i
!=
(
*
start
);
});
});
if
(
last
!=
reshapes
.
rend
())
{
if
(
last
!=
reshapes
.
rend
())
{
r
=
std
::
make_pair
(
*
start
,
*
last
);
r
=
std
::
make_pair
(
*
start
,
*
last
);
break
;
break
;
}
}
}
}
if
(
r
.
first
!=
r
.
second
)
{
if
(
r
.
first
!=
r
.
second
)
{
p
.
replace_instruction
(
r
.
first
,
r
.
second
);
p
.
replace_instruction
(
r
.
first
,
r
.
second
);
}
}
}
}
...
...
test/simplify_reshapes_test.cpp
View file @
52f44f87
...
@@ -34,7 +34,7 @@ migraph::literal get_2_broadcasted()
...
@@ -34,7 +34,7 @@ migraph::literal get_2_broadcasted()
void
double_contig
()
void
double_contig
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
::
contiguous
{},
t1
);
auto
c1
=
p
.
add_instruction
(
migraph
::
contiguous
{},
t1
);
auto
c2
=
p
.
add_instruction
(
migraph
::
contiguous
{},
c1
);
auto
c2
=
p
.
add_instruction
(
migraph
::
contiguous
{},
c1
);
...
@@ -52,7 +52,7 @@ void double_contig()
...
@@ -52,7 +52,7 @@ void double_contig()
void
double_transpose
()
void
double_transpose
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
t2
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
t1
);
auto
t2
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
t1
);
p
.
add_instruction
(
pass_op
{},
t2
);
p
.
add_instruction
(
pass_op
{},
t2
);
...
@@ -69,7 +69,7 @@ void double_transpose()
...
@@ -69,7 +69,7 @@ void double_transpose()
void
double_transpose_contig
()
void
double_transpose_contig
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
c1
=
p
.
add_instruction
(
migraph
::
contiguous
{},
t1
);
auto
c1
=
p
.
add_instruction
(
migraph
::
contiguous
{},
t1
);
auto
t2
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
c1
);
auto
t2
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
c1
);
...
@@ -88,7 +88,7 @@ void double_transpose_contig()
...
@@ -88,7 +88,7 @@ void double_transpose_contig()
void
single_transpose
()
void
single_transpose
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
pass_op
{},
t1
);
p
.
add_instruction
(
pass_op
{},
t1
);
EXPECT
(
not
p
.
get_shape
().
standard
());
EXPECT
(
not
p
.
get_shape
().
standard
());
...
@@ -104,7 +104,7 @@ void single_transpose()
...
@@ -104,7 +104,7 @@ void single_transpose()
void
double_transpose_sin_pass
()
void
double_transpose_sin_pass
()
{
{
migraph
::
program
p
;
migraph
::
program
p
;
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
l
=
p
.
add_literal
(
get_2x2
());
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
auto
t1
=
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
l
);
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
t1
);
p
.
add_instruction
(
migraph
::
transpose
{{
1
,
0
}},
t1
);
EXPECT
(
p
.
get_shape
().
standard
());
EXPECT
(
p
.
get_shape
().
standard
());
...
...
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