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
b2051bbc
Commit
b2051bbc
authored
May 02, 2019
by
Paul
Browse files
Merge branch 'develop' into hcc23
parents
52c90f8a
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 @
b2051bbc
...
@@ -72,7 +72,9 @@ struct instruction
...
@@ -72,7 +72,9 @@ struct instruction
static
void
static
void
replace
(
instruction_ref
ins
,
operation
o
,
const
shape
&
r
,
std
::
vector
<
instruction_ref
>
args
);
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
);
void
finalize
(
context
&
ctx
);
...
...
src/instruction.cpp
View file @
b2051bbc
...
@@ -162,7 +162,24 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
...
@@ -162,7 +162,24 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
old
->
remove_output
(
*
this
);
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"
)
if
(
op
.
name
()
==
"@literal"
)
{
{
...
@@ -170,14 +187,13 @@ argument instruction::eval() const
...
@@ -170,14 +187,13 @@ argument instruction::eval() const
}
}
if
(
is_context_free
(
op
))
if
(
is_context_free
(
op
))
{
{
if
(
check_eval
and
not
this
->
can_eval
())
return
{};
std
::
vector
<
argument
>
args
;
std
::
vector
<
argument
>
args
;
for
(
auto
&&
arg
:
this
->
inputs
())
std
::
transform
(
this
->
inputs
().
begin
(),
{
this
->
inputs
().
end
(),
argument
a
=
arg
->
eval
();
std
::
back_inserter
(
args
),
if
(
a
.
empty
())
[](
auto
arg
)
{
return
arg
->
eval
(
false
);
});
return
{};
args
.
push_back
(
a
);
}
return
op
.
compute
(
result
,
args
);
return
op
.
compute
(
result
,
args
);
}
}
return
{};
return
{};
...
...
src/propagate_constant.cpp
View file @
b2051bbc
...
@@ -22,22 +22,32 @@ bool skip_propogate(instruction_ref ins)
...
@@ -22,22 +22,32 @@ bool skip_propogate(instruction_ref ins)
void
propagate_constant
::
apply
(
program
&
p
)
const
void
propagate_constant
::
apply
(
program
&
p
)
const
{
{
fix
([
&
](
auto
self
,
auto
ins
)
{
for
(
auto
i
:
iterator_for
(
p
))
if
(
not
skip_propogate
(
ins
))
{
{
if
(
i
->
name
()
!=
"@literal"
)
auto
r
=
ins
->
eval
();
continue
;
if
(
not
r
.
empty
())
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
());
if
(
skip_propogate
(
child
))
auto
l
=
p
.
add_literal
(
r
.
get_shape
(),
r
.
data
());
{
p
.
replace_instruction
(
ins
,
l
);
self
(
child
);
return
;
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
));
}
}
}
}
})(
i
);
std
::
unordered_set
<
instruction_ref
>
children
(
ins
->
inputs
().
begin
(),
ins
->
inputs
().
end
());
}
for
(
auto
child
:
children
)
self
(
child
);
})(
std
::
prev
(
p
.
end
()));
}
}
}
// namespace MIGRAPHX_INLINE_NS
}
// 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