Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
4ba12b4f
Commit
4ba12b4f
authored
May 05, 2018
by
Paul
Browse files
Add insert instruction
parent
d3886685
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
include/rtg/program.hpp
include/rtg/program.hpp
+8
-0
src/program.cpp
src/program.cpp
+7
-4
No files found.
include/rtg/program.hpp
View file @
4ba12b4f
...
@@ -26,6 +26,14 @@ struct program
...
@@ -26,6 +26,14 @@ struct program
return
add_instruction
(
op
,
{
args
...});
return
add_instruction
(
op
,
{
args
...});
}
}
instruction_ref
add_instruction
(
operation
op
,
std
::
vector
<
instruction_ref
>
args
);
instruction_ref
add_instruction
(
operation
op
,
std
::
vector
<
instruction_ref
>
args
);
template
<
class
...
Ts
>
instruction_ref
insert_instruction
(
instruction_ref
ins
,
operation
op
,
Ts
...
args
)
{
return
insert_instruction
(
ins
,
op
,
{
args
...});
}
instruction_ref
insert_instruction
(
instruction_ref
ins
,
operation
op
,
std
::
vector
<
instruction_ref
>
args
);
template
<
class
...
Ts
>
template
<
class
...
Ts
>
instruction_ref
add_literal
(
Ts
&&
...
xs
)
instruction_ref
add_literal
(
Ts
&&
...
xs
)
{
{
...
...
src/program.cpp
View file @
4ba12b4f
...
@@ -19,17 +19,20 @@ program& program::operator=(program&&) noexcept = default;
...
@@ -19,17 +19,20 @@ program& program::operator=(program&&) noexcept = default;
program
::~
program
()
noexcept
=
default
;
program
::~
program
()
noexcept
=
default
;
instruction_ref
program
::
add_instruction
(
operation
op
,
std
::
vector
<
instruction_ref
>
args
)
instruction_ref
program
::
add_instruction
(
operation
op
,
std
::
vector
<
instruction_ref
>
args
)
{
return
insert_instruction
(
impl
->
instructions
.
end
(),
std
::
move
(
op
),
std
::
move
(
args
));
}
instruction_ref
program
::
insert_instruction
(
instruction_ref
ins
,
operation
op
,
std
::
vector
<
instruction_ref
>
args
)
{
{
assert
(
std
::
all_of
(
assert
(
std
::
all_of
(
args
.
begin
(),
args
.
end
(),
[
&
](
instruction_ref
x
)
{
return
has_instruction
(
x
);
})
&&
args
.
begin
(),
args
.
end
(),
[
&
](
instruction_ref
x
)
{
return
has_instruction
(
x
);
})
&&
"Argument is not an exisiting instruction"
);
"Argument is not an exisiting instruction"
);
std
::
vector
<
shape
>
shapes
(
args
.
size
());
std
::
vector
<
shape
>
shapes
(
args
.
size
());
std
::
transform
(
std
::
transform
(
args
.
begin
(),
args
.
end
(),
shapes
.
begin
(),
[](
instruction_ref
i
ns
)
{
return
i
ns
->
result
;
});
args
.
begin
(),
args
.
end
(),
shapes
.
begin
(),
[](
instruction_ref
i
)
{
return
i
->
result
;
});
shape
r
=
op
.
compute_shape
(
shapes
);
shape
r
=
op
.
compute_shape
(
shapes
);
impl
->
instructions
.
push_back
({
op
,
r
,
args
});
auto
result
=
impl
->
instructions
.
insert
(
ins
,
{
op
,
r
,
args
});
assert
(
impl
->
instructions
.
back
().
arguments
==
args
);
assert
(
result
->
arguments
==
args
);
auto
result
=
std
::
prev
(
impl
->
instructions
.
end
());
for
(
auto
&&
arg
:
args
)
for
(
auto
&&
arg
:
args
)
arg
->
output
.
push_back
(
result
);
arg
->
output
.
push_back
(
result
);
return
result
;
return
result
;
...
...
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