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
dfb016fe
Commit
dfb016fe
authored
Aug 29, 2019
by
Shucai Xiao
Browse files
clang format
parent
e12ee1f8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
18 deletions
+21
-18
src/include/migraphx/quantization.hpp
src/include/migraphx/quantization.hpp
+6
-4
src/quantization.cpp
src/quantization.cpp
+15
-14
No files found.
src/include/migraphx/quantization.hpp
View file @
dfb016fe
...
@@ -23,12 +23,14 @@ std::size_t capture_arguments(program& prog,
...
@@ -23,12 +23,14 @@ std::size_t capture_arguments(program& prog,
const
std
::
vector
<
std
::
string
>&
ins_names
,
const
std
::
vector
<
std
::
string
>&
ins_names
,
const
std
::
function
<
void
(
std
::
size_t
,
std
::
vector
<
argument
>
)
>&
func
);
const
std
::
function
<
void
(
std
::
size_t
,
std
::
vector
<
argument
>
)
>&
func
);
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
capture_arguments_impl
(
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
program
&
prog
,
const
target
&
t
,
const
std
::
vector
<
std
::
string
>&
ins_names
=
{
"dot"
,
"convolution"
});
capture_arguments_impl
(
program
&
prog
,
const
target
&
t
,
const
std
::
vector
<
std
::
string
>&
ins_names
=
{
"dot"
,
"convolution"
});
template
<
class
T
>
template
<
class
T
>
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
capture_arguments
(
capture_arguments
(
program
&
prog
,
T
&&
t
,
const
std
::
vector
<
std
::
string
>&
ins_names
=
{
"dot"
,
"convolution"
})
program
&
prog
,
T
&&
t
,
const
std
::
vector
<
std
::
string
>&
ins_names
=
{
"dot"
,
"convolution"
})
{
{
static_assert
(
std
::
is_same
<
std
::
remove_cv_t
<
std
::
remove_reference_t
<
T
>>
,
target
>
{}
&&
static_assert
(
std
::
is_same
<
std
::
remove_cv_t
<
std
::
remove_reference_t
<
T
>>
,
target
>
{}
&&
std
::
is_lvalue_reference
<
T
>
{},
std
::
is_lvalue_reference
<
T
>
{},
...
...
src/quantization.cpp
View file @
dfb016fe
...
@@ -162,7 +162,8 @@ void quantize(program& prog, const std::vector<std::string>& ins_names)
...
@@ -162,7 +162,8 @@ void quantize(program& prog, const std::vector<std::string>& ins_names)
void
quantize
(
program
&
prog
)
{
quantize
(
prog
,
{
"all"
});
}
void
quantize
(
program
&
prog
)
{
quantize
(
prog
,
{
"all"
});
}
static
void
quantize_ins
(
program
&
prog
,
instruction_ref
ins
,
static
void
quantize_ins
(
program
&
prog
,
instruction_ref
ins
,
std
::
vector
<
instruction_ref
>&
converted_inputs
,
std
::
vector
<
instruction_ref
>&
converted_inputs
,
const
std
::
vector
<
std
::
pair
<
float
,
float
>>&
ins_quant_params
)
const
std
::
vector
<
std
::
pair
<
float
,
float
>>&
ins_quant_params
)
{
{
...
@@ -171,8 +172,7 @@ static void quantize_ins(program& prog, instruction_ref ins,
...
@@ -171,8 +172,7 @@ static void quantize_ins(program& prog, instruction_ref ins,
if
(
ins
->
name
()
==
"dot"
)
if
(
ins
->
name
()
==
"dot"
)
{
{
auto
dot_op
=
any_cast
<
op
::
dot
>
(
ins
->
get_operator
());
auto
dot_op
=
any_cast
<
op
::
dot
>
(
ins
->
get_operator
());
float
new_alpha
=
float
new_alpha
=
dot_op
.
alpha
/
(
ins_quant_params
[
0
].
first
*
ins_quant_params
[
1
].
first
);
dot_op
.
alpha
/
(
ins_quant_params
[
0
].
first
*
ins_quant_params
[
1
].
first
);
float
new_beta
=
dot_op
.
beta
;
float
new_beta
=
dot_op
.
beta
;
// We need additional checking about the quant_alpha value. If
// We need additional checking about the quant_alpha value. If
// abs(quant_alpha) > 50 (some tmp value set here), we can convert
// abs(quant_alpha) > 50 (some tmp value set here), we can convert
...
@@ -218,8 +218,8 @@ static void quantize_ins(program& prog, instruction_ref ins,
...
@@ -218,8 +218,8 @@ static void quantize_ins(program& prog, instruction_ref ins,
instruction_ref
beta_c
{};
instruction_ref
beta_c
{};
if
(
orig_type
!=
shape
::
float_type
)
if
(
orig_type
!=
shape
::
float_type
)
{
{
auto
fp32_c
=
prog
.
insert_instruction
(
auto
fp32_c
=
ins
,
op
::
convert
{
shape
::
float_type
},
inputs
.
back
());
prog
.
insert_instruction
(
ins
,
op
::
convert
{
shape
::
float_type
},
inputs
.
back
());
auto
fp32_beta_c
=
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_beta
,
fp32_c
);
auto
fp32_beta_c
=
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_beta
,
fp32_c
);
beta_c
=
prog
.
insert_instruction
(
ins
,
op
::
convert
{
orig_type
},
fp32_beta_c
);
beta_c
=
prog
.
insert_instruction
(
ins
,
op
::
convert
{
orig_type
},
fp32_beta_c
);
}
}
...
@@ -289,8 +289,7 @@ static void quantize_ins(program& prog, instruction_ref ins,
...
@@ -289,8 +289,7 @@ static void quantize_ins(program& prog, instruction_ref ins,
}
}
else
else
{
{
auto
adjusted_conv
=
auto
adjusted_conv
=
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_factor
,
float_conv
);
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_factor
,
float_conv
);
prog
.
replace_instruction
(
ins
,
op
::
convert
{
orig_type
},
adjusted_conv
);
prog
.
replace_instruction
(
ins
,
op
::
convert
{
orig_type
},
adjusted_conv
);
}
}
}
}
...
@@ -348,7 +347,8 @@ void quantize_int8(program& prog,
...
@@ -348,7 +347,8 @@ void quantize_int8(program& prog,
for
(
auto
input
:
inputs
)
for
(
auto
input
:
inputs
)
{
{
// calculate the index of each instruction to be quantized
// calculate the index of each instruction to be quantized
std
::
size_t
ins_index
=
(
map_ins_index
.
count
(
input
)
>
0
)
?
map_ins_index
[
input
]
:
quant_param_index
++
;
std
::
size_t
ins_index
=
(
map_ins_index
.
count
(
input
)
>
0
)
?
map_ins_index
[
input
]
:
quant_param_index
++
;
map_ins_index
[
input
]
=
ins_index
;
map_ins_index
[
input
]
=
ins_index
;
auto
param
=
quant_params
[
map_ins_index
[
input
]];
auto
param
=
quant_params
[
map_ins_index
[
input
]];
...
@@ -371,7 +371,8 @@ void quantize_int8(program& prog,
...
@@ -371,7 +371,8 @@ void quantize_int8(program& prog,
// if the input is a convert operator, uses its input
// if the input is a convert operator, uses its input
// as its current input
// as its current input
instruction_ref
quant_input
{};
instruction_ref
quant_input
{};
if
(
input
->
name
()
==
"convert"
and
input
->
inputs
().
front
()
->
get_shape
().
type
()
==
quant_type
)
if
(
input
->
name
()
==
"convert"
and
input
->
inputs
().
front
()
->
get_shape
().
type
()
==
quant_type
)
{
{
quant_input
=
input
->
inputs
().
front
();
quant_input
=
input
->
inputs
().
front
();
}
}
...
...
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