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
a518c097
Commit
a518c097
authored
Oct 06, 2023
by
Paul
Browse files
Use dq after qlinear to handle multiple uses
parent
65c37c3d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
1 deletion
+45
-1
src/simplify_qdq.cpp
src/simplify_qdq.cpp
+45
-1
No files found.
src/simplify_qdq.cpp
View file @
a518c097
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
namespace
migraphx
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
{
std
::
unordered_set
<
std
::
string
>
get_quantizable_op_names
()
std
::
unordered_set
<
std
::
string
>
get_quantizable_op_names
()
{
{
static
std
::
unordered_set
<
std
::
string
>
s
=
{
"convolution"
,
"dot"
};
static
std
::
unordered_set
<
std
::
string
>
s
=
{
"convolution"
,
"dot"
};
...
@@ -146,6 +146,48 @@ bool compare_literals(instruction_ref ins1, instruction_ref ins2)
...
@@ -146,6 +146,48 @@ bool compare_literals(instruction_ref ins1, instruction_ref ins2)
return
(
x
==
y
)
or
diff_shapes_equal_vals
;
return
(
x
==
y
)
or
diff_shapes_equal_vals
;
}
}
template
<
class
Iterator
>
bool
precedes
(
Iterator
x
,
Iterator
y
,
Iterator
last
)
{
auto
r
=
range
(
std
::
next
(
x
),
last
);
return
any_of
(
iterator_for
(
r
),
[
&
](
auto
it
)
{
return
it
==
y
;
});
}
struct
match_qlinear_reused
{
auto
matcher
()
const
{
return
match
::
name
(
"quantizelinear"
)(
match
::
used_once
(),
match
::
arg
(
0
)(
match
::
none_of
(
match
::
used_once
()).
bind
(
"x"
)));
}
void
apply
(
module
&
m
,
const
match
::
matcher_result
&
r
)
const
{
auto
ins
=
r
.
result
;
auto
x_ins
=
r
.
instructions
[
"x"
];
assert
(
ins
!=
x_ins
);
auto
dq_inputs
=
ins
->
inputs
();
dq_inputs
[
0
]
=
ins
;
auto
outputs
=
x_ins
->
outputs
();
if
(
outputs
.
size
()
!=
2
)
return
;
for
(
auto
output
:
outputs
)
{
if
(
output
->
name
()
==
"quantizelinear"
)
continue
;
if
(
not
output
->
get_operator
().
attributes
().
contains
(
"pointwise"
))
continue
;
if
(
not
precedes
(
ins
,
output
,
m
.
end
()))
continue
;
auto
dq
=
m
.
insert_instruction
(
std
::
next
(
ins
),
make_op
(
"dequantizelinear"
),
dq_inputs
);
instruction
::
replace_argument
(
output
,
x_ins
,
dq
);
}
}
};
void
remove_qdq_pairs
(
module
&
m
)
void
remove_qdq_pairs
(
module
&
m
)
{
{
for
(
auto
ins
:
iterator_for
(
m
))
for
(
auto
ins
:
iterator_for
(
m
))
...
@@ -166,6 +208,7 @@ void remove_qdq_pairs(module& m)
...
@@ -166,6 +208,7 @@ void remove_qdq_pairs(module& m)
}
}
}
}
}
}
}
// namespace
void
simplify_qdq
::
apply
(
module
&
m
)
const
void
simplify_qdq
::
apply
(
module
&
m
)
const
{
{
...
@@ -173,6 +216,7 @@ void simplify_qdq::apply(module& m) const
...
@@ -173,6 +216,7 @@ void simplify_qdq::apply(module& m) const
migraphx
::
run_passes
(
m
,
{
migraphx
::
dead_code_elimination
{}});
migraphx
::
run_passes
(
m
,
{
migraphx
::
dead_code_elimination
{}});
remove_qdq_pairs
(
m
);
remove_qdq_pairs
(
m
);
migraphx
::
run_passes
(
m
,
{
migraphx
::
dead_code_elimination
{}});
migraphx
::
run_passes
(
m
,
{
migraphx
::
dead_code_elimination
{}});
match
::
find_matches
(
m
,
match_qlinear_reused
{});
}
}
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace MIGRAPHX_INLINE_NS
...
...
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