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
2a2f82c7
Commit
2a2f82c7
authored
Dec 13, 2023
by
Ahsan Saghir
Browse files
Address review: used contains to check fp8_types set
parent
15df0bc8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
11 deletions
+7
-11
src/autocast_fp8.cpp
src/autocast_fp8.cpp
+5
-9
src/include/migraphx/autocast_fp8.hpp
src/include/migraphx/autocast_fp8.hpp
+2
-2
No files found.
src/autocast_fp8.cpp
View file @
2a2f82c7
...
...
@@ -26,28 +26,24 @@
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/ranges.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
bool
autocast_fp8_pass
::
is_fp8_type
(
const
shape
::
type_t
&
s
)
const
{
return
fp8_types
.
find
(
s
)
!=
fp8_types
.
end
();
}
void
autocast_fp8_pass
::
apply
(
module
&
m
)
const
{
std
::
vector
<
instruction_ref
>
remove_parameters
;
for
(
auto
ins
:
iterator_for
(
m
))
{
const
auto
&
ins_name
=
ins
->
name
();
if
(
ins_name
==
"@param"
and
is_
fp8_type
(
ins
->
get_shape
().
type
()))
if
(
ins_name
==
"@param"
and
contains
(
fp8_type
s
,
ins
->
get_shape
().
type
()))
{
shape
::
type_t
fp8_type
=
ins
->
get_shape
().
type
();
migraphx
::
shape
new_shape
=
ins
->
get_shape
().
with_type
(
target_type
);
std
::
string
new_
param_name
=
std
::
string
param_name
=
ins
->
get_operator
().
to_value
()[
"parameter"
].
to
<
std
::
string
>
();
auto
new_param
=
m
.
add_parameter
(
new_
param_name
,
new_shape
);
auto
new_param
=
m
.
add_parameter
(
param_name
,
new_shape
);
auto
new_ins
=
m
.
insert_instruction
(
ins
,
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
to_value
(
fp8_type
)}}),
new_param
);
...
...
@@ -61,7 +57,7 @@ void autocast_fp8_pass::apply(module& m) const
std
::
vector
<
instruction_ref
>
new_inputs
;
for
(
const
auto
&
i
:
inputs
)
{
if
(
is_
fp8_type
(
i
->
get_shape
().
type
()))
if
(
contains
(
fp8_type
s
,
i
->
get_shape
().
type
()))
{
new_inputs
.
push_back
(
m
.
insert_instruction
(
ins
,
...
...
src/include/migraphx/autocast_fp8.hpp
View file @
2a2f82c7
...
...
@@ -33,14 +33,14 @@ struct program;
struct
module
;
/**
This will cast input paramater data types to fp8 and return data types to fp32.*/
This pass will convert model with fp8 input parameter to model with fp32
input parameter and internally add casts to fp8 for those converted params.*/
struct
MIGRAPHX_EXPORT
autocast_fp8_pass
{
std
::
set
<
shape
::
type_t
>
fp8_types
=
{
migraphx
::
shape
::
fp8e4m3fnuz_type
};
shape
::
type_t
target_type
=
migraphx
::
shape
::
float_type
;
std
::
string
name
()
const
{
return
"autocast_fp8_pass"
;
}
void
apply
(
module
&
m
)
const
;
bool
is_fp8_type
(
const
shape
::
type_t
&
s
)
const
;
};
}
// 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