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
b30a17c3
Commit
b30a17c3
authored
May 15, 2019
by
Shucai Xiao
Browse files
clang format
parent
d64ab071
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
17 deletions
+21
-17
src/include/migraphx/op/convert.hpp
src/include/migraphx/op/convert.hpp
+3
-3
src/quantization.cpp
src/quantization.cpp
+18
-14
No files found.
src/include/migraphx/op/convert.hpp
View file @
b30a17c3
...
@@ -20,8 +20,8 @@ namespace op {
...
@@ -20,8 +20,8 @@ namespace op {
struct
convert
:
unary
<
convert
>
struct
convert
:
unary
<
convert
>
{
{
shape
::
type_t
target_type
=
shape
::
half_type
;
shape
::
type_t
target_type
=
shape
::
half_type
;
float
scale
=
1.0
f
;
float
scale
=
1.0
f
;
float
shift
=
0.0
f
;
float
shift
=
0.0
f
;
template
<
class
Self
,
class
F
>
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
static
auto
reflect
(
Self
&
self
,
F
f
)
...
@@ -41,7 +41,7 @@ struct convert : unary<convert>
...
@@ -41,7 +41,7 @@ struct convert : unary<convert>
}
}
convert
(
shape
::
type_t
t
)
:
target_type
{
t
}
{}
convert
(
shape
::
type_t
t
)
:
target_type
{
t
}
{}
convert
(
shape
::
type_t
t
,
float
sle
,
float
sft
)
:
target_type
{
t
},
scale
{
sle
},
shift
{
sft
}
{}
convert
(
shape
::
type_t
t
,
float
sle
,
float
sft
)
:
target_type
{
t
},
scale
{
sle
},
shift
{
sft
}
{}
convert
()
{}
convert
()
{}
};
};
...
...
src/quantization.cpp
View file @
b30a17c3
...
@@ -215,29 +215,33 @@ void quantize_int8(program& prog, const std::vector<std::string>& ins_names)
...
@@ -215,29 +215,33 @@ void quantize_int8(program& prog, const std::vector<std::string>& ins_names)
// used as scale and shift(.0f), which will generate results diffrent from
// used as scale and shift(.0f), which will generate results diffrent from
// the original results. To adjust the output to be "correct(approximatly
// the original results. To adjust the output to be "correct(approximatly
// equal)", we need additional calculation for the adjustment
// equal)", we need additional calculation for the adjustment
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
());
int32_t
quant_alpha
=
static_cast
<
int32_t
>
(
dot_op
.
alpha
/
(
int8_param
[
0
].
first
*
int8_param
[
1
].
first
)
+
0.5
f
);
int32_t
quant_alpha
=
static_cast
<
int32_t
>
(
dot_op
.
alpha
/
(
int8_param
[
0
].
first
*
int8_param
[
1
].
first
)
+
0.5
f
);
int32_t
quant_beta
=
static_cast
<
int32_t
>
(
dot_op
.
beta
+
0.5
f
);
int32_t
quant_beta
=
static_cast
<
int32_t
>
(
dot_op
.
beta
+
0.5
f
);
prog
.
replace_instruction
(
ins
,
op
::
quant_dot
{
quant_alpha
,
quant_beta
},
converted_inputs
);
prog
.
replace_instruction
(
ins
,
op
::
quant_dot
{
quant_alpha
,
quant_beta
},
converted_inputs
);
}
}
else
if
(
ins
->
name
()
==
"convolution"
)
else
if
(
ins
->
name
()
==
"convolution"
)
{
{
// Current MIOpen convolution does not support alpha and beta,
// Current MIOpen convolution does not support alpha and beta,
// so we need a separate multiply to adjust the output
// so we need a separate multiply to adjust the output
auto
conv_op
=
any_cast
<
op
::
convolution
>
(
ins
->
get_operator
());
auto
conv_op
=
any_cast
<
op
::
convolution
>
(
ins
->
get_operator
());
auto
padding
=
conv_op
.
padding
;
auto
padding
=
conv_op
.
padding
;
auto
stride
=
conv_op
.
stride
;
auto
stride
=
conv_op
.
stride
;
auto
dilation
=
conv_op
.
dilation
;
auto
dilation
=
conv_op
.
dilation
;
auto
padding_mode
=
conv_op
.
padding_mode
;
auto
padding_mode
=
conv_op
.
padding_mode
;
auto
group
=
conv_op
.
group
;
auto
group
=
conv_op
.
group
;
auto
adjust_factor
=
1.0
/
int8_param
[
0
].
first
*
int8_param
[
1
].
first
;
auto
adjust_factor
=
1.0
/
int8_param
[
0
].
first
*
int8_param
[
1
].
first
;
auto
conv_res
=
prog
.
insert_instruction
(
ins
,
op
::
quant_convolution
{
padding
,
stride
,
dilation
,
padding_mode
,
group
},
converted_inputs
);
auto
conv_res
=
prog
.
insert_instruction
(
ins
,
op
::
quant_convolution
{
padding
,
stride
,
dilation
,
padding_mode
,
group
},
converted_inputs
);
auto
conv_lens
=
conv_res
->
get_shape
().
lens
();
auto
conv_lens
=
conv_res
->
get_shape
().
lens
();
auto
fl
=
prog
.
add_literal
(
literal
(
adjust_factor
));
auto
fl
=
prog
.
add_literal
(
literal
(
adjust_factor
));
auto
adj_fact
=
prog
.
insert_instruction
(
ins
,
op
::
multibroadcast
{
conv_lens
},
fl
);
auto
adj_fact
=
prog
.
insert_instruction
(
ins
,
op
::
multibroadcast
{
conv_lens
},
fl
);
prog
.
replace_instruction
(
ins
,
adj_fact
);
prog
.
replace_instruction
(
ins
,
adj_fact
);
}
}
else
else
...
...
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