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
9130aee8
Commit
9130aee8
authored
Dec 06, 2023
by
Umang Yadav
Browse files
add nested converts Pass
parent
4315a991
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
133 additions
and
39 deletions
+133
-39
src/CMakeLists.txt
src/CMakeLists.txt
+1
-0
src/eliminate_data_type.cpp
src/eliminate_data_type.cpp
+0
-16
src/eliminate_nested_converts.cpp
src/eliminate_nested_converts.cpp
+75
-0
src/include/migraphx/eliminate_nested_converts.hpp
src/include/migraphx/eliminate_nested_converts.hpp
+48
-0
src/optimize_module.cpp
src/optimize_module.cpp
+2
-0
src/simplify_reshapes.cpp
src/simplify_reshapes.cpp
+0
-23
src/targets/cpu/target.cpp
src/targets/cpu/target.cpp
+2
-0
src/targets/gpu/target.cpp
src/targets/gpu/target.cpp
+3
-0
src/targets/ref/target.cpp
src/targets/ref/target.cpp
+2
-0
No files found.
src/CMakeLists.txt
View file @
9130aee8
...
@@ -50,6 +50,7 @@ add_library(migraphx
...
@@ -50,6 +50,7 @@ add_library(migraphx
eliminate_contiguous.cpp
eliminate_contiguous.cpp
eliminate_data_type.cpp
eliminate_data_type.cpp
eliminate_identity.cpp
eliminate_identity.cpp
eliminate_nested_converts.cpp
eliminate_pad.cpp
eliminate_pad.cpp
env.cpp
env.cpp
file_buffer.cpp
file_buffer.cpp
...
...
src/eliminate_data_type.cpp
View file @
9130aee8
...
@@ -120,22 +120,6 @@ void eliminate_data_type::apply(module& m) const
...
@@ -120,22 +120,6 @@ void eliminate_data_type::apply(module& m) const
if
(
contains
(
unsupported_ops
,
"all"
)
or
contains
(
unsupported_ops
,
ins
->
name
()))
if
(
contains
(
unsupported_ops
,
"all"
)
or
contains
(
unsupported_ops
,
ins
->
name
()))
insert_convert_to_supported_type
(
m
,
ins
,
target_type
,
unsupported_types
);
insert_convert_to_supported_type
(
m
,
ins
,
target_type
,
unsupported_types
);
}
}
// remove nested converts
for
(
auto
ins
:
iterator_for
(
m
))
{
if
(
ins
->
name
()
==
"convert"
)
{
auto
convert_input
=
ins
->
inputs
().
front
();
while
(
convert_input
->
name
()
==
"convert"
)
{
convert_input
=
convert_input
->
inputs
().
front
();
}
if
(
convert_input
->
get_shape
()
==
ins
->
get_shape
())
{
m
.
replace_instruction
(
ins
,
convert_input
);
}
}
}
}
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/eliminate_nested_converts.cpp
0 → 100644
View file @
9130aee8
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <iterator>
#include <migraphx/eliminate_nested_converts.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/op/as_shape.hpp>
#include <migraphx/op/transpose.hpp>
#include <migraphx/op/concat.hpp>
#include <migraphx/op/slice.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/matcher.hpp>
#include <migraphx/permutation.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <unordered_set>
#include <migraphx/make_op.hpp>
#include <migraphx/tune_axis.hpp>
#include <map>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
struct
find_nested_convert
{
auto
matcher
()
const
{
return
match
::
name
(
"convert"
)(
match
::
arg
(
0
)(
match
::
name
(
"convert"
)));
}
void
apply
(
module
&
m
,
const
match
::
matcher_result
&
mr
)
const
{
auto
ins
=
mr
.
result
;
auto
x
=
ins
->
inputs
().
front
();
auto
input
=
x
->
inputs
().
front
();
while
(
input
->
name
()
==
"convert"
)
{
input
=
input
->
inputs
().
front
();
}
if
(
ins
->
get_shape
()
!=
input
->
get_shape
())
return
;
m
.
replace_instruction
(
ins
,
input
);
}
};
void
eliminate_nested_converts
::
apply
(
module
&
m
)
const
{
match
::
find_matches
(
m
,
find_nested_convert
{});
dead_code_elimination
{}.
apply
(
m
);
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
src/include/migraphx/eliminate_nested_converts.hpp
0 → 100644
View file @
9130aee8
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MIGRAPHX_GUARD_RTGLIB_ELIMINATE_NESTED_CONVERTS_HPP
#define MIGRAPHX_GUARD_RTGLIB_ELIMINATE_NESTED_CONVERTS_HPP
#include <string>
#include <migraphx/instruction_ref.hpp>
#include <migraphx/config.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
struct
module
;
/**
* Eliminate nested converts
*/
struct
MIGRAPHX_EXPORT
eliminate_nested_converts
{
std
::
string
name
()
const
{
return
"eliminate_nested_converts"
;
}
void
apply
(
module
&
m
)
const
;
};
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif
src/optimize_module.cpp
View file @
9130aee8
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/simplify_algebra.hpp>
#include <migraphx/simplify_algebra.hpp>
#include <migraphx/eliminate_common_subexpression.hpp>
#include <migraphx/eliminate_common_subexpression.hpp>
#include <migraphx/eliminate_nested_converts.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/propagate_constant.hpp>
#include <migraphx/propagate_constant.hpp>
...
@@ -42,6 +43,7 @@ void optimize_module::apply(module_pass_manager& mpm) const
...
@@ -42,6 +43,7 @@ void optimize_module::apply(module_pass_manager& mpm) const
mpm
.
run_pass
(
simplify_reshapes
{});
mpm
.
run_pass
(
simplify_reshapes
{});
mpm
.
run_pass
(
simplify_algebra
{});
mpm
.
run_pass
(
simplify_algebra
{});
}
}
mpm
.
run_pass
(
eliminate_nested_converts
{});
mpm
.
run_pass
(
eliminate_common_subexpression
{});
mpm
.
run_pass
(
eliminate_common_subexpression
{});
mpm
.
run_pass
(
dead_code_elimination
{});
mpm
.
run_pass
(
dead_code_elimination
{});
mpm
.
run_pass
(
propagate_constant
{});
mpm
.
run_pass
(
propagate_constant
{});
...
...
src/simplify_reshapes.cpp
View file @
9130aee8
...
@@ -173,28 +173,6 @@ struct find_transpose
...
@@ -173,28 +173,6 @@ struct find_transpose
}
}
};
};
struct
find_nested_convert
{
auto
matcher
()
const
{
return
match
::
name
(
"convert"
)(
match
::
arg
(
0
)(
match
::
name
(
"convert"
)));
}
void
apply
(
module
&
m
,
const
match
::
matcher_result
&
mr
)
const
{
auto
ins
=
mr
.
result
;
auto
x
=
ins
->
inputs
().
front
();
auto
input
=
x
->
inputs
().
front
();
while
(
input
->
name
()
==
"convert"
)
{
input
=
input
->
inputs
().
front
();
}
if
(
ins
->
get_shape
()
!=
input
->
get_shape
())
return
;
m
.
replace_instruction
(
ins
,
input
);
}
};
struct
find_nested_slice
struct
find_nested_slice
{
{
auto
matcher
()
const
{
return
match
::
name
(
"slice"
)(
match
::
arg
(
0
)(
match
::
name
(
"slice"
)));
}
auto
matcher
()
const
{
return
match
::
name
(
"slice"
)(
match
::
arg
(
0
)(
match
::
name
(
"slice"
)));
}
...
@@ -841,7 +819,6 @@ void simplify_reshapes::apply(module& m) const
...
@@ -841,7 +819,6 @@ void simplify_reshapes::apply(module& m) const
find_transpose
{},
find_transpose
{},
find_concat_transpose
{},
find_concat_transpose
{},
find_concat_multibroadcasts
{},
find_concat_multibroadcasts
{},
find_nested_convert
{},
find_nested_slice
{},
find_nested_slice
{},
find_nested_concat
{},
find_nested_concat
{},
find_transpose_slice
{},
find_transpose_slice
{},
...
...
src/targets/cpu/target.cpp
View file @
9130aee8
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
* THE SOFTWARE.
* THE SOFTWARE.
*/
*/
#include "migraphx/eliminate_nested_converts.hpp"
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/adjust_allocation.hpp>
#include <migraphx/adjust_allocation.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
...
@@ -72,6 +73,7 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
...
@@ -72,6 +73,7 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
dead_code_elimination
{},
dead_code_elimination
{},
eliminate_data_type
{
unsupported_types
,
shape
::
type_t
::
float_type
},
eliminate_data_type
{
unsupported_types
,
shape
::
type_t
::
float_type
},
dead_code_elimination
{},
dead_code_elimination
{},
eliminate_nested_converts
{},
simplify_reshapes
{},
simplify_reshapes
{},
eliminate_identity
{},
eliminate_identity
{},
eliminate_pad
{},
eliminate_pad
{},
...
...
src/targets/gpu/target.cpp
View file @
9130aee8
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include <migraphx/eliminate_concat.hpp>
#include <migraphx/eliminate_concat.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/eliminate_data_type.hpp>
#include <migraphx/eliminate_data_type.hpp>
#include <migraphx/eliminate_nested_converts.hpp>
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/eliminate_pad.hpp>
#include <migraphx/eliminate_pad.hpp>
#include <migraphx/fuse_pointwise.hpp>
#include <migraphx/fuse_pointwise.hpp>
...
@@ -124,6 +125,8 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
...
@@ -124,6 +125,8 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
enable_pass
(
not
mlir_enabled
(),
rewrite_quantization
{}),
enable_pass
(
not
mlir_enabled
(),
rewrite_quantization
{}),
dead_code_elimination
{},
dead_code_elimination
{},
eliminate_data_type
{
unsupported_types
,
shape
::
type_t
::
float_type
},
eliminate_data_type
{
unsupported_types
,
shape
::
type_t
::
float_type
},
dead_code_elimination
{},
eliminate_nested_converts
{},
simplify_reshapes
{},
simplify_reshapes
{},
eliminate_identity
{},
eliminate_identity
{},
eliminate_pad
{},
eliminate_pad
{},
...
...
src/targets/ref/target.cpp
View file @
9130aee8
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include <migraphx/pass.hpp>
#include <migraphx/pass.hpp>
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/rewrite_rnn.hpp>
#include <migraphx/rewrite_rnn.hpp>
#include <migraphx/eliminate_nested_converts.hpp>
#include <migraphx/eliminate_pad.hpp>
#include <migraphx/eliminate_pad.hpp>
#include <migraphx/insert_pad.hpp>
#include <migraphx/insert_pad.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/dead_code_elimination.hpp>
...
@@ -49,6 +50,7 @@ std::vector<pass> target::get_passes(migraphx::context&, const compile_options&)
...
@@ -49,6 +50,7 @@ std::vector<pass> target::get_passes(migraphx::context&, const compile_options&)
dead_code_elimination
{},
dead_code_elimination
{},
eliminate_data_type
{{
migraphx
::
shape
::
fp8e4m3fnuz_type
},
shape
::
float_type
,
{
"quant_dot"
}},
eliminate_data_type
{{
migraphx
::
shape
::
fp8e4m3fnuz_type
},
shape
::
float_type
,
{
"quant_dot"
}},
dead_code_elimination
{},
dead_code_elimination
{},
eliminate_nested_converts
{},
insert_pad
{},
insert_pad
{},
dead_code_elimination
{},
dead_code_elimination
{},
rewrite_rnn
{},
rewrite_rnn
{},
...
...
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