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
cb204d61
Commit
cb204d61
authored
Aug 31, 2019
by
Shucai Xiao
Browse files
add more unit tests
parent
cc0189df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
test/gpu/quantization.cpp
test/gpu/quantization.cpp
+61
-0
No files found.
test/gpu/quantization.cpp
View file @
cb204d61
...
...
@@ -2,6 +2,7 @@
#include <vector>
#include <migraphx/operators.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/quantization.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/gpu/target.hpp>
...
...
@@ -65,4 +66,64 @@ TEST_CASE(target_copy)
}
}
TEST_CASE
(
int8_quantization
)
{
auto
run_prog
=
[](
migraphx
::
program
p
,
const
migraphx
::
target
&
t
,
migraphx
::
program
::
parameter_map
&
m_in
,
std
::
vector
<
float
>&
res
)
{
std
::
vector
<
migraphx
::
program
::
parameter_map
>
cali_data
;
cali_data
.
push_back
(
m_in
);
migraphx
::
quantize_int8
(
p
,
t
,
cali_data
);
p
.
compile
(
t
);
migraphx
::
program
::
parameter_map
m
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
{
if
(
m_in
.
count
(
x
.
first
)
>
0
)
{
m
[
x
.
first
]
=
t
.
copy_to
(
m_in
[
x
.
first
]);
}
else
{
m
[
x
.
first
]
=
t
.
allocate
(
x
.
second
);
}
}
auto
result
=
t
.
copy_from
(
p
.
eval
(
m
));
result
.
visit
([
&
](
auto
v
)
{
res
.
assign
(
v
.
begin
(),
v
.
end
());
});
};
auto
create_program
=
[]
{
migraphx
::
program
p
;
migraphx
::
shape
sa
{
migraphx
::
shape
::
float_type
,
{
2
,
16
}};
migraphx
::
shape
sb
{
migraphx
::
shape
::
float_type
,
{
16
,
8
}};
migraphx
::
shape
sc
{
migraphx
::
shape
::
float_type
,
{
2
,
8
}};
auto
pa
=
p
.
add_parameter
(
"a"
,
sa
);
auto
pb
=
p
.
add_parameter
(
"b"
,
sb
);
auto
pc
=
p
.
add_parameter
(
"c"
,
sc
);
p
.
add_instruction
(
migraphx
::
op
::
dot
{},
pa
,
pb
,
pc
);
return
p
;
};
{
auto
p
=
create_program
();
migraphx
::
program
::
parameter_map
m
;
migraphx
::
shape
sa
{
migraphx
::
shape
::
float_type
,
{
2
,
16
}};
migraphx
::
shape
sc
{
migraphx
::
shape
::
float_type
,
{
2
,
8
}};
m
[
"a"
]
=
migraphx
::
generate_argument
(
sa
);
m
[
"c"
]
=
migraphx
::
generate_argument
(
sc
);
std
::
vector
<
float
>
cpu_result
;
migraphx
::
target
cpu_t
=
migraphx
::
cpu
::
target
{};
run_prog
(
p
,
cpu_t
,
m
,
cpu_result
);
std
::
vector
<
float
>
gpu_result
;
migraphx
::
target
gpu_t
=
migraphx
::
gpu
::
target
{};
run_prog
(
p
,
gpu_t
,
m
,
gpu_result
);
EXPECT
(
migraphx
::
verify_range
(
cpu_result
,
gpu_result
));
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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