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
ad4a68f0
Unverified
Commit
ad4a68f0
authored
Jul 22, 2021
by
Cagri Eryilmaz
Committed by
GitHub
Jul 22, 2021
Browse files
Merge branch 'develop' into unet
parents
7555a27a
eacf042e
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
282 additions
and
11 deletions
+282
-11
test/onnx/quantizelinear_neg_axis_test.onnx
test/onnx/quantizelinear_neg_axis_test.onnx
+1
-1
test/onnx/quantizelinear_test.onnx
test/onnx/quantizelinear_test.onnx
+4
-9
test/onnx/quantizelinear_zero_point_test.onnx
test/onnx/quantizelinear_zero_point_test.onnx
+21
-0
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+107
-0
test/rewrite_quantization_test.cpp
test/rewrite_quantization_test.cpp
+72
-0
test/tf/tf_test.cpp
test/tf/tf_test.cpp
+5
-1
test/verify/test_dequantizelinear.cpp
test/verify/test_dequantizelinear.cpp
+24
-0
test/verify/test_quantizelinear.cpp
test/verify/test_quantizelinear.cpp
+24
-0
test/verify/test_quantizelinear_int32.cpp
test/verify/test_quantizelinear_int32.cpp
+24
-0
No files found.
test/onnx/quantizelinear_neg_axis_test.onnx
View file @
ad4a68f0
...
...
@@ -23,4 +23,4 @@
B
\ No newline at end of file
B
\ No newline at end of file
test/onnx/quantizelinear_test.onnx
View file @
ad4a68f0
quantizelinear_test:
{
quantizelinear_test:
g
0
1
2out"QuantizeLinearquantizelinear_testZ
1out"QuantizeLinearquantizelinear_testZ
0
...
...
@@ -10,12 +9,8 @@
1
Z
2
b
out
B
\ No newline at end of file
B
\ No newline at end of file
test/onnx/quantizelinear_zero_point_test.onnx
0 → 100644
View file @
ad4a68f0
quantizelinear_zero_point_test:
0
1
2out"QuantizeLinearquantizelinear_zero_point_testZ
0
Z
1
Z
2
b
out
B
\ No newline at end of file
test/ref_ops_test.cpp
View file @
ad4a68f0
...
...
@@ -1233,6 +1233,58 @@ TEST_CASE(deconv_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
dequantizelinear
)
{
{
/*uint8*/
migraphx
::
shape
xs
{
migraphx
::
shape
::
uint8_type
,
{
1
,
3
,
3
}};
std
::
vector
<
uint8_t
>
xv
=
{
0
,
1
,
2
,
5
,
10
,
50
,
100
,
150
,
250
};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
}};
std
::
vector
<
float
>
sv
=
{
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
};
migraphx
::
shape
zs
{
migraphx
::
shape
::
uint8_type
,
{
1
,
3
,
3
}};
std
::
vector
<
uint8_t
>
zv
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
xs
,
xv
);
auto
s
=
mm
->
add_literal
(
ss
,
sv
);
auto
z
=
mm
->
add_literal
(
zs
,
zv
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"dequantizelinear"
),
x
,
s
,
z
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
p1
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p1
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
(
9
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
0
,
2
,
4
,
10
,
20
,
100
,
200
,
300
,
500
};
EXPECT
(
results_vector
==
gold
);
}
{
/*int8*/
migraphx
::
shape
xs
{
migraphx
::
shape
::
int8_type
,
{
1
,
3
,
3
}};
std
::
vector
<
int8_t
>
xv
=
{
-
128
,
-
100
,
-
50
,
-
1
,
0
,
1
,
50
,
100
,
127
};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
}};
std
::
vector
<
float
>
sv
=
{
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
xs
,
xv
);
auto
s
=
mm
->
add_literal
(
ss
,
sv
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"dequantizelinear"
),
x
,
s
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
p1
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p1
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
(
9
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
-
256
,
-
200
,
-
100
,
-
2
,
0
,
2
,
100
,
200
,
254
};
EXPECT
(
results_vector
==
gold
);
}
}
TEST_CASE
(
div_test
)
{
migraphx
::
program
p
;
...
...
@@ -3287,6 +3339,61 @@ TEST_CASE(quant_conv2d_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
s
));
}
TEST_CASE
(
quantizelinear
)
{
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
3
}};
std
::
vector
<
float
>
xv
=
{
-
300
,
600
,
129
,
-
1000
,
4
,
3
,
-
6
,
600
,
550
,
-
300
,
600
,
129
,
-
1000
,
4
,
3
,
-
6
,
600
,
550
};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
3
}};
std
::
vector
<
float
>
sv
=
{
2
,
2
,
2
,
4
,
4
,
4
,
6
,
6
,
6
,
2
,
2
,
2
,
4
,
4
,
4
,
6
,
6
,
6
};
migraphx
::
shape
zs
{
migraphx
::
shape
::
int8_type
,
{
2
,
3
,
3
}};
std
::
vector
<
uint8_t
>
zv
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
xs
,
xv
);
auto
s
=
mm
->
add_literal
(
ss
,
sv
);
auto
z
=
mm
->
add_literal
(
zs
,
zv
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"quantizelinear"
),
x
,
s
,
z
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
p1
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p1
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
(
18
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
-
128
,
127
,
65
,
-
128
,
1
,
1
,
-
1
,
100
,
92
,
-
128
,
127
,
65
,
-
128
,
1
,
1
,
-
1
,
100
,
92
};
EXPECT
(
results_vector
==
gold
);
}
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
3
}};
std
::
vector
<
float
>
xv
=
{
-
300
,
600
,
129
,
-
1000
,
4
,
3
,
-
6
,
600
,
550
,
-
300
,
600
,
129
,
-
1000
,
4
,
3
,
-
6
,
600
,
550
};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
3
}};
std
::
vector
<
float
>
sv
=
{
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
xs
,
xv
);
auto
s
=
mm
->
add_literal
(
ss
,
sv
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"quantizelinear"
),
x
,
s
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
p1
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p1
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
(
18
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
0
,
255
,
65
,
0
,
2
,
2
,
0
,
255
,
255
,
0
,
255
,
65
,
0
,
2
,
2
,
0
,
255
,
255
};
EXPECT
(
results_vector
==
gold
);
}
}
TEST_CASE
(
recip_test
)
{
migraphx
::
program
p
;
...
...
test/rewrite_quantization_test.cpp
0 → 100644
View file @
ad4a68f0
#include <migraphx/rewrite_quantization.hpp>
#include <migraphx/program.hpp>
#include <migraphx/ref/target.hpp>
#include <migraphx/op/convolution.hpp>
#include <migraphx/op/reshape.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/ranges.hpp>
#include <test.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/serialize.hpp>
#include <migraphx/verify.hpp>
bool
is_quantizelinear
(
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"quantizelinear"
;
}
bool
is_dequantizelinear
(
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"dequantizelinear"
;
}
TEST_CASE
(
quantizelinear
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
}};
std
::
vector
<
float
>
xv
=
{
-
300
,
200
,
129
,
1
,
2
,
3
,
500
,
1000
,
50
};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
}};
std
::
vector
<
float
>
sv
=
{
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
xs
,
xv
);
auto
s
=
mm
->
add_literal
(
ss
,
sv
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"quantizelinear"
),
x
,
s
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_quantization
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_quantizelinear
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_quantizelinear
));
}
TEST_CASE
(
dequantizelinear
)
{
migraphx
::
shape
xs
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
}};
std
::
vector
<
float
>
xv
=
{
0
,
1
,
2
,
5
,
10
,
50
,
100
,
150
,
250
};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
3
}};
std
::
vector
<
float
>
sv
=
{
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
,
2
};
migraphx
::
shape
zs
{
migraphx
::
shape
::
uint8_type
,
{
1
,
3
,
3
}};
std
::
vector
<
uint8_t
>
zv
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
auto
create_program
=
[
&
]()
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_literal
(
xs
,
xv
);
auto
s
=
mm
->
add_literal
(
ss
,
sv
);
auto
z
=
mm
->
add_literal
(
zs
,
zv
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"dequantizelinear"
),
x
,
s
,
z
);
return
p
;
};
migraphx
::
program
p1
=
create_program
();
migraphx
::
program
p2
=
create_program
();
migraphx
::
rewrite_quantization
opt
;
opt
.
apply
(
*
p2
.
get_main_module
());
EXPECT
(
any_of
(
*
p1
.
get_main_module
(),
&
is_dequantizelinear
));
EXPECT
(
none_of
(
*
p2
.
get_main_module
(),
&
is_dequantizelinear
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/tf/tf_test.cpp
View file @
ad4a68f0
...
...
@@ -6,11 +6,15 @@
#include <migraphx/simplify_reshapes.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/tf.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
#include <migraphx/op/convolution.hpp>
#include <migraphx/op/reduce_mean.hpp>
#include <migraphx/op/pooling.hpp>
#include <migraphx/op/slice.hpp>
#include <migraphx/serialize.hpp>
...
...
test/verify/test_dequantizelinear.cpp
0 → 100644
View file @
ad4a68f0
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_dequantizelinear
:
verify_program
<
test_dequantizelinear
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sx
{
migraphx
::
shape
::
int8_type
,
{
2
,
2
,
2
}};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
}};
migraphx
::
shape
sz
{
migraphx
::
shape
::
int8_type
,
{
2
,
2
,
2
}};
auto
input1
=
mm
->
add_parameter
(
"x"
,
sx
);
auto
input2
=
mm
->
add_parameter
(
"x_scale"
,
ss
);
auto
input3
=
mm
->
add_parameter
(
"x_zero_point"
,
sz
);
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"dequantizelinear"
),
input1
,
input2
,
input3
);
mm
->
add_return
({
r
});
return
p
;
};
};
test/verify/test_quantizelinear.cpp
0 → 100644
View file @
ad4a68f0
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_quantizelinear
:
verify_program
<
test_quantizelinear
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sx
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
}};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
}};
migraphx
::
shape
sz
{
migraphx
::
shape
::
int8_type
,
{
2
,
2
,
2
}};
auto
input1
=
mm
->
add_parameter
(
"x"
,
sx
);
auto
input2
=
mm
->
add_parameter
(
"y_scale"
,
ss
);
auto
input3
=
mm
->
add_parameter
(
"y_zero_point"
,
sz
);
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"quantizelinear"
),
input1
,
input2
,
input3
);
mm
->
add_return
({
r
});
return
p
;
};
};
test/verify/test_quantizelinear_int32.cpp
0 → 100644
View file @
ad4a68f0
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_quantizelinear_int32
:
verify_program
<
test_quantizelinear_int32
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
sx
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
,
2
}};
migraphx
::
shape
ss
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
}};
migraphx
::
shape
sz
{
migraphx
::
shape
::
int8_type
,
{
2
,
2
,
2
}};
auto
input1
=
mm
->
add_parameter
(
"x"
,
sx
);
auto
input2
=
mm
->
add_parameter
(
"y_scale"
,
ss
);
auto
input3
=
mm
->
add_parameter
(
"y_zero_point"
,
sz
);
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"quantizelinear"
),
input1
,
input2
,
input3
);
mm
->
add_return
({
r
});
return
p
;
};
};
Prev
1
2
Next
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