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
c83ee9f8
Commit
c83ee9f8
authored
Dec 10, 2021
by
Paul
Browse files
Add mlir verification
parent
e2967e04
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
3 deletions
+71
-3
src/include/migraphx/module.hpp
src/include/migraphx/module.hpp
+1
-1
src/include/migraphx/module_ref.hpp
src/include/migraphx/module_ref.hpp
+1
-0
src/module.cpp
src/module.cpp
+1
-1
test/gpu/mlir.cpp
test/gpu/mlir.cpp
+68
-1
No files found.
src/include/migraphx/module.hpp
View file @
c83ee9f8
...
...
@@ -98,7 +98,7 @@ struct module
std
::
vector
<
instruction_ref
>
insert_module_instructions
(
instruction_ref
ins
,
module_ref
m
,
const_
module_ref
m
,
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
map_ins
=
{});
template
<
class
...
Ts
>
...
...
src/include/migraphx/module_ref.hpp
View file @
c83ee9f8
...
...
@@ -10,6 +10,7 @@ inline namespace MIGRAPHX_INLINE_NS {
struct
module
;
using
module_ref
=
module
*
;
using
const_module_ref
=
const
module
*
;
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
...
...
src/module.cpp
View file @
c83ee9f8
...
...
@@ -310,7 +310,7 @@ instruction_ref module::move_instructions(instruction_ref src, instruction_ref d
}
std
::
vector
<
instruction_ref
>
module
::
insert_module_instructions
(
instruction_ref
ins
,
module_ref
m
,
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
map_ins
)
instruction_ref
ins
,
const_
module_ref
m
,
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
map_ins
)
{
std
::
vector
<
instruction_ref
>
mod_outputs
;
for
(
auto
sins
:
iterator_for
(
*
m
))
...
...
test/gpu/mlir.cpp
View file @
c83ee9f8
#include <migraphx/gpu/mlir.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/module.hpp>
#include <migraphx/program.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/verify_args.hpp>
#include <test.hpp>
using
migraphx
::
trim
;
...
...
@@ -28,6 +33,67 @@ std::string encode(std::string s)
return
migraphx
::
trim
(
ss
.
str
());
}
migraphx
::
program
create_program_from_mlir
(
const
migraphx
::
module
&
mmlir
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
names
=
mmlir
.
get_parameter_names
();
std
::
vector
<
migraphx
::
instruction_ref
>
inputs
;
std
::
transform
(
names
.
begin
(),
names
.
end
(),
std
::
back_inserter
(
inputs
),
[
&
](
const
auto
&
name
)
{
return
mm
->
add_parameter
(
name
,
mmlir
.
get_parameter_shape
(
name
));
});
inputs
.
push_back
(
mm
->
add_parameter
(
"output"
,
mmlir
.
get_output_shapes
().
front
()));
migraphx
::
gpu
::
insert_mlir
(
*
mm
,
mm
->
end
(),
mmlir
,
inputs
);
return
p
;
}
migraphx
::
parameter_map
generate_params
(
const
migraphx
::
program
&
p
)
{
migraphx
::
parameter_map
m
;
std
::
size_t
i
=
0
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
{
m
[
x
.
first
]
=
migraphx
::
generate_argument
(
x
.
second
,
i
++
);
}
return
m
;
}
migraphx
::
argument
run_gpu
(
migraphx
::
program
p
,
const
migraphx
::
parameter_map
&
inputs
)
{
migraphx
::
gpu
::
target
t
;
p
.
compile
(
t
);
migraphx
::
parameter_map
m
;
for
(
auto
&&
input
:
inputs
)
{
m
[
input
.
first
]
=
t
.
copy_to
(
input
.
second
);
}
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
{
if
(
m
.
count
(
x
.
first
)
==
0
)
{
m
[
x
.
first
]
=
t
.
allocate
(
x
.
second
);
}
}
return
t
.
copy_from
(
p
.
eval
(
m
).
front
());
}
migraphx
::
argument
run_ref
(
migraphx
::
program
p
,
const
migraphx
::
parameter_map
&
inputs
)
{
p
.
compile
(
migraphx
::
ref
::
target
{});
return
p
.
eval
(
inputs
).
front
();
}
bool
verify_mlir
(
const
migraphx
::
module
&
mmlir
)
{
migraphx
::
program
ref
;
ref
.
get_main_module
()
->
insert_module_instructions
(
ref
.
get_main_module
()
->
end
(),
&
mmlir
);
auto
inputs
=
generate_params
(
ref
);
auto
mlir
=
create_program_from_mlir
(
mmlir
);
return
migraphx
::
verify_args
(
"mlir"
,
run_ref
(
ref
,
inputs
),
run_gpu
(
mlir
,
inputs
));
}
TEST_CASE
(
conv
)
{
const
std
::
string
mlir_output
=
R"__migraphx__(
...
...
@@ -49,7 +115,7 @@ module {
return
;
std
::
cout
<<
s
<<
std
::
endl
;
EXPECT
(
encode
(
s
)
==
encode
(
mlir_output
));
auto
op
=
migraphx
::
gpu
::
compile
_mlir
(
m
);
EXPECT
(
verify
_mlir
(
m
)
)
;
}
TEST_CASE
(
conv_add_relu
)
...
...
@@ -78,6 +144,7 @@ module {
return
;
std
::
cout
<<
s
<<
std
::
endl
;
EXPECT
(
encode
(
s
)
==
encode
(
mlir_output
));
EXPECT
(
verify_mlir
(
m
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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