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
7531f5f6
Commit
7531f5f6
authored
Apr 09, 2019
by
Shucai Xiao
Browse files
backup code for the function to quantize an instruction.
parent
9174d78f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
7 deletions
+17
-7
src/quantize_ins.cpp
src/quantize_ins.cpp
+17
-7
No files found.
src/quantize_ins.cpp
View file @
7531f5f6
...
@@ -22,6 +22,16 @@ instruction_ref insert_fp16(program& prog,
...
@@ -22,6 +22,16 @@ instruction_ref insert_fp16(program& prog,
assert
(
ins
->
get_shape
().
type
()
==
shape
::
float_type
||
assert
(
ins
->
get_shape
().
type
()
==
shape
::
float_type
||
ins
->
get_shape
().
type
()
==
shape
::
double_type
);
ins
->
get_shape
().
type
()
==
shape
::
double_type
);
instruction_ref
ins_fp16
{};
instruction_ref
ins_fp16
{};
if
(
ins
->
name
()
==
"@literal"
&&
ins
->
outputs
().
size
()
==
1
)
{
std
::
vector
<
float
>
values
;
auto
l_fp32
=
ins
->
get_literal
();
shape
s
=
ins
->
get_shape
();
l_fp32
.
visit
([
&
](
auto
val
)
{
values
.
assign
(
val
.
begin
(),
val
.
end
());
});
ins_fp16
=
prog
.
add_literal
(
literal
({
shape
::
half_type
,
s
.
lens
()},
values
));
}
else
{
if
(
ins
==
std
::
prev
(
prog
.
end
()))
if
(
ins
==
std
::
prev
(
prog
.
end
()))
{
{
ins_fp16
=
prog
.
add_instruction
(
op
::
fp_conversion
{
type
},
ins
);
ins_fp16
=
prog
.
add_instruction
(
op
::
fp_conversion
{
type
},
ins
);
...
@@ -30,6 +40,7 @@ instruction_ref insert_fp16(program& prog,
...
@@ -30,6 +40,7 @@ instruction_ref insert_fp16(program& prog,
{
{
ins_fp16
=
prog
.
insert_instruction
(
std
::
next
(
ins
),
op
::
fp_conversion
{},
ins
);
ins_fp16
=
prog
.
insert_instruction
(
std
::
next
(
ins
),
op
::
fp_conversion
{},
ins
);
}
}
}
map_fp16
[
ins
]
=
ins_fp16
;
map_fp16
[
ins
]
=
ins_fp16
;
return
ins_fp16
;
return
ins_fp16
;
...
@@ -76,18 +87,17 @@ void quantize_ins(program& prog, const std::vector<std::string>& ins_names)
...
@@ -76,18 +87,17 @@ void quantize_ins(program& prog, const std::vector<std::string>& ins_names)
// to convert it back to the original type
// to convert it back to the original type
if
(
ins
->
get_shape
().
type
()
!=
orig_type
)
if
(
ins
->
get_shape
().
type
()
!=
orig_type
)
{
{
instruction_ref
ins_orig_type
{};
if
(
ins
==
std
::
prev
(
prog
.
end
()))
if
(
ins
==
std
::
prev
(
prog
.
end
()))
{
{
ins_orig_type
=
prog
.
add_instruction
(
op
::
fp_conversion
{
orig_type
},
ins
);
prog
.
add_instruction
(
op
::
fp_conversion
{
orig_type
},
ins
);
}
}
else
else
{
{
ins_orig_type
=
auto
ins_orig_type
=
prog
.
insert_instruction
(
std
::
next
(
ins
),
op
::
fp_conversion
{
orig_type
},
ins
);
prog
.
insert_instruction
(
std
::
next
(
ins
),
op
::
fp_conversion
{
orig_type
},
ins
);
prog
.
replace_instruction
(
ins
,
ins_orig_type
);
}
}
prog
.
replace_instruction
(
ins
,
ins_orig_type
);
}
}
}
}
}
}
...
...
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