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
cbfbd04c
Commit
cbfbd04c
authored
May 21, 2019
by
Shucai Xiao
Browse files
extend the convert operator for int8 quantization
parent
b643f202
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
7 deletions
+31
-7
src/include/migraphx/op/convert.hpp
src/include/migraphx/op/convert.hpp
+10
-1
src/targets/gpu/convert.cpp
src/targets/gpu/convert.cpp
+1
-1
src/targets/gpu/device/convert.cpp
src/targets/gpu/device/convert.cpp
+19
-4
src/targets/gpu/include/migraphx/gpu/device/convert.hpp
src/targets/gpu/include/migraphx/gpu/device/convert.hpp
+1
-1
No files found.
src/include/migraphx/op/convert.hpp
View file @
cbfbd04c
...
...
@@ -38,7 +38,16 @@ struct convert : unary<convert>
auto
apply
()
const
{
return
[
&
](
auto
x
)
{
return
scale
*
x
+
shift
;
};
return
[
&
](
auto
x
)
{
float
res
=
scale
*
x
+
shift
;
if
(
target_type
==
shape
::
int8_type
)
{
res
=
res
>
127.0
?
127.0
:
res
;
res
=
res
<
-
128.0
?
-
128.0
:
res
;
}
return
res
;
};
}
convert
(
shape
::
type_t
t
)
:
target_type
{
t
}
{}
...
...
src/targets/gpu/convert.cpp
View file @
cbfbd04c
...
...
@@ -15,7 +15,7 @@ shape hip_convert::compute_shape(std::vector<shape> inputs) const
argument
hip_convert
::
compute
(
context
&
ctx
,
const
shape
&
,
const
std
::
vector
<
argument
>&
args
)
const
{
device
::
convert
(
ctx
.
get_stream
().
get
(),
args
[
1
],
args
[
0
],
op
.
scale
,
op
.
shift
);
device
::
convert
(
ctx
.
get_stream
().
get
(),
args
[
1
],
args
[
0
],
op
.
scale
,
op
.
shift
,
op
.
target_type
);
return
args
[
1
];
}
...
...
src/targets/gpu/device/convert.cpp
View file @
cbfbd04c
...
...
@@ -6,15 +6,30 @@ inline namespace MIGRAPHX_INLINE_NS {
namespace
gpu
{
namespace
device
{
void
convert
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
float
scale
,
float
shift
)
void
convert
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
float
scale
,
float
shift
,
shape
::
type_t
target_type
)
{
result
.
visit
([
&
](
auto
output
)
{
arg
.
visit
([
&
](
auto
input
)
{
const
auto
*
input_ptr
=
device_cast
(
input
.
data
());
auto
*
output_ptr
=
device_cast
(
output
.
data
());
gs_launch
(
stream
,
result
.
get_shape
().
elements
())(
[
=
](
auto
i
)
{
output_ptr
[
i
]
=
input_ptr
[
i
]
*
scale
+
shift
;
});
if
(
target_type
==
shape
::
int8_type
)
{
gs_launch
(
stream
,
result
.
get_shape
().
elements
())(
[
=
](
auto
i
)
{
output_ptr
[
i
]
=
std
::
min
<
int8_t
>
(
std
::
max
<
float
>
(
-
128
,
input_ptr
[
i
]
*
scale
+
shift
),
127
);
});
}
else
{
gs_launch
(
stream
,
result
.
get_shape
().
elements
())(
[
=
](
auto
i
)
{
output_ptr
[
i
]
=
input_ptr
[
i
]
*
scale
+
shift
;
});
}
});
});
}
...
...
src/targets/gpu/include/migraphx/gpu/device/convert.hpp
View file @
cbfbd04c
...
...
@@ -12,7 +12,7 @@ namespace gpu {
namespace
device
{
void
convert
(
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
float
scale
,
float
shift
);
hipStream_t
stream
,
const
argument
&
result
,
const
argument
&
arg
,
float
scale
,
float
shift
,
shape
::
type_t
target_type
);
}
// namespace device
}
// namespace gpu
...
...
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