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
78b8f79b
Commit
78b8f79b
authored
Sep 19, 2023
by
Umang Yadav
Browse files
expected working
parent
78142841
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
11 deletions
+38
-11
src/include/migraphx/verify.hpp
src/include/migraphx/verify.hpp
+25
-2
src/verify_args.cpp
src/verify_args.cpp
+4
-3
test/gpu/quantization.cpp
test/gpu/quantization.cpp
+1
-1
test/quantization.cpp
test/quantization.cpp
+2
-1
test/ref/multinomial.cpp
test/ref/multinomial.cpp
+2
-1
test/ref/random_uniform.cpp
test/ref/random_uniform.cpp
+2
-1
test/ref/rnn_ops.cpp
test/ref/rnn_ops.cpp
+2
-2
No files found.
src/include/migraphx/verify.hpp
View file @
78b8f79b
...
...
@@ -29,6 +29,7 @@
#include <functional>
#include <iostream>
#include <numeric>
#include <assert.h>
#include <migraphx/float_equal.hpp>
#include <migraphx/config.hpp>
...
...
@@ -194,6 +195,25 @@ double get_threshold(const R&, std::size_t tolerance = 80)
return
threshold
;
}
template
<
class
T
>
struct
expected
{
expected
()
=
default
;
expected
(
const
T
&
input
)
:
x
(
&
input
)
{}
const
T
&
data
()
const
{
assert
(
x
!=
nullptr
);
return
*
x
;
}
private:
const
T
*
x
=
nullptr
;
};
// deduction guide for templated expected class
template
<
class
T
>
expected
(
const
T
&
)
->
expected
<
T
>
;
template
<
class
R1
,
class
R2
>
bool
verify_range
(
const
R1
&
r1
,
const
R2
&
r2
,
...
...
@@ -208,9 +228,12 @@ bool verify_range(const R1& r1,
}
template
<
class
R1
,
class
R2
>
bool
verify_range_with_threshold
(
const
R1
&
r1
,
const
R2
&
r2
,
double
threshold
,
double
*
out_error
=
nullptr
)
bool
verify_range_with_threshold
(
const
R1
&
r1
,
const
expected
<
R2
>&
r2
,
double
threshold
,
double
*
out_error
=
nullptr
)
{
auto
error
=
rms_range
(
r1
,
r2
);
auto
error
=
rms_range
(
r1
,
r2
.
data
()
);
if
(
out_error
!=
nullptr
)
*
out_error
=
error
;
return
error
<=
threshold
;
...
...
src/verify_args.cpp
View file @
78b8f79b
...
...
@@ -28,14 +28,15 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
bool
verify_args_with_threshold
(
const
std
::
string
&
name
,
const
argument
&
ref_arg
,
const
argument
&
target_arg
,
const
argument
&
ref_arg
,
double
threshold
)
{
bool
passed
=
true
;
visit_all
(
ref_arg
,
target_arg
)([
&
](
auto
ref
,
auto
target
)
{
double
error
;
passed
=
verify
::
verify_range_with_threshold
(
ref
,
target
,
threshold
,
&
error
);
passed
=
verify
::
verify_range_with_threshold
(
target
,
verify
::
expected
{
ref
},
threshold
,
&
error
);
if
(
not
passed
)
{
// TODO: Check for nans
...
...
@@ -100,7 +101,7 @@ bool verify_args(const std::string& name,
{
double
threshold
=
0.001
;
target_arg
.
visit
([
&
](
auto
ta
)
{
threshold
=
verify
::
get_threshold
(
ta
,
tolerance
);
});
return
verify_args_with_threshold
(
name
,
ref_arg
,
target
_arg
,
threshold
);
return
verify_args_with_threshold
(
name
,
target_arg
,
ref
_arg
,
threshold
);
}
}
// namespace MIGRAPHX_INLINE_NS
...
...
test/gpu/quantization.cpp
View file @
78b8f79b
...
...
@@ -118,7 +118,7 @@ TEST_CASE(int8_quantization)
// the regular pipeline uses the rewrite_quantization in the much
// earlier stage.
if
(
migraphx
::
gpu
::
mlir_enabled
())
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
ref
_result
,
gpu
_result
,
0.01
));
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
gpu
_result
,
migraphx
::
verify
::
expected
{
ref
_result
}
,
0.01
));
else
EXPECT
(
migraphx
::
verify
::
verify_range
(
ref_result
,
gpu_result
));
}
...
...
test/quantization.cpp
View file @
78b8f79b
...
...
@@ -1077,7 +1077,8 @@ TEST_CASE(int8_quantization_dot)
std
::
vector
<
float
>
no_quant_result
;
run_prog
(
p
,
ref_t
,
m
,
no_quant_result
);
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
quant_result
,
no_quant_result
,
0.003
));
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
quant_result
,
migraphx
::
verify
::
expected
{
no_quant_result
},
0.003
));
}
}
...
...
test/ref/multinomial.cpp
View file @
78b8f79b
...
...
@@ -78,5 +78,6 @@ TEST_CASE(multinomial_test)
std
::
transform
(
res_dist
.
begin
(),
res_dist
.
end
(),
res_norm
.
begin
(),
[
&
](
auto
n
)
{
return
static_cast
<
double
>
(
n
)
/
res_dist_sum
;
});
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
norm
,
res_norm
,
0.01
));
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
res_norm
,
migraphx
::
verify
::
expected
{
norm
},
0.01
));
}
test/ref/random_uniform.cpp
View file @
78b8f79b
...
...
@@ -68,7 +68,8 @@ TEST_CASE(random_uniform_test)
std
::
uniform_real_distribution
<>
dis
(
0.0
,
1.0
);
std
::
vector
<
float
>
rand_samples
(
sample_size
);
std
::
generate
(
rand_samples
.
begin
(),
rand_samples
.
end
(),
[
&
]()
{
return
dis
(
gen
);
});
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
result_vec
,
rand_samples
,
0.00001
));
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
result_vec
,
migraphx
::
verify
::
expected
{
rand_samples
},
0.00001
));
}
TEST_CASE
(
random_uniform_int_test
)
...
...
test/ref/rnn_ops.cpp
View file @
78b8f79b
...
...
@@ -1008,7 +1008,7 @@ TEST_CASE(rnn_fp16)
std
::
vector
<
float
>
last_output_data_gold
{
0.2935145
,
-
0.23719997
,
-
0.31123261
,
-
0.18357255
,
0.
,
0.
,
0.
,
0.
};
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
last_output_data
,
last_output_data_gold
,
0.005
));
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
last_output_data
,
migraphx
::
verify
::
expected
{
last_output_data_gold
}
,
0.005
));
}
TEST_CASE
(
gru_forward
)
...
...
@@ -2983,7 +2983,7 @@ TEST_CASE(gru_fp16)
-
0.3969709
,
0.43360898
,
0.35775262
,
0.23280787
,
-
0.52179873
,
-
0.21944991
,
0.4535257
,
-
0.13735442
,
0.51757574
,
0.50380427
};
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
hs_data
,
hs_data_gold
,
0.005
));
EXPECT
(
migraphx
::
verify
::
verify_range_with_threshold
(
hs_data
,
migraphx
::
verify
::
expected
{
hs_data_gold
}
,
0.005
));
}
TEST_CASE
(
lstm_forward
)
...
...
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