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
3a474fca
"docs/zh_CN/NAS/QuickStart.md" did not exist on "06123ed8ea4aee20ef131ab0bd52d0735147c36f"
Commit
3a474fca
authored
Oct 04, 2021
by
Khalique Ahmed
Browse files
Merge branch 'develop' of
https://github.com/ROCmSoftwarePlatform/AMDMIGraphX
into mi100_opts
parents
d9568511
0b7672d7
Changes
44
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
0 deletions
+118
-0
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+51
-0
test/verify/test_layernorm.cpp
test/verify/test_layernorm.cpp
+17
-0
test/verify/test_multinomial.cpp
test/verify/test_multinomial.cpp
+37
-0
test/verify/test_reduce_op_large.cpp
test/verify/test_reduce_op_large.cpp
+13
-0
No files found.
test/ref_ops_test.cpp
View file @
3a474fca
#include <iostream>
#include <vector>
#include <cmath>
#include <random>
#include <migraphx/literal.hpp>
#include <migraphx/op/pooling.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
...
...
@@ -2687,6 +2688,56 @@ TEST_CASE(mul_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
multinomial_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
size_t
sample_size
=
100000
;
float
seed
=
0.0
f
;
std
::
mt19937
gen
(
seed
);
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
);
});
migraphx
::
shape
rs
{
migraphx
::
shape
::
float_type
,
{
1
,
sample_size
}};
auto
rs_lit
=
mm
->
add_literal
(
migraphx
::
literal
{
rs
,
rand_samples
});
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
,
5
}};
std
::
vector
<
int
>
dist
{
15
,
25
,
15
,
25
,
20
};
std
::
vector
<
float
>
data
(
5
);
std
::
transform
(
dist
.
begin
(),
dist
.
end
(),
data
.
begin
(),
[
&
](
auto
d
)
{
return
std
::
log
(
d
);
});
auto
input
=
mm
->
add_literal
(
migraphx
::
literal
(
s
,
data
));
auto
maxes
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"reduce_max"
,
{{
"axes"
,
{
1
}}}),
input
);
auto
mb_maxes
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
5
}}}),
maxes
);
auto
cdf
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"sub"
),
input
,
mb_maxes
);
cdf
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"exp"
),
cdf
);
cdf
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"prefix_scan_sum"
,
{{
"axis"
,
1
},
{
"exclusive"
,
false
}}),
cdf
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"multinomial"
),
cdf
,
rs_lit
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
int32_t
>
result_vec
(
sample_size
);
result
.
visit
([
&
](
auto
output
)
{
result_vec
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
int
>
res_dist
(
5
,
0
);
for
(
auto
&
r
:
result_vec
)
res_dist
[
r
]
++
;
auto
dist_sum
=
std
::
accumulate
(
dist
.
begin
(),
dist
.
end
(),
0
);
auto
res_dist_sum
=
std
::
accumulate
(
res_dist
.
begin
(),
res_dist
.
end
(),
0
);
std
::
vector
<
float
>
norm
(
5
);
std
::
vector
<
float
>
res_norm
(
5
);
std
::
transform
(
dist
.
begin
(),
dist
.
end
(),
norm
.
begin
(),
[
&
](
auto
n
)
{
return
static_cast
<
double
>
(
n
)
/
dist_sum
;
});
std
::
transform
(
res_dist
.
begin
(),
res_dist
.
end
(),
res_norm
.
begin
(),
[
&
](
auto
n
)
{
return
static_cast
<
double
>
(
n
)
/
res_dist_sum
;
});
EXPECT
(
migraphx
::
verify_range
(
norm
,
res_norm
,
100000
));
}
TEST_CASE
(
neg_test
)
{
migraphx
::
program
p
;
...
...
test/verify/test_layernorm.cpp
View file @
3a474fca
...
...
@@ -81,3 +81,20 @@ struct test_layernorm_triadd : verify_program<test_layernorm_triadd>
return
p
;
}
};
struct
test_layernorm_triadd_large
:
verify_program
<
test_layernorm_triadd_large
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
std
::
vector
<
size_t
>
dims
=
{
1
,
384
,
1024
};
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
dims
});
auto
y
=
mm
->
add_parameter
(
"y"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
dims
});
auto
z
=
mm
->
add_parameter
(
"z"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
dims
});
auto
add1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
x
,
y
);
auto
add2
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
add1
,
z
);
add_layernorm
(
*
mm
,
add2
,
dims
);
return
p
;
}
};
test/verify/test_multinomial.cpp
0 → 100644
View file @
3a474fca
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_multinomial
:
verify_program
<
test_multinomial
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
size_t
sample_size
=
10
;
size_t
batch_size
=
2
;
float
seed
=
0.0
f
;
std
::
mt19937
gen
(
seed
);
std
::
uniform_real_distribution
<>
dis
(
0.0
,
1.0
);
std
::
vector
<
float
>
rand_samples
(
batch_size
*
sample_size
);
std
::
generate
(
rand_samples
.
begin
(),
rand_samples
.
end
(),
[
&
]()
{
return
dis
(
gen
);
});
migraphx
::
shape
rs
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
sample_size
}};
auto
rs_lit
=
mm
->
add_literal
(
migraphx
::
literal
{
rs
,
rand_samples
});
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
batch_size
,
5
}};
auto
input
=
mm
->
add_parameter
(
"input"
,
s
);
auto
maxes
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"reduce_max"
,
{{
"axes"
,
{
1
}}}),
input
);
auto
mb_maxes
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
batch_size
,
5
}}}),
maxes
);
auto
cdf
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"sub"
),
input
,
mb_maxes
);
cdf
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"exp"
),
cdf
);
cdf
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"prefix_scan_sum"
,
{{
"axis"
,
1
},
{
"exclusive"
,
false
}}),
cdf
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"multinomial"
),
cdf
,
rs_lit
);
return
p
;
}
};
test/verify/test_reduce_op_large.cpp
View file @
3a474fca
...
...
@@ -27,3 +27,16 @@ template struct test_reduce_op_large<migraphx::op::reduce_mean, 1, migraphx::sha
template
struct
test_reduce_op_large
<
migraphx
::
op
::
reduce_min
,
1
,
migraphx
::
shape
::
float_type
>;
template
struct
test_reduce_op_large
<
migraphx
::
op
::
reduce_prod
,
2
,
migraphx
::
shape
::
float_type
>;
template
struct
test_reduce_op_large
<
migraphx
::
op
::
reduce_sum
,
1
,
migraphx
::
shape
::
float_type
>;
struct
test_reduce_mean
:
verify_program
<
test_reduce_mean
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
,
384
,
1024
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
mm
->
add_instruction
(
migraphx
::
op
::
reduce_mean
{{
1
}},
x
);
return
p
;
};
};
Prev
1
2
3
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