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
b7f31df5
Commit
b7f31df5
authored
May 24, 2022
by
Paul
Browse files
Cleanup debug output
parent
9dcbd52b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
15 deletions
+37
-15
src/targets/gpu/mlir.cpp
src/targets/gpu/mlir.cpp
+11
-4
test/gpu/mlir.cpp
test/gpu/mlir.cpp
+26
-11
No files found.
src/targets/gpu/mlir.cpp
View file @
b7f31df5
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include <mlir-c/Registration.h>
#include <mlir-c/Registration.h>
#endif
#endif
#include <migraphx/env.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/module.hpp>
#include <migraphx/module.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/instruction.hpp>
...
@@ -27,6 +28,8 @@ namespace migraphx {
...
@@ -27,6 +28,8 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
namespace
gpu
{
MIGRAPHX_DECLARE_ENV_VAR
(
MIGRAPHX_TRACE_MLIR
);
#ifdef MIGRAPHX_MLIR
#ifdef MIGRAPHX_MLIR
template
<
class
T
,
class
F
,
F
f
>
// NOLINT
template
<
class
T
,
class
F
,
F
f
>
// NOLINT
struct
mlir_handle
struct
mlir_handle
...
@@ -484,9 +487,10 @@ struct mlir_program
...
@@ -484,9 +487,10 @@ struct mlir_program
std
::
string
tname
=
get_device_name
();
std
::
string
tname
=
get_device_name
();
// HACK: Since MLIR can't handle the full target name
// HACK: Since MLIR can't handle the full target name
auto
hacked_tname
=
tname
.
substr
(
0
,
tname
.
find
(
":"
));
auto
hacked_tname
=
tname
.
substr
(
0
,
tname
.
find
(
":"
));
auto
hacked_features
=
tname
.
substr
(
tname
.
find
(
":"
));
if
(
tname
.
size
()
!=
hacked_tname
.
size
())
std
::
cout
<<
"*************** WARNING: MLIR may not compile the correct target features for: "
<<
tname
<<
std
::
endl
;
mlirMIGraphXAddBackendPipeline
(
mlirMIGraphXAddBackendPipeline
(
pm
.
get
(),
hacked_tname
.
c_str
(),
"amdgcn-amd-amdhsa"
,
hacked_features
.
c_str
()
);
pm
.
get
(),
hacked_tname
.
c_str
(),
"amdgcn-amd-amdhsa"
,
""
);
mlirPassManagerRun
(
pm
.
get
(),
mmodule
.
get
());
mlirPassManagerRun
(
pm
.
get
(),
mmodule
.
get
());
code_object_op
op
;
code_object_op
op
;
...
@@ -532,11 +536,14 @@ std::string dump_mlir(const module& m)
...
@@ -532,11 +536,14 @@ std::string dump_mlir(const module& m)
code_object_op
compile_mlir
(
const
module
&
m
)
code_object_op
compile_mlir
(
const
module
&
m
)
{
{
std
::
cout
<<
m
<<
std
::
endl
;
const
bool
trace
=
enabled
(
MIGRAPHX_TRACE_MLIR
{});
if
(
trace
)
std
::
cout
<<
m
<<
std
::
endl
;
mlir_program
mp
;
mlir_program
mp
;
mp
.
parse
(
m
);
mp
.
parse
(
m
);
auto
mod_op
=
mlirModuleGetOperation
(
mp
.
mmodule
.
get
());
auto
mod_op
=
mlirModuleGetOperation
(
mp
.
mmodule
.
get
());
std
::
cout
<<
mlir_print
(
&
mlirOperationPrint
,
mod_op
)
<<
std
::
endl
;
if
(
trace
)
std
::
cout
<<
mlir_print
(
&
mlirOperationPrint
,
mod_op
)
<<
std
::
endl
;
return
mp
.
compile
();
return
mp
.
compile
();
}
}
...
...
test/gpu/mlir.cpp
View file @
b7f31df5
#include <migraphx/gpu/mlir.hpp>
#include <migraphx/gpu/mlir.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/write_literals.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/module.hpp>
#include <migraphx/module.hpp>
#include <migraphx/program.hpp>
#include <migraphx/program.hpp>
...
@@ -8,12 +10,26 @@
...
@@ -8,12 +10,26 @@
#include <migraphx/stringutils.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/verify_args.hpp>
#include <migraphx/verify_args.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/functional.hpp>
#include <test.hpp>
#include <test.hpp>
using
migraphx
::
trim
;
using
migraphx
::
trim
;
// m test_gpu_mlir && ./bin/test_gpu_mlir
// m test_gpu_mlir && ./bin/test_gpu_mlir
struct
mlir_gpu_target
:
migraphx
::
gpu
::
target
{
std
::
string
name
()
const
{
return
"mlir"
;
}
std
::
vector
<
migraphx
::
pass
>
get_passes
(
migraphx
::
context
&
gctx
,
const
migraphx
::
compile_options
&
)
const
{
auto
&
ctx
=
migraphx
::
any_cast
<
migraphx
::
gpu
::
context
>
(
gctx
);
return
{
migraphx
::
gpu
::
write_literals
{
&
ctx
}
};
}
};
std
::
string
encode
(
std
::
string
s
)
std
::
string
encode
(
std
::
string
s
)
{
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
...
@@ -44,9 +60,10 @@ migraphx::program create_program_from_mlir(const migraphx::module& mmlir)
...
@@ -44,9 +60,10 @@ migraphx::program create_program_from_mlir(const migraphx::module& mmlir)
std
::
transform
(
names
.
begin
(),
names
.
end
(),
std
::
back_inserter
(
inputs
),
[
&
](
const
auto
&
name
)
{
std
::
transform
(
names
.
begin
(),
names
.
end
(),
std
::
back_inserter
(
inputs
),
[
&
](
const
auto
&
name
)
{
return
mm
->
add_parameter
(
name
,
mmlir
.
get_parameter_shape
(
name
));
return
mm
->
add_parameter
(
name
,
mmlir
.
get_parameter_shape
(
name
));
});
});
std
::
sort
(
inputs
.
begin
(),
inputs
.
end
(),
migraphx
::
by
(
std
::
less
<>
{},
[](
auto
ins
)
{
return
to_string
(
ins
->
get_operator
());
}));
inputs
.
push_back
(
mm
->
add_parameter
(
"output"
,
mmlir
.
get_output_shapes
().
front
()));
inputs
.
push_back
(
mm
->
add_parameter
(
"output"
,
mmlir
.
get_output_shapes
().
front
()));
migraphx
::
gpu
::
insert_mlir
(
*
mm
,
mm
->
end
(),
mmlir
,
inputs
);
migraphx
::
gpu
::
insert_mlir
(
*
mm
,
mm
->
end
(),
mmlir
,
inputs
);
std
::
cout
<<
p
<<
std
::
endl
;
return
p
;
return
p
;
}
}
...
@@ -64,7 +81,7 @@ migraphx::parameter_map generate_params(const migraphx::program& p)
...
@@ -64,7 +81,7 @@ migraphx::parameter_map generate_params(const migraphx::program& p)
migraphx
::
argument
run_gpu
(
migraphx
::
program
p
,
const
migraphx
::
parameter_map
&
inputs
)
migraphx
::
argument
run_gpu
(
migraphx
::
program
p
,
const
migraphx
::
parameter_map
&
inputs
)
{
{
m
igraphx
::
gpu
::
target
t
;
m
lir_
gpu
_
target
t
;
p
.
compile
(
t
);
p
.
compile
(
t
);
migraphx
::
parameter_map
m
;
migraphx
::
parameter_map
m
;
for
(
auto
&&
input
:
inputs
)
for
(
auto
&&
input
:
inputs
)
...
@@ -101,9 +118,9 @@ bool verify_mlir(const migraphx::module& mmlir)
...
@@ -101,9 +118,9 @@ bool verify_mlir(const migraphx::module& mmlir)
TEST_CASE
(
conv
)
TEST_CASE
(
conv
)
{
{
const
std
::
string
mlir_output
=
R"__migraphx__(
const
std
::
string
mlir_output
=
R"__migraphx__(
module
{
module {
func @main(%arg0: tensor<
1
x8x
4x4
xf32>, %arg1: tensor<
2
x8x
3x3
xf32>) -> tensor<1x2x2x2xf32> {
func @main(%arg0: tensor<
2
x8x
3x3
xf32>, %arg1: tensor<
1
x8x
4x4
xf32>) -> tensor<1x2x2x2xf32>
attributes {kernel = "mixr"}
{
%0 = migraphx.convolution(%arg
0
, %arg
1
) {dilation = [1, 1], group = 1 : i64, padding = [0, 0, 0, 0], padding_mode = 0 : i64, stride = [1, 1]} : (tensor<1x8x4x4xf32>, tensor<2x8x3x3xf32>) -> tensor<1x2x2x2xf32>
%0 = migraphx.convolution(%arg
1
, %arg
0
) {dilation = [1, 1], group = 1 : i64, padding = [0, 0, 0, 0], padding_mode = 0 : i64, stride = [1, 1]} : (tensor<1x8x4x4xf32>, tensor<2x8x3x3xf32>) -> tensor<1x2x2x2xf32>
return %0 : tensor<1x2x2x2xf32>
return %0 : tensor<1x2x2x2xf32>
}
}
}
}
...
@@ -117,7 +134,6 @@ module {
...
@@ -117,7 +134,6 @@ module {
// Skip test if MLIR is not enabled
// Skip test if MLIR is not enabled
if
(
s
.
empty
())
if
(
s
.
empty
())
return
;
return
;
std
::
cout
<<
s
<<
std
::
endl
;
CHECK
(
encode
(
s
)
==
encode
(
mlir_output
));
CHECK
(
encode
(
s
)
==
encode
(
mlir_output
));
EXPECT
(
verify_mlir
(
m
));
EXPECT
(
verify_mlir
(
m
));
}
}
...
@@ -125,10 +141,10 @@ module {
...
@@ -125,10 +141,10 @@ module {
TEST_CASE
(
conv_add_relu
)
TEST_CASE
(
conv_add_relu
)
{
{
const
std
::
string
mlir_output
=
R"__migraphx__(
const
std
::
string
mlir_output
=
R"__migraphx__(
module
{
module {
func @main(%arg0: tensor<1x
8x4x4
xf32>, %arg1: tensor<2x8x3x3xf32>, %arg2: tensor<1x
2x2x2
xf32>) -> tensor<1x2x2x2xf32> {
func @main(%arg0: tensor<1x
2x2x2
xf32>, %arg1: tensor<2x8x3x3xf32>, %arg2: tensor<1x
8x4x4
xf32>) -> tensor<1x2x2x2xf32>
attributes {kernel = "mixr"}
{
%0 = migraphx.convolution(%arg
0
, %arg1) {dilation = [1, 1], group = 1 : i64, padding = [0, 0, 0, 0], padding_mode = 0 : i64, stride = [1, 1]} : (tensor<1x8x4x4xf32>, tensor<2x8x3x3xf32>) -> tensor<1x2x2x2xf32>
%0 = migraphx.convolution(%arg
2
, %arg1) {dilation = [1, 1], group = 1 : i64, padding = [0, 0, 0, 0], padding_mode = 0 : i64, stride = [1, 1]} : (tensor<1x8x4x4xf32>, tensor<2x8x3x3xf32>) -> tensor<1x2x2x2xf32>
%1 = migraphx.add(%0, %arg
2
) : (tensor<1x2x2x2xf32>, tensor<1x2x2x2xf32>) -> tensor<1x2x2x2xf32>
%1 = migraphx.add(%0, %arg
0
) : (tensor<1x2x2x2xf32>, tensor<1x2x2x2xf32>) -> tensor<1x2x2x2xf32>
%2 = migraphx.relu(%1) : (tensor<1x2x2x2xf32>) -> tensor<1x2x2x2xf32>
%2 = migraphx.relu(%1) : (tensor<1x2x2x2xf32>) -> tensor<1x2x2x2xf32>
return %2 : tensor<1x2x2x2xf32>
return %2 : tensor<1x2x2x2xf32>
}
}
...
@@ -146,7 +162,6 @@ module {
...
@@ -146,7 +162,6 @@ module {
// Skip test if MLIR is not enabled
// Skip test if MLIR is not enabled
if
(
s
.
empty
())
if
(
s
.
empty
())
return
;
return
;
std
::
cout
<<
s
<<
std
::
endl
;
CHECK
(
encode
(
s
)
==
encode
(
mlir_output
));
CHECK
(
encode
(
s
)
==
encode
(
mlir_output
));
EXPECT
(
verify_mlir
(
m
));
EXPECT
(
verify_mlir
(
m
));
}
}
...
...
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