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
8efe1eeb
"torchvision/vscode:/vscode.git/clone" did not exist on "152c2b3a9403811198beb8fffc5070fc80d1273c"
Commit
8efe1eeb
authored
Aug 19, 2019
by
Shucai Xiao
Browse files
clang format
parent
3f199ad8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
12 deletions
+15
-12
src/include/migraphx/quantization.hpp
src/include/migraphx/quantization.hpp
+4
-3
src/program.cpp
src/program.cpp
+1
-1
src/quantization.cpp
src/quantization.cpp
+10
-8
No files found.
src/include/migraphx/quantization.hpp
View file @
8efe1eeb
...
@@ -18,9 +18,10 @@ void quantize(program& prog);
...
@@ -18,9 +18,10 @@ void quantize(program& prog);
// insert the capture operator for the inputs of each operator to be quantized
// insert the capture operator for the inputs of each operator to be quantized
// to int8
// to int8
std
::
size_t
capture_arguments
(
program
&
prog
,
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
(
program
&
prog
,
const
std
::
vector
<
std
::
string
>&
ins_names
);
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
capture_arguments
(
program
&
prog
,
const
std
::
vector
<
std
::
string
>&
ins_names
);
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
capture_arguments
(
program
&
prog
);
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
capture_arguments
(
program
&
prog
);
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace MIGRAPHX_INLINE_NS
...
...
src/program.cpp
View file @
8efe1eeb
...
@@ -112,7 +112,7 @@ void program::assign(const program& p)
...
@@ -112,7 +112,7 @@ void program::assign(const program& p)
{
{
impl
->
instructions
.
clear
();
impl
->
instructions
.
clear
();
}
}
impl
->
ctx
=
p
.
impl
->
ctx
;
impl
->
ctx
=
p
.
impl
->
ctx
;
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
ins_map
;
std
::
unordered_map
<
instruction_ref
,
instruction_ref
>
ins_map
;
for
(
auto
ins
:
iterator_for
(
p
))
for
(
auto
ins
:
iterator_for
(
p
))
...
...
src/quantization.cpp
View file @
8efe1eeb
...
@@ -119,8 +119,8 @@ void quantize(program& prog) { quantize(prog, {"all"}); }
...
@@ -119,8 +119,8 @@ void quantize(program& prog) { quantize(prog, {"all"}); }
// For the input of each input argument, we need to insert a
// For the input of each input argument, we need to insert a
// capture operator to compute the scale and shift
// capture operator to compute the scale and shift
std
::
size_t
capture_arguments
(
program
&
prog
,
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
)
{
{
size_t
num_quant_params
=
0
;
size_t
num_quant_params
=
0
;
...
@@ -164,25 +164,27 @@ std::size_t capture_arguments(program& prog,
...
@@ -164,25 +164,27 @@ std::size_t capture_arguments(program& prog,
return
num_quant_params
;
return
num_quant_params
;
}
}
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
capture_arguments
(
program
&
prog
,
const
std
::
vector
<
std
::
string
>&
ins_names
)
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
capture_arguments
(
program
&
prog
,
const
std
::
vector
<
std
::
string
>&
ins_names
)
{
{
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
int8_quant_params
=
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
int8_quant_params
=
std
::
make_shared
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
();
std
::
make_shared
<
std
::
vector
<
std
::
pair
<
float
,
float
>>>
();
std
::
shared_ptr
<
std
::
vector
<
float
>>
max_abs_vals
=
std
::
make_shared
<
std
::
vector
<
float
>>
();
std
::
shared_ptr
<
std
::
vector
<
float
>>
max_abs_vals
=
std
::
make_shared
<
std
::
vector
<
float
>>
();
auto
calc_quant_params
=
[
int8_quant_params
,
max_abs_vals
](
std
::
size_t
ins_index
,
std
::
vector
<
migraphx
::
argument
>
args
)
{
auto
calc_quant_params
=
[
int8_quant_params
,
max_abs_vals
](
std
::
size_t
ins_index
,
std
::
vector
<
migraphx
::
argument
>
args
)
{
std
::
pair
<
float
,
float
>
param_pair
{
64.0
f
,
0.0
f
};
std
::
pair
<
float
,
float
>
param_pair
{
64.0
f
,
0.0
f
};
// scale and shift is need for only int8 type, and we do not
// scale and shift is need for only int8 type, and we do not
// consider shift, so set shift to 0
// consider shift, so set shift to 0
std
::
vector
<
float
>
vec_val
;
std
::
vector
<
float
>
vec_val
;
args
.
front
().
visit
([
&
](
auto
output
)
{
vec_val
.
assign
(
output
.
begin
(),
output
.
end
());
});
args
.
front
().
visit
([
&
](
auto
output
)
{
vec_val
.
assign
(
output
.
begin
(),
output
.
end
());
});
auto
max_val
=
*
std
::
max_element
(
vec_val
.
begin
(),
vec_val
.
end
());
auto
max_val
=
*
std
::
max_element
(
vec_val
.
begin
(),
vec_val
.
end
());
auto
min_val
=
*
std
::
min_element
(
vec_val
.
begin
(),
vec_val
.
end
());
auto
min_val
=
*
std
::
min_element
(
vec_val
.
begin
(),
vec_val
.
end
());
auto
max_abs
=
std
::
max
(
std
::
fabs
(
max_val
),
std
::
fabs
(
min_val
));
auto
max_abs
=
std
::
max
(
std
::
fabs
(
max_val
),
std
::
fabs
(
min_val
));
max_abs_vals
->
at
(
ins_index
)
=
std
::
max
(
max_abs_vals
->
at
(
ins_index
),
max_abs
);
max_abs_vals
->
at
(
ins_index
)
=
std
::
max
(
max_abs_vals
->
at
(
ins_index
),
max_abs
);
param_pair
.
first
=
127.0
f
/
max_abs_vals
->
at
(
ins_index
);
param_pair
.
first
=
127.0
f
/
max_abs_vals
->
at
(
ins_index
);
int8_quant_params
->
at
(
ins_index
)
=
param_pair
;
int8_quant_params
->
at
(
ins_index
)
=
param_pair
;
};
};
...
...
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