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
cba7ee62
Unverified
Commit
cba7ee62
authored
May 02, 2019
by
Paul Fultz II
Committed by
GitHub
May 02, 2019
Browse files
Merge branch 'develop' into refine_eliminate_contiguous
parents
2e04ea47
1af75182
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
23 deletions
+51
-23
src/include/migraphx/instruction.hpp
src/include/migraphx/instruction.hpp
+3
-1
src/instruction.cpp
src/instruction.cpp
+24
-8
src/propagate_constant.cpp
src/propagate_constant.cpp
+24
-14
No files found.
src/include/migraphx/instruction.hpp
View file @
cba7ee62
...
...
@@ -72,7 +72,9 @@ struct instruction
static
void
replace
(
instruction_ref
ins
,
operation
o
,
const
shape
&
r
,
std
::
vector
<
instruction_ref
>
args
);
argument
eval
()
const
;
bool
can_eval
()
const
;
argument
eval
(
bool
check_eval
=
true
)
const
;
void
finalize
(
context
&
ctx
);
...
...
src/instruction.cpp
View file @
cba7ee62
...
...
@@ -162,7 +162,24 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
old
->
remove_output
(
*
this
);
}
argument
instruction
::
eval
()
const
bool
instruction
::
can_eval
()
const
{
if
(
op
.
name
()
==
"@literal"
)
{
return
true
;
}
else
if
(
is_context_free
(
op
))
{
return
std
::
all_of
(
this
->
inputs
().
begin
(),
this
->
inputs
().
end
(),
[](
auto
arg
)
{
return
arg
->
can_eval
();
});
}
else
{
return
false
;
}
}
argument
instruction
::
eval
(
bool
check_eval
)
const
{
if
(
op
.
name
()
==
"@literal"
)
{
...
...
@@ -170,14 +187,13 @@ argument instruction::eval() const
}
if
(
is_context_free
(
op
))
{
if
(
check_eval
and
not
this
->
can_eval
())
return
{};
std
::
vector
<
argument
>
args
;
for
(
auto
&&
arg
:
this
->
inputs
())
{
argument
a
=
arg
->
eval
();
if
(
a
.
empty
())
return
{};
args
.
push_back
(
a
);
}
std
::
transform
(
this
->
inputs
().
begin
(),
this
->
inputs
().
end
(),
std
::
back_inserter
(
args
),
[](
auto
arg
)
{
return
arg
->
eval
(
false
);
});
return
op
.
compute
(
result
,
args
);
}
return
{};
...
...
src/propagate_constant.cpp
View file @
cba7ee62
...
...
@@ -22,22 +22,32 @@ bool skip_propogate(instruction_ref ins)
void
propagate_constant
::
apply
(
program
&
p
)
const
{
fix
([
&
](
auto
self
,
auto
ins
)
{
if
(
not
skip_propogate
(
ins
))
{
auto
r
=
ins
->
eval
();
if
(
not
r
.
empty
())
for
(
auto
i
:
iterator_for
(
p
))
{
if
(
i
->
name
()
!=
"@literal"
)
continue
;
if
(
i
->
outputs
().
empty
())
continue
;
fix
([
&
](
auto
self
,
auto
ins
)
{
std
::
unordered_set
<
instruction_ref
>
children
(
ins
->
outputs
().
begin
(),
ins
->
outputs
().
end
());
for
(
auto
child
:
children
)
{
assert
(
r
.
get_shape
()
==
ins
->
get_shape
());
auto
l
=
p
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
p
.
replace_instruction
(
ins
,
l
);
return
;
if
(
skip_propogate
(
child
))
{
self
(
child
);
continue
;
}
auto
r
=
child
->
eval
();
if
(
not
r
.
empty
())
{
assert
(
r
.
get_shape
()
==
child
->
get_shape
());
auto
l
=
p
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
self
(
p
.
replace_instruction
(
child
,
l
));
}
}
}
std
::
unordered_set
<
instruction_ref
>
children
(
ins
->
inputs
().
begin
(),
ins
->
inputs
().
end
());
for
(
auto
child
:
children
)
self
(
child
);
})(
std
::
prev
(
p
.
end
()));
})(
i
);
}
}
}
// namespace MIGRAPHX_INLINE_NS
...
...
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