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
2c8ba41a
Commit
2c8ba41a
authored
Nov 09, 2023
by
charlie
Browse files
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX into simplify_dyn_reshape
parents
5d998fb2
6dc96db7
Changes
47
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
186 additions
and
21 deletions
+186
-21
test/ref/nearbyint.cpp
test/ref/nearbyint.cpp
+43
-11
test/ref/quantizelinear.cpp
test/ref/quantizelinear.cpp
+2
-2
test/ref/reshape.cpp
test/ref/reshape.cpp
+0
-1
test/simplify_dyn_ops_test.cpp
test/simplify_dyn_ops_test.cpp
+82
-0
test/simplify_reshapes_test.cpp
test/simplify_reshapes_test.cpp
+2
-2
test/verify/gemm_2args_mm_8.cpp
test/verify/gemm_2args_mm_8.cpp
+10
-5
test/verify/test_nearbyint.cpp
test/verify/test_nearbyint.cpp
+47
-0
No files found.
test/ref/
round
.cpp
→
test/ref/
nearbyint
.cpp
View file @
2c8ba41a
...
@@ -30,39 +30,71 @@
...
@@ -30,39 +30,71 @@
#include <test.hpp>
#include <test.hpp>
TEST_CASE
(
round
_test
)
TEST_CASE
(
nearbyint
_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
9
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
4
,
4
}};
auto
l
=
auto
l
=
mm
->
add_literal
(
migraphx
::
literal
{
s
,
mm
->
add_literal
(
migraphx
::
literal
{
s
,
{
1.1
,
1.5
,
1.6
,
-
1.1
,
-
1.5
,
-
1.6
,
0.0
,
2.0
,
-
2.0
}});
{
-
3.51
,
mm
->
add_instruction
(
migraphx
::
make_op
(
"round"
),
l
);
-
3.5
,
-
3.49
,
-
2.51
,
-
2.50
,
-
2.49
,
-
1.6
,
-
1.5
,
-
0.51
,
-
0.5
,
0.5
,
0.6
,
2.4
,
2.5
,
3.5
,
4.5
}});
mm
->
add_instruction
(
migraphx
::
make_op
(
"nearbyint"
),
l
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
auto
result
=
p
.
eval
({}).
back
();
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
1.0
,
2.0
,
2.0
,
-
1.0
,
-
2.0
,
-
2.0
,
0.0
,
2.0
,
-
2.0
};
std
::
vector
<
float
>
gold
=
{
-
4.0
,
-
4.0
,
-
3.0
,
-
3.0
,
-
2.0
,
-
2.0
,
-
2.0
,
-
2.0
,
-
1.0
,
0.0
,
0.0
,
1.0
,
2.0
,
2.0
,
4.0
,
4.0
};
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
round
_dyn_test
)
TEST_CASE
(
nearbyint
_dyn_test
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
4
,
10
};
migraphx
::
shape
::
dynamic_dimension
dd
{
4
,
10
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"
round
"
),
input
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"
nearbyint
"
),
input
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
std
::
vector
<
float
>
input_data
{
1.1
,
1.5
,
1.6
,
-
1.1
,
-
1.5
,
-
1.6
,
0.0
,
2.0
,
-
2.0
};
std
::
vector
<
float
>
input_data
{
-
3.51
,
-
3.5
,
-
3.49
,
-
2.51
,
-
2.50
,
-
2.49
,
-
1.6
,
-
1.5
,
-
0.51
,
-
0.5
,
0.5
,
0.6
,
2.4
,
2.5
,
3.5
,
4.5
};
migraphx
::
parameter_map
params0
;
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
9
}};
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
16
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
;
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
1.0
,
2.0
,
2.0
,
-
1.0
,
-
2.0
,
-
2.0
,
0.0
,
2.0
,
-
2.0
};
std
::
vector
<
float
>
gold
=
{
-
4.0
,
-
4.0
,
-
3.0
,
-
3.0
,
-
2.0
,
-
2.0
,
-
2.0
,
-
2.0
,
-
1.0
,
0.0
,
0.0
,
1.0
,
2.0
,
2.0
,
4.0
,
4.0
};
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
}
test/ref/quantizelinear.cpp
View file @
2c8ba41a
...
@@ -55,7 +55,7 @@ TEST_CASE(quantizelinear_1)
...
@@ -55,7 +55,7 @@ TEST_CASE(quantizelinear_1)
std
::
vector
<
float
>
results_vector
(
18
);
std
::
vector
<
float
>
results_vector
(
18
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
std
::
vector
<
float
>
gold
{
-
128
,
127
,
6
5
,
-
128
,
1
,
1
,
-
1
,
100
,
92
,
-
128
,
127
,
6
5
,
-
128
,
1
,
1
,
-
1
,
100
,
92
};
-
128
,
127
,
6
4
,
-
128
,
1
,
1
,
-
1
,
100
,
92
,
-
128
,
127
,
6
4
,
-
128
,
1
,
1
,
-
1
,
100
,
92
};
EXPECT
(
results_vector
==
gold
);
EXPECT
(
results_vector
==
gold
);
}
}
...
@@ -80,6 +80,6 @@ TEST_CASE(quantizelinear_2)
...
@@ -80,6 +80,6 @@ TEST_CASE(quantizelinear_2)
auto
result
=
p1
.
eval
({}).
back
();
auto
result
=
p1
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
(
18
);
std
::
vector
<
float
>
results_vector
(
18
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
0
,
255
,
6
5
,
0
,
2
,
2
,
0
,
255
,
255
,
0
,
255
,
6
5
,
0
,
2
,
2
,
0
,
255
,
255
};
std
::
vector
<
float
>
gold
{
0
,
255
,
6
4
,
0
,
2
,
2
,
0
,
255
,
255
,
0
,
255
,
6
4
,
0
,
2
,
2
,
0
,
255
,
255
};
EXPECT
(
results_vector
==
gold
);
EXPECT
(
results_vector
==
gold
);
}
}
test/ref/reshape.cpp
View file @
2c8ba41a
...
@@ -226,7 +226,6 @@ TEST_CASE(reshape_2in_test1)
...
@@ -226,7 +226,6 @@ TEST_CASE(reshape_2in_test1)
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
reshape_2in_elements_runtime_error
)
TEST_CASE
(
reshape_2in_elements_runtime_error
)
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
...
...
test/simplify_dyn_ops_test.cpp
View file @
2c8ba41a
...
@@ -237,4 +237,86 @@ TEST_CASE(const_slice_4input)
...
@@ -237,4 +237,86 @@ TEST_CASE(const_slice_4input)
EXPECT
(
m0
==
m1
);
EXPECT
(
m0
==
m1
);
}
}
TEST_CASE
(
static_dimensions_of0
)
{
// dead_code_elimination will get rid of atan
migraphx
::
module
m0
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
4
,
4
}};
auto
input
=
m0
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"end"
,
3
}}),
atan_ins
);
m0
.
add_return
({
dimensions_of_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
4
,
4
}};
m1
.
add_parameter
(
"data"
,
s
);
migraphx
::
shape
lit_shape
{
migraphx
::
shape
::
int64_type
,
{
3
}};
std
::
vector
<
int64_t
>
lit_data
=
{
2
,
4
,
4
};
auto
lit_ins
=
m1
.
add_literal
(
migraphx
::
literal
{
lit_shape
,
lit_data
});
m1
.
add_return
({
lit_ins
});
}
EXPECT
(
m0
==
m1
);
}
TEST_CASE
(
static_dimensions_of1
)
{
// dead_code_elimination will get rid of atan
migraphx
::
module
m0
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
4
},
{
4
,
4
}}};
auto
input
=
m0
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
atan_ins
);
m0
.
add_return
({
dimensions_of_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
4
},
{
4
,
4
}}};
m1
.
add_parameter
(
"data"
,
s
);
migraphx
::
shape
lit_shape
{
migraphx
::
shape
::
int64_type
,
{
2
}};
std
::
vector
<
int64_t
>
lit_data
=
{
4
,
4
};
auto
lit_ins
=
m1
.
add_literal
(
migraphx
::
literal
{
lit_shape
,
lit_data
});
m1
.
add_return
({
lit_ins
});
}
EXPECT
(
m0
==
m1
);
}
// Does nothing because the dynamic_dimensions from start to end
// are not all fixed
TEST_CASE
(
static_dimensions_of_nonfixed
)
{
// dead_code_elimination will get rid of atan
migraphx
::
module
m0
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
8
},
{
4
,
8
}}};
auto
input
=
m0
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m0
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
atan_ins
);
m0
.
add_return
({
dimensions_of_ins
});
}
run_pass
(
m0
);
migraphx
::
module
m1
;
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
{
2
,
4
}},
{
4
,
8
},
{
4
,
8
}}};
auto
input
=
m1
.
add_parameter
(
"data"
,
s
);
auto
atan_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"atan"
),
input
);
auto
dimensions_of_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"dimensions_of"
,
{{
"start"
,
1
},
{
"end"
,
3
}}),
atan_ins
);
m1
.
add_return
({
dimensions_of_ins
});
}
EXPECT
(
m0
==
m1
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/simplify_reshapes_test.cpp
View file @
2c8ba41a
...
@@ -1345,7 +1345,7 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
...
@@ -1345,7 +1345,7 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
auto
cont_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
transpose_ins
);
auto
cont_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
transpose_ins
);
auto
unsq_ins
=
auto
unsq_ins
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
cont_ins
);
m1
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
cont_ins
);
auto
round
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"
round
"
),
unsq_ins
);
auto
round
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"
nearbyint
"
),
unsq_ins
);
m1
.
add_instruction
(
pass_op
{},
round
);
m1
.
add_instruction
(
pass_op
{},
round
);
}
}
run_pass
(
m1
);
run_pass
(
m1
);
...
@@ -1354,7 +1354,7 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
...
@@ -1354,7 +1354,7 @@ TEST_CASE(transpose_contiguous_unsqueeze_unary)
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
2
,
8
,
5
,
5
}});
auto
x
=
m2
.
add_parameter
(
"x"
,
{
migraphx
::
shape
::
float_type
,
{
2
,
8
,
5
,
5
}});
auto
transpose_ins
=
auto
transpose_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
3
,
1
}}}),
x
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
0
,
2
,
3
,
1
}}}),
x
);
auto
round
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"
round
"
),
transpose_ins
);
auto
round
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"
nearbyint
"
),
transpose_ins
);
auto
cont_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
round
);
auto
cont_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
round
);
auto
unsq_ins
=
auto
unsq_ins
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
cont_ins
);
m2
.
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
cont_ins
);
...
...
test/verify/
test_round
.cpp
→
test/verify/
gemm_2args_mm_8
.cpp
View file @
2c8ba41a
...
@@ -27,16 +27,21 @@
...
@@ -27,16 +27,21 @@
#include <migraphx/generate.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/make_op.hpp>
struct
test_round
:
verify_program
<
test_round
>
struct
gemm_2args_mm_8
:
verify_program
<
gemm_2args_mm_8
>
{
{
migraphx
::
program
create_program
()
const
migraphx
::
program
create_program
()
const
{
{
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
a_shape
{
migraphx
::
shape
::
float_type
,
{
2
,
128
,
32
},
{
4096
,
1
,
128
}};
migraphx
::
shape
b_shape
{
migraphx
::
shape
::
float_type
,
{
32
,
32
}};
auto
a
=
mm
->
add_parameter
(
"a"
,
a_shape
);
auto
b
=
mm
->
add_parameter
(
"b"
,
b_shape
);
auto
bb
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
2
,
32
,
32
}}}),
b
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"dot"
),
a
,
bb
);
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
6
}};
auto
param
=
mm
->
add_parameter
(
"x"
,
s
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"round"
),
param
);
return
p
;
return
p
;
}
;
}
};
};
test/verify/test_nearbyint.cpp
0 → 100644
View file @
2c8ba41a
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
template
<
class
T
>
struct
test_nearbyint
:
verify_program
<
test_nearbyint
<
T
>>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
std
::
vector
<
float
>
tmp
{
-
4.5
,
-
3.5
,
0.5
,
2.5
,
3.5
};
std
::
vector
<
T
>
data
{
tmp
.
cbegin
(),
tmp
.
cend
()};
migraphx
::
shape
s1
{
migraphx
::
shape
::
get_type
<
T
>
(),
{
5
}};
auto
*
mm
=
p
.
get_main_module
();
auto
l0
=
mm
->
add_literal
(
migraphx
::
literal
{
s1
,
data
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"isinf"
),
l0
);
return
p
;
};
};
template
struct
test_nearbyint
<
migraphx
::
half
>;
template
struct
test_nearbyint
<
float
>;
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