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
bd86c201
"git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "95431eb769013ccb9e6553b8edd80705afb8971b"
Commit
bd86c201
authored
Apr 24, 2019
by
Shucai Xiao
Browse files
clang format
parent
bbbf98a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
22 deletions
+24
-22
src/program.cpp
src/program.cpp
+20
-18
test/program_test.cpp
test/program_test.cpp
+4
-4
No files found.
src/program.cpp
View file @
bd86c201
...
...
@@ -90,15 +90,12 @@ program& program::operator=(program&&) noexcept = default;
program
::~
program
()
noexcept
=
default
;
// copy constructor
program
::
program
(
const
program
&
p
)
noexcept
{
copy
(
p
);
}
program
::
program
(
const
program
&
p
)
noexcept
{
copy
(
p
);
}
// copy assignment operator
program
&
program
::
operator
=
(
const
program
&
p
)
noexcept
{
if
(
this
!=
&
p
)
if
(
this
!=
&
p
)
{
copy
(
p
);
}
...
...
@@ -109,44 +106,49 @@ program& program::operator=(const program& p) noexcept
void
program
::
copy
(
const
program
&
p
)
{
// clean the current program
if
(
!
impl
)
if
(
!
impl
)
{
impl
=
std
::
make_unique
<
program_impl
>
();
}
else
if
(
!
impl
->
instructions
.
empty
())
else
if
(
!
impl
->
instructions
.
empty
())
{
remove_instructions
(
begin
(),
end
());
}
impl
->
ctx
=
p
.
impl
->
ctx
;
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
ins_map
;
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
p
))
{
instruction_ref
copy_ins
{};
if
(
ins
->
name
()
==
"@literal"
)
if
(
ins
->
name
()
==
"@literal"
)
{
auto
l
=
ins
->
get_literal
();
auto
l
=
ins
->
get_literal
();
copy_ins
=
impl
->
instructions
.
insert
(
impl
->
instructions
.
end
(),
instruction
{
l
});
}
else
if
(
ins
->
name
()
==
"@param"
)
else
if
(
ins
->
name
()
==
"@param"
)
{
auto
&&
name
=
any_cast
<
builtin
::
param
>
(
ins
->
get_operator
()).
parameter
;
auto
s
=
ins
->
get_shape
();
copy_ins
=
impl
->
instructions
.
insert
(
impl
->
instructions
.
end
(),
{
builtin
::
param
{
std
::
move
(
name
)},
std
::
move
(
s
),
{}});
auto
&&
name
=
any_cast
<
builtin
::
param
>
(
ins
->
get_operator
()).
parameter
;
auto
s
=
ins
->
get_shape
();
copy_ins
=
impl
->
instructions
.
insert
(
impl
->
instructions
.
end
(),
{
builtin
::
param
{
std
::
move
(
name
)},
std
::
move
(
s
),
{}});
}
else
if
(
ins
->
name
()
==
"@outline"
)
else
if
(
ins
->
name
()
==
"@outline"
)
{
auto
s
=
ins
->
get_shape
();
copy_ins
=
impl
->
instructions
.
insert
(
impl
->
instructions
.
end
(),
{
builtin
::
outline
{
s
},
s
,
{}});
copy_ins
=
impl
->
instructions
.
insert
(
impl
->
instructions
.
end
(),
{
builtin
::
outline
{
s
},
s
,
{}});
}
else
{
// retrieve its mapped input
auto
inputs
=
ins
->
inputs
();
// ensure all inputs have its corresponding copy instructions
assert
(
std
::
all_of
(
inputs
.
begin
(),
inputs
.
end
(),
[
&
](
auto
i
)
{
return
ins_map
.
count
(
i
)
>
0
;
}));
assert
(
std
::
all_of
(
inputs
.
begin
(),
inputs
.
end
(),
[
&
](
auto
i
)
{
return
ins_map
.
count
(
i
)
>
0
;
}));
std
::
vector
<
instruction_ref
>
copy_inputs
(
inputs
.
size
());
std
::
transform
(
inputs
.
begin
(),
inputs
.
end
(),
copy_inputs
.
begin
(),
[
&
]
(
auto
i
)
{
return
ins_map
[
i
];
});
std
::
transform
(
inputs
.
begin
(),
inputs
.
end
(),
copy_inputs
.
begin
(),
[
&
](
auto
i
)
{
return
ins_map
[
i
];
});
copy_ins
=
add_instruction
(
ins
->
get_operator
(),
copy_inputs
);
}
...
...
test/program_test.cpp
View file @
bd86c201
...
...
@@ -36,9 +36,9 @@ TEST_CASE(program_copy)
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
5
}};
std
::
vector
<
float
>
data
(
3
*
4
*
5
);
std
::
iota
(
data
.
begin
(),
data
.
end
(),
1.0
f
);
auto
l2
=
p
.
add_literal
(
migraphx
::
literal
(
s
,
data
));
auto
p1
=
p
.
add_parameter
(
"x"
,
s
);
auto
po
=
p
.
add_outline
(
s
);
auto
l2
=
p
.
add_literal
(
migraphx
::
literal
(
s
,
data
));
auto
p1
=
p
.
add_parameter
(
"x"
,
s
);
auto
po
=
p
.
add_outline
(
s
);
auto
sum
=
p
.
add_instruction
(
migraphx
::
op
::
add
{},
l2
,
p1
);
p
.
add_instruction
(
migraphx
::
op
::
mul
{},
sum
,
po
);
...
...
@@ -60,7 +60,7 @@ TEST_CASE(program_copy)
{
auto
p1
=
create_program_1
();
auto
p2
=
create_program
();
p2
=
p1
;
p2
=
p1
;
EXPECT
(
p1
==
p2
);
}
...
...
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