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
10432892
Commit
10432892
authored
Aug 17, 2023
by
Brian Pickrell
Browse files
changed rand_uniform op. to random_uniform, and other requested changes
parent
d88ca899
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
48 deletions
+40
-48
src/CMakeLists.txt
src/CMakeLists.txt
+1
-1
src/include/migraphx/op/random_seed.hpp
src/include/migraphx/op/random_seed.hpp
+5
-8
src/include/migraphx/op/random_uniform.hpp
src/include/migraphx/op/random_uniform.hpp
+16
-21
test/op_shape_test.cpp
test/op_shape_test.cpp
+4
-4
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+14
-14
No files found.
src/CMakeLists.txt
View file @
10432892
...
...
@@ -183,7 +183,7 @@ register_migraphx_ops(
quant_convolution
quant_dot
quantizelinear
rand_uniform
rand
om
_uniform
random_seed
recip
reduce_max
...
...
src/include/migraphx/op/random_seed.hpp
View file @
10432892
...
...
@@ -43,7 +43,7 @@ namespace op {
*/
struct
random_seed
{
shape
::
type_t
dtype
=
shape
::
type_t
::
uint
32
_type
;
shape
::
type_t
dtype
=
shape
::
type_t
::
uint
64
_type
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
...
...
@@ -54,19 +54,16 @@ struct random_seed
std
::
string
name
()
const
{
return
"random_seed"
;
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
(
void
)
inputs
;
return
migraphx
::
shape
(
dtype
,
{
1
})
;
check_shapes
{
inputs
,
*
this
}.
has
(
0
)
;
return
shape
{
dtype
}
;
}
argument
compute
(
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
args
)
const
argument
compute
(
const
shape
&
output_shape
,
const
std
::
vector
<
argument
>&
)
const
{
(
void
)
args
;
argument
result
(
output_shape
);
result
.
visit
([
&
](
auto
output
)
{
std
::
generate
(
output
.
begin
(),
output
.
end
(),
[
&
]()
{
return
uint32_t
(
std
::
chrono
::
system_clock
::
now
().
time_since_epoch
().
count
());
});
output
.
front
()
=
std
::
random_device
{}();
});
return
result
;
}
...
...
src/include/migraphx/op/rand_uniform.hpp
→
src/include/migraphx/op/rand
om
_uniform.hpp
View file @
10432892
...
...
@@ -24,12 +24,12 @@
/**
* Random Uniform distribution operator. Given a shape, populate it with random
* values. Calls to rand_uniform using the same randomization seed will
* values. Calls to rand
om
_uniform using the same randomization seed will
* always generate the same pseudo-random sequence. Seed can
* be given as a runtime argument containing a single value, or a compile-time
* attribute.
*
* Inputs: (1) randomization seed (uint
32
)
* Inputs: (1) randomization seed (uint
64
)
* (2) the shape of the set to be populated.
*
*
...
...
@@ -38,8 +38,8 @@
* Output: Same shape.
*
*/
#ifndef MIGRAPHX_GUARD_OPERATORS_RAND_UNIFORM_HPP
#define MIGRAPHX_GUARD_OPERATORS_RAND_UNIFORM_HPP
#ifndef MIGRAPHX_GUARD_OPERATORS_RAND
OM
_UNIFORM_HPP
#define MIGRAPHX_GUARD_OPERATORS_RAND
OM
_UNIFORM_HPP
#include <migraphx/check_shapes.hpp>
#include <migraphx/argument.hpp>
...
...
@@ -51,53 +51,48 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
rand_uniform
struct
rand
om
_uniform
{
// The rand_uniform operation does not contain a random number generator seed
// The rand
om
_uniform operation does not contain a random number generator seed
// as a member, and expects it to be passed as a runtime input.
// todo: not currently settable
float
range_min
=
0.0
f
;
float
range_max
=
1.0
f
;
// todo: integer data type(s) not yet supported
shape
::
type_t
dtype
=
shape
::
type_t
::
float_type
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
dtype
,
"dtype
"
));
return
pack
(
f
(
self
.
range_min
,
"range_min"
),
f
(
self
.
range_max
,
"range_max
"
));
}
/**
* Input 1: seed
* Input 2: output shape
*/
std
::
string
name
()
const
{
return
"rand_uniform"
;
}
std
::
string
name
()
const
{
return
"rand
om
_uniform"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
,
*
this
,
true
}.
has
(
2
);
if
(
inputs
.
front
().
type
()
!=
shape
::
type_t
::
uint
32
_type
)
MIGRAPHX_THROW
(
"RAND_UNIFORM: Input
2
(seed) must have type unsigned int"
);
if
(
inputs
.
front
().
type
()
!=
shape
::
type_t
::
uint
64
_type
)
MIGRAPHX_THROW
(
"RAND
OM
_UNIFORM: Input
1
(seed) must have type
long
unsigned int"
);
auto
s
=
inputs
.
at
(
1
);
if
(
s
.
dynamic
())
{
return
s
.
with_type
(
dtype
)
;
return
s
;
}
else
{
return
s
.
with_lens
(
s
.
lens
())
.
with_type
(
dtype
)
;
return
s
.
with_lens
(
s
.
lens
());
}
}
argument
compute
(
const
shape
&
output
,
std
::
vector
<
argument
>
args
)
const
argument
compute
(
const
shape
&
,
std
::
vector
<
argument
>
args
)
const
{
// Output goes into the passed buffer, not the shape output
(
void
)
output
;
argument
result
{
args
[
1
].
get_shape
()};
// Output goes into the passed buffer, not the shape output.
argument
result
=
args
[
1
];
uint
32
_t
local_seed
=
args
[
0
].
at
<
uint
32
_t
>
(
0
);
uint
64
_t
local_seed
=
args
[
0
].
at
<
uint
64
_t
>
(
0
);
std
::
mt19937
gen
(
local_seed
);
std
::
uniform_real_distribution
<>
dis
(
range_min
,
range_max
);
...
...
test/op_shape_test.cpp
View file @
10432892
...
...
@@ -2216,17 +2216,17 @@ TEST_CASE(prefix_scan_sum_dyn_2d)
}
}
TEST_CASE
(
rand_uniform
)
TEST_CASE
(
rand
om
_uniform
)
{
std
::
vector
<
migraphx
::
shape
::
dynamic_dimension
>
dd
{{
5
,
8
},
{
3
,
7
}};
migraphx
::
shape
s0
{
migraphx
::
shape
::
uint
32
_type
,
{
1
}};
migraphx
::
shape
s0
{
migraphx
::
shape
::
uint
64
_type
,
{
1
}};
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
dd
};
expect_shape
(
s1
,
migraphx
::
make_op
(
"rand_uniform"
),
s0
,
s1
);
expect_shape
(
s1
,
migraphx
::
make_op
(
"rand
om
_uniform"
),
s0
,
s1
);
}
TEST_CASE
(
random_seed
)
{
migraphx
::
shape
s
{
migraphx
::
shape
::
uint
32
_type
,
{
1
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
uint
64
_type
,
{
1
}};
expect_shape
(
s
,
migraphx
::
make_op
(
"random_seed"
));
}
...
...
test/ref_ops_test.cpp
View file @
10432892
...
...
@@ -6458,11 +6458,11 @@ TEST_CASE(quantizelinear)
}
}
TEST_CASE(rand_uniform_test)
TEST_CASE(rand
om
_uniform_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
uint
32
_t seed(0);
uint
64
_t seed(0);
size_t sample_size(200);
// Shape of the random data
...
...
@@ -6473,11 +6473,11 @@ TEST_CASE(rand_uniform_test)
auto input = mm->add_literal(migraphx::literal(rs, data));
// Runtime randomization seed
migraphx::shape seed_shape{migraphx::shape::uint
32
_type, {1}};
std::vector<uint
32
_t> seed_data{seed};
migraphx::shape seed_shape{migraphx::shape::uint
64
_type, {1}};
std::vector<uint
64
_t> seed_data{seed};
auto seed_input = mm->add_literal(migraphx::literal(seed_shape, seed_data));
mm->add_instruction(migraphx::make_op("rand_uniform"), seed_input, input);
mm->add_instruction(migraphx::make_op("rand
om
_uniform"), seed_input, input);
p.compile(migraphx::make_target("ref"));
migraphx::parameter_map params0;
...
...
@@ -6493,11 +6493,11 @@ TEST_CASE(rand_uniform_test)
EXPECT(migraphx::verify::verify_range(result_vec, rand_samples, 100000));
}
TEST_CASE(rand_uniform_dyn_test)
TEST_CASE(rand
om
_uniform_dyn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
uint
32
_t seed(17);
uint
64
_t seed(17);
size_t sample_size(200);
// Shape of the random data
...
...
@@ -6505,10 +6505,10 @@ TEST_CASE(rand_uniform_dyn_test)
auto input = mm->add_parameter("Input_1", rs);
// Runtime randomization seed
migraphx::shape seed_shape{migraphx::shape::uint
32
_type, {1}};
migraphx::shape seed_shape{migraphx::shape::uint
64
_type, {1}};
auto seed_input = mm->add_parameter("Seed", seed_shape);
mm->add_instruction(migraphx::make_op("rand_uniform", {}), seed_input, input);
mm->add_instruction(migraphx::make_op("rand
om
_uniform", {}), seed_input, input);
p.compile(migraphx::make_target("ref"));
// Create a dummy input to hold the random data
...
...
@@ -6516,9 +6516,9 @@ TEST_CASE(rand_uniform_dyn_test)
migraphx::parameter_map params0;
params0["Input_1"] = migraphx::argument(input_fixed_shape1);
migraphx::shape seed_fixed_shape{migraphx::shape::uint
32
_type, {1}};
std::vector<uint
32
_t> seed_data = {seed};
params0["Seed"] = migraphx::argument(seed_
fixed_
shape, seed_data.data());
//
migraphx::shape seed_fixed_shape{migraphx::shape::uint
64
_type, {1}};
std::vector<uint
64
_t> seed_data = {seed};
params0["Seed"] = migraphx::argument(seed_shape, seed_data.data());
auto result = p.eval(params0).back();
std::vector<float> result_vec(sample_size);
...
...
@@ -6532,7 +6532,7 @@ TEST_CASE(rand_uniform_dyn_test)
EXPECT(migraphx::verify::verify_range(result_vec, rand_samples, 100000));
}
TEST_CASE(rand_uniform_and_seed_test)
TEST_CASE(rand
om
_uniform_and_seed_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
...
...
@@ -6546,7 +6546,7 @@ TEST_CASE(rand_uniform_and_seed_test)
// Runtime randomization seed
auto seed_input = mm->add_instruction(migraphx::make_op("random_seed"));
mm->add_instruction(migraphx::make_op("rand_uniform"), seed_input, input);
mm->add_instruction(migraphx::make_op("rand
om
_uniform"), seed_input, input);
p.compile(migraphx::make_target("ref"));
// Create a dummy input to hold the random data
...
...
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