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
f0a16e67
"...targets/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "76f7ae49f71eb0892c0d531a275c371e3ef61e56"
Commit
f0a16e67
authored
Apr 30, 2019
by
Paul
Browse files
Check if eval can run before computing
parent
17bc98d0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
8 deletions
+24
-8
src/include/migraphx/instruction.hpp
src/include/migraphx/instruction.hpp
+2
-0
src/instruction.cpp
src/instruction.cpp
+22
-8
No files found.
src/include/migraphx/instruction.hpp
View file @
f0a16e67
...
...
@@ -72,6 +72,8 @@ struct instruction
static
void
replace
(
instruction_ref
ins
,
operation
o
,
const
shape
&
r
,
std
::
vector
<
instruction_ref
>
args
);
bool
can_eval
()
const
;
argument
eval
()
const
;
void
finalize
(
context
&
ctx
);
...
...
src/instruction.cpp
View file @
f0a16e67
...
...
@@ -162,22 +162,36 @@ void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
old
->
remove_output
(
*
this
);
}
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
()
const
{
if
(
op
.
name
()
==
"@literal"
)
{
return
this
->
get_literal
().
get_argument
();
}
if
(
is_context_free
(
op
))
if
(
is_context_free
(
op
)
and
this
->
can_eval
()
)
{
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
();
});
return
op
.
compute
(
result
,
args
);
}
return
{};
...
...
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