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
d7b1895a
Commit
d7b1895a
authored
Jul 07, 2023
by
Khalique Ahmed
Browse files
Merge branch 'develop' of
https://github.com/ROCmSoftwarePlatform/AMDMIGraphX
into nhwc_workaround
parents
1add453a
a83371ca
Changes
62
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
432 additions
and
96 deletions
+432
-96
src/targets/gpu/kernels/include/migraphx/kernels/ck_gemm.hpp
src/targets/gpu/kernels/include/migraphx/kernels/ck_gemm.hpp
+1
-1
src/targets/gpu/lowering.cpp
src/targets/gpu/lowering.cpp
+17
-12
test/api/test_c_op_construct.c
test/api/test_c_op_construct.c
+1
-1
test/dead_code_elimination_test.cpp
test/dead_code_elimination_test.cpp
+27
-15
test/eliminate_identity_test.cpp
test/eliminate_identity_test.cpp
+4
-4
test/eval_test.cpp
test/eval_test.cpp
+33
-32
test/gpu/codegen_literal.cpp
test/gpu/codegen_literal.cpp
+86
-0
test/include/basic_ops.hpp
test/include/basic_ops.hpp
+35
-3
test/literal_test.cpp
test/literal_test.cpp
+6
-0
test/onnx/clip_dyn_min_max_test.onnx
test/onnx/clip_dyn_min_max_test.onnx
+0
-0
test/onnx/clip_dyn_min_only_test.onnx
test/onnx/clip_dyn_min_only_test.onnx
+0
-0
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+27
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+41
-0
test/propagate_constant_test.cpp
test/propagate_constant_test.cpp
+12
-12
test/quantization.cpp
test/quantization.cpp
+14
-10
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+26
-1
test/validate.cpp
test/validate.cpp
+5
-4
test/verify/gemm_add_broadcast_half.cpp
test/verify/gemm_add_broadcast_half.cpp
+49
-0
test/verify/gemm_add_half.cpp
test/verify/gemm_add_half.cpp
+47
-0
test/verify/run_verify.cpp
test/verify/run_verify.cpp
+1
-1
No files found.
src/targets/gpu/kernels/include/migraphx/kernels/ck_gemm.hpp
View file @
d7b1895a
...
...
@@ -52,7 +52,7 @@ __device__ void ck_gemm_matrix(E e, A a, B b, Ds... ds)
ck
::
make_tuple
(
to_ck_tensor
<
Ds
>
()...),
to_ck_tensor
<
E
>
());
static_assert
(
desc
.
is_v
alid
,
"Invalid ck gemm."
);
static_assert
(
desc
.
IsV
alid
()
,
"Invalid ck gemm."
);
G
::
Run
(
desc
,
to_ck_const_pointer
(
a
.
data
()),
...
...
src/targets/gpu/lowering.cpp
View file @
d7b1895a
...
...
@@ -22,12 +22,19 @@
* THE SOFTWARE.
*/
#include <iterator>
#include <migraphx/gpu/lowering.hpp>
#include <utility>
#include <functional>
#include <algorithm>
#include <map>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction_ref.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/program.hpp>
#include <migraphx/op/dot.hpp>
#include <migraphx/op/if_op.hpp>
...
...
@@ -35,17 +42,12 @@
#include <migraphx/op/quant_dot.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/gpu/device_name.hpp>
#include <migraphx/gpu/gemm.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <migraphx/gpu/rocblas.hpp>
#include <migraphx/gpu/compiler.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/program.hpp>
#include <utility>
#include <functional>
#include <algorithm>
#include <map>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
...
@@ -53,8 +55,9 @@ namespace gpu {
struct
miopen_apply
{
module
*
mod
=
nullptr
;
const
lowering
*
pass
=
nullptr
;
module
*
mod
=
nullptr
;
module_pass_manager
*
mpm
=
nullptr
;
const
lowering
*
pass
=
nullptr
;
std
::
unordered_map
<
std
::
string
,
std
::
function
<
instruction_ref
(
instruction_ref
)
>>
apply_map
{};
instruction_ref
last
{};
bool
offload_copy
=
false
;
...
...
@@ -83,8 +86,7 @@ struct miopen_apply
auto
&
ctx
=
get_context
();
int8_x4_format
=
get_int8_x4_format
(
ctx
);
compute_fp32
=
get_compute_fp32_flag
();
// TODO: Set Offload copy based on root modules' compile options
offload_copy
=
(
mod
->
name
()
==
"main"
)
?
pass
->
offload_copy
:
false
;
offload_copy
=
(
mod
==
mpm
->
get_root_module
())
?
pass
->
offload_copy
:
false
;
add_generic_op
(
"contiguous"
);
...
...
@@ -376,7 +378,10 @@ struct miopen_apply
}
};
void
lowering
::
apply
(
module
&
m
)
const
{
miopen_apply
{
&
m
,
this
}.
apply
();
}
void
lowering
::
apply
(
module_pass_manager
&
mpm
)
const
{
miopen_apply
{
&
mpm
.
get_module
(),
&
mpm
,
this
}.
apply
();
}
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
...
...
test/api/test_c_op_construct.c
View file @
d7b1895a
...
...
@@ -30,7 +30,7 @@ void expect_equal(const char* x, const char* y)
abort
();
}
int
main
()
int
main
(
void
)
{
char
name
[
1024
];
migraphx_operation_t
op
;
...
...
test/dead_code_elimination_test.cpp
View file @
d7b1895a
...
...
@@ -41,7 +41,7 @@ TEST_CASE(simple_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
count
);
...
...
@@ -57,7 +57,7 @@ TEST_CASE(simple_test_nop)
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
nop
{});
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
count
);
...
...
@@ -73,7 +73,7 @@ TEST_CASE(simple_test_nop2)
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
nop
{});
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
nop
{});
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
2
);
...
...
@@ -88,8 +88,8 @@ TEST_CASE(duplicate_test1)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
(
count
-
1
));
...
...
@@ -104,9 +104,9 @@ TEST_CASE(duplicate_test2)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
mi
nus_op
{}
,
one
,
two
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
mi
graphx
::
make_op
(
"sub"
)
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
(
count
-
2
));
...
...
@@ -121,11 +121,11 @@ TEST_CASE(depth_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
x1
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
x2
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
mi
nus_op
{}
,
x1
,
x2
);
mm
->
add_instruction
(
mi
nus_op
{}
,
x1
,
x2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
x1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
x2
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
mi
graphx
::
make_op
(
"sub"
)
,
x1
,
x2
);
mm
->
add_instruction
(
mi
graphx
::
make_op
(
"sub"
)
,
x1
,
x2
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
(
count
-
4
));
...
...
@@ -141,7 +141,7 @@ TEST_CASE(undefined_test)
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"undefined"
));
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
count
-
1
);
...
...
@@ -232,7 +232,6 @@ TEST_CASE(reused_twice)
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
p
.
debug_print
();
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
!=
count
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
4
);
}
...
...
@@ -274,4 +273,17 @@ TEST_CASE(param_not_eliminated)
EXPECT
(
p
==
create_program
());
}
TEST_CASE
(
tuple_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
tuple_op
{},
one
,
two
);
mm
->
add_return
({
one
,
two
});
auto
count
=
std
::
distance
(
mm
->
begin
(),
mm
->
end
());
run_pass
(
p
);
EXPECT
(
std
::
distance
(
mm
->
begin
(),
mm
->
end
())
==
(
count
-
1
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/eliminate_identity_test.cpp
View file @
d7b1895a
...
...
@@ -45,7 +45,7 @@ TEST_CASE(simple_test)
auto
one_identity
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
one
);
auto
two
=
mm
->
add_literal
(
2
);
auto
two_identity
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
two
);
mm
->
add_instruction
(
sum_op
{}
,
one_identity
,
two_identity
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one_identity
,
two_identity
);
run_pass
(
p
);
EXPECT
(
std
::
none_of
(
mm
->
begin
(),
mm
->
end
(),
[](
const
migraphx
::
instruction
&
ins
)
{
return
ins
.
name
()
==
"identity"
;
...
...
@@ -62,7 +62,7 @@ TEST_CASE(simple_test_end)
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
ans
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
ans
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
ans
);
run_pass
(
p
);
EXPECT
(
std
::
none_of
(
mm
->
begin
(),
mm
->
end
(),
[](
const
migraphx
::
instruction
&
ins
)
{
...
...
@@ -81,8 +81,8 @@ TEST_CASE(simple_test_end_dependency)
auto
one
=
mm
->
add_literal
(
1.0
);
auto
two
=
mm
->
add_literal
(
2.0
);
auto
three
=
mm
->
add_literal
(
3.0
);
auto
ans
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
sum_op
{}
,
ans
,
three
);
auto
ans
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
ans
,
three
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
ans
);
run_pass
(
p
);
EXPECT
(
std
::
any_of
(
mm
->
begin
(),
mm
->
end
(),
[](
const
migraphx
::
instruction
&
ins
)
{
...
...
test/eval_test.cpp
View file @
d7b1895a
...
...
@@ -27,6 +27,7 @@
#include <migraphx/instruction.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/compile_options.hpp>
#include <migraphx/make_op.hpp>
#include <sstream>
#include "test.hpp"
#include <basic_ops.hpp>
...
...
@@ -49,7 +50,7 @@ struct id_target
struct
id_ctx_op
{
std
::
string
name
()
const
{
return
"
id_ctx_op
"
;
}
std
::
string
name
()
const
{
return
""
;
}
migraphx
::
argument
compute
(
id_target
::
context
&
,
const
migraphx
::
shape
&
,
std
::
vector
<
migraphx
::
argument
>
args
)
const
{
...
...
@@ -156,7 +157,7 @@ TEST_CASE(literal_test1)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
result
=
p
.
eval
({}).
back
();
EXPECT
(
result
==
migraphx
::
literal
{
3
});
EXPECT
(
result
!=
migraphx
::
literal
{
4
});
...
...
@@ -168,8 +169,8 @@ TEST_CASE(literal_test2)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum1
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
sum_op
{}
,
sum1
,
two
);
auto
sum1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
sum1
,
two
);
auto
result
=
p
.
eval
({}).
back
();
EXPECT
(
result
==
migraphx
::
literal
{
5
});
...
...
@@ -182,7 +183,7 @@ TEST_CASE(print_test)
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
});
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
x
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
x
,
two
);
std
::
stringstream
ss
;
ss
<<
p
;
...
...
@@ -197,7 +198,7 @@ TEST_CASE(param_test)
auto
x
=
mm
->
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
});
auto
y
=
mm
->
add_parameter
(
"y"
,
{
migraphx
::
shape
::
int32_type
});
mm
->
add_instruction
(
sum_op
{}
,
x
,
y
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
x
,
y
);
auto
result
=
p
.
eval
({{
"x"
,
migraphx
::
literal
{
1
}.
get_argument
()},
{
"y"
,
migraphx
::
literal
{
2
}.
get_argument
()}})
.
back
();
...
...
@@ -227,7 +228,7 @@ TEST_CASE(param_error_shape_test)
auto
x
=
mm
->
add_parameter
(
"x"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
1
}});
auto
y
=
mm
->
add_parameter
(
"y"
,
{
migraphx
::
shape
::
int32_type
,
{
1
,
1
}});
mm
->
add_instruction
(
sum_op
{}
,
x
,
y
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
x
,
y
);
EXPECT
(
test
::
throws
<
migraphx
::
exception
>
(
[
&
]
{
p
.
eval
({
...
...
@@ -245,7 +246,7 @@ TEST_CASE(get_param1)
migraphx
::
shape
s
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
y
=
mm
->
add_parameter
(
"y"
,
s
);
mm
->
add_instruction
(
sum_op
{}
,
x
,
y
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
x
,
y
);
EXPECT
(
bool
{
p
.
get_parameter
(
"x"
)
==
x
});
EXPECT
(
bool
{
p
.
get_parameter
(
"y"
)
==
y
});
EXPECT
(
bool
{
p
.
get_parameter
(
"nonexistent"
)
==
mm
->
end
()});
...
...
@@ -257,7 +258,7 @@ TEST_CASE(get_param2)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
EXPECT
(
bool
{
p
.
get_parameter
(
"nonexistent"
)
==
mm
->
end
()});
}
...
...
@@ -268,7 +269,7 @@ TEST_CASE(get_param_shapes)
migraphx
::
shape
s
{
migraphx
::
shape
::
int32_type
,
{
1
,
2
}};
auto
x
=
mm
->
add_parameter
(
"x"
,
s
);
auto
y
=
mm
->
add_parameter
(
"y"
,
s
);
mm
->
add_instruction
(
sum_op
{}
,
x
,
y
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
x
,
y
);
auto
m
=
p
.
get_parameter_shapes
();
EXPECT
(
m
.
count
(
"nonexistent"
)
==
0
);
EXPECT
(
m
.
at
(
"x"
)
==
s
);
...
...
@@ -281,8 +282,8 @@ TEST_CASE(replace_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
replace_instruction
(
sum
,
mi
nus_op
{}
,
two
,
one
);
auto
sum
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
replace_instruction
(
sum
,
mi
graphx
::
make_op
(
"sub"
)
,
two
,
one
);
EXPECT
(
bool
{
p
.
validate
()
==
mm
->
end
()});
auto
result
=
p
.
eval
({}).
back
();
...
...
@@ -296,8 +297,8 @@ TEST_CASE(replace_ins_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
minus
=
mm
->
add_instruction
(
mi
nus_op
{}
,
two
,
one
);
auto
sum
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
minus
=
mm
->
add_instruction
(
mi
graphx
::
make_op
(
"sub"
)
,
two
,
one
);
mm
->
replace_instruction
(
sum
,
minus
);
EXPECT
(
bool
{
p
.
validate
()
==
mm
->
end
()});
...
...
@@ -312,8 +313,8 @@ TEST_CASE(replace_ins_test2)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
minus
=
mm
->
add_instruction
(
mi
nus_op
{}
,
two
,
one
);
auto
sum
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
minus
=
mm
->
add_instruction
(
mi
graphx
::
make_op
(
"sub"
)
,
two
,
one
);
mm
->
add_instruction
(
pass_op
{},
minus
);
mm
->
replace_instruction
(
two
,
sum
);
EXPECT
(
bool
{
p
.
validate
()
==
mm
->
end
()});
...
...
@@ -329,8 +330,8 @@ TEST_CASE(replace_op_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum
=
mm
->
add_instruction
(
sum_op
{}
,
two
,
one
);
sum
->
replace
(
mi
nus_op
{}
);
auto
sum
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
two
,
one
);
sum
->
replace
(
mi
graphx
::
make_op
(
"sub"
)
);
EXPECT
(
bool
{
p
.
validate
()
==
mm
->
end
()});
auto
result
=
p
.
eval
({}).
back
();
...
...
@@ -344,7 +345,7 @@ TEST_CASE(replace_op_recompute_shape_throw)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
sum
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
EXPECT
(
test
::
throws
<
migraphx
::
exception
>
([
&
]
{
sum
->
replace
(
unary_pass_op
{});
}));
}
...
...
@@ -354,11 +355,11 @@ TEST_CASE(insert_replace_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum1
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
sum_op
{}
,
sum1
,
two
);
auto
sum1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
sum1
,
two
);
auto
sum0
=
mm
->
insert_instruction
(
sum1
,
sum_op
{}
,
two
,
two
);
mm
->
replace_instruction
(
sum1
,
mi
nus_op
{}
,
sum0
,
two
);
auto
sum0
=
mm
->
insert_instruction
(
sum1
,
migraphx
::
make_op
(
"add"
)
,
two
,
two
);
mm
->
replace_instruction
(
sum1
,
mi
graphx
::
make_op
(
"sub"
)
,
sum0
,
two
);
EXPECT
(
bool
{
p
.
validate
()
==
mm
->
end
()});
auto
result
=
p
.
eval
({}).
back
();
...
...
@@ -372,8 +373,8 @@ TEST_CASE(remove_test1)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
sum
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
removed
=
mm
->
add_instruction
(
mi
nus_op
{}
,
sum
,
one
);
auto
sum
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
auto
removed
=
mm
->
add_instruction
(
mi
graphx
::
make_op
(
"sub"
)
,
sum
,
one
);
mm
->
remove_instruction
(
removed
);
EXPECT
(
bool
{
p
.
validate
()
==
mm
->
end
()});
...
...
@@ -388,8 +389,8 @@ TEST_CASE(remove_test2)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
removed
=
mm
->
add_instruction
(
mi
nus_op
{}
,
two
,
one
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
removed
=
mm
->
add_instruction
(
mi
graphx
::
make_op
(
"sub"
)
,
two
,
one
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
remove_instruction
(
removed
);
EXPECT
(
bool
{
p
.
validate
()
==
mm
->
end
()});
...
...
@@ -404,7 +405,7 @@ TEST_CASE(target_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
p
.
compile
(
id_target
{});
auto
result
=
p
.
eval
({}).
back
();
EXPECT
(
result
==
migraphx
::
literal
{
3
});
...
...
@@ -460,7 +461,7 @@ TEST_CASE(eval_context1)
mm
->
add_instruction
(
sum_op
{},
one
,
two
);
p
.
compile
(
t
);
EXPECT
(
is_shared
(
t
.
ctx
,
p
.
get_context
()));
p
.
eval
({}).
back
();
std
::
ignore
=
p
.
eval
({}).
back
();
EXPECT
(
is_shared
(
t
.
ctx
,
p
.
get_context
()));
}
...
...
@@ -475,7 +476,7 @@ TEST_CASE(eval_context2)
mm
->
add_instruction
(
id_ctx_op
{},
one
,
two
);
p
.
compile
(
t
);
EXPECT
(
is_shared
(
t
.
ctx
,
p
.
get_context
()));
p
.
eval
({}).
back
();
std
::
ignore
=
p
.
eval
({}).
back
();
// id_ctx_op will modify the context
EXPECT
(
not
is_shared
(
t
.
ctx
,
p
.
get_context
()));
}
...
...
@@ -492,8 +493,8 @@ TEST_CASE(eval_context3)
p
.
compile
(
t
);
// Finalizer will modify the context
EXPECT
(
not
is_shared
(
t
.
ctx
,
p
.
get_context
()));
auto
ctx
=
p
.
get_context
();
p
.
eval
({}).
back
();
auto
ctx
=
p
.
get_context
();
std
::
ignore
=
p
.
eval
({}).
back
();
EXPECT
(
is_shared
(
ctx
,
p
.
get_context
()));
EXPECT
(
not
is_shared
(
t
.
ctx
,
p
.
get_context
()));
}
...
...
test/gpu/codegen_literal.cpp
0 → 100644
View file @
d7b1895a
/*
* 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 <migraphx/program.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/verify.hpp>
#include <test.hpp>
#include <migraphx/make_op.hpp>
void
run_prog
(
migraphx
::
program
p
,
const
migraphx
::
target
&
t
,
migraphx
::
parameter_map
&
m_in
,
std
::
vector
<
float
>&
res
)
{
p
.
compile
(
t
);
migraphx
::
parameter_map
m
;
for
(
auto
&&
x
:
p
.
get_parameter_shapes
())
{
if
(
m_in
.
count
(
x
.
first
)
>
0
)
{
m
[
x
.
first
]
=
t
.
copy_to
(
m_in
[
x
.
first
]);
}
else
{
m
[
x
.
first
]
=
t
.
allocate
(
x
.
second
);
}
}
auto
result
=
t
.
copy_from
(
p
.
eval
(
m
).
back
());
result
.
visit
([
&
](
auto
v
)
{
res
.
assign
(
v
.
begin
(),
v
.
end
());
});
}
// This test ensures that the codegen path doesn't round up literals,
// otherwise there are accuracy differences compared to ref.
// The values being passed in are 0.5 * (1/0.00787402),
// and after rounding must equal 63, not 64.
TEST_CASE
(
mul_literal_round_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
float_type
,
{
1
}};
auto
l0
=
mm
->
add_parameter
(
"a"
,
s0
);
auto
l1
=
mm
->
add_literal
(
1
/
0.00787402
f
);
auto
mul
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"mul"
),
l0
,
l1
);
auto
round
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"round"
),
mul
);
mm
->
add_return
({
round
});
migraphx
::
parameter_map
m
;
std
::
vector
<
float
>
a
=
{
0.5
f
};
m
[
"a"
]
=
migraphx
::
argument
{
s0
,
a
.
data
()};
std
::
vector
<
float
>
ref_result
;
migraphx
::
target
ref_t
=
migraphx
::
make_target
(
"ref"
);
run_prog
(
p
,
ref_t
,
m
,
ref_result
);
std
::
vector
<
float
>
gpu_result
;
migraphx
::
target
gpu_t
=
migraphx
::
make_target
(
"gpu"
);
run_prog
(
p
,
gpu_t
,
m
,
gpu_result
);
EXPECT
(
migraphx
::
verify_range
(
ref_result
,
gpu_result
));
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/include/basic_ops.hpp
View file @
d7b1895a
...
...
@@ -86,6 +86,25 @@ struct minus_op
};
struct
pass_op
{
std
::
string
name
()
const
{
return
"pass"
;
}
migraphx
::
argument
compute
(
const
migraphx
::
shape
&
,
std
::
vector
<
migraphx
::
argument
>
args
)
const
{
if
(
args
.
empty
())
return
{};
return
args
.
front
();
}
migraphx
::
shape
compute_shape
(
std
::
vector
<
migraphx
::
shape
>
inputs
)
const
{
if
(
inputs
.
empty
())
return
{};
return
inputs
.
front
();
}
int
output_alias
(
const
std
::
vector
<
migraphx
::
shape
>&
s
)
const
{
return
s
.
empty
()
?
-
1
:
0
;
}
};
struct
non_const_pass_op
{
std
::
string
name
()
const
{
return
"pass"
;
}
migraphx
::
argument
...
...
@@ -176,9 +195,7 @@ struct pass_standard_op
struct
nop
{
std
::
string
name
()
const
{
return
"nop"
;
}
migraphx
::
argument
compute
(
migraphx
::
context
&
,
const
migraphx
::
shape
&
,
const
std
::
vector
<
migraphx
::
argument
>&
)
const
migraphx
::
argument
compute
(
const
migraphx
::
shape
&
,
const
std
::
vector
<
migraphx
::
argument
>&
)
const
{
return
{};
}
...
...
@@ -186,6 +203,21 @@ struct nop
migraphx
::
shape
compute_shape
(
const
std
::
vector
<
migraphx
::
shape
>&
)
const
{
return
{};
}
};
struct
tuple_op
{
std
::
string
name
()
const
{
return
"tuple_op"
;
}
migraphx
::
shape
compute_shape
(
const
std
::
vector
<
migraphx
::
shape
>&
inputs
)
const
{
return
{
inputs
};
}
migraphx
::
argument
compute
(
migraphx
::
context
&
,
const
migraphx
::
shape
&
,
const
std
::
vector
<
migraphx
::
argument
>&
input_args
)
const
{
return
input_args
;
}
};
inline
migraphx
::
literal
get_2x2
(
int
base
=
0
)
{
return
migraphx
::
literal
{{
migraphx
::
shape
::
float_type
,
{
2
,
2
}},
...
...
test/literal_test.cpp
View file @
d7b1895a
...
...
@@ -177,4 +177,10 @@ TEST_CASE(value_literal)
EXPECT
(
l4
==
l2
);
}
TEST_CASE
(
literal_to_string_float_precision
)
{
migraphx
::
literal
x
{
126.99993142003703
f
};
EXPECT
(
x
.
to_string
()
!=
"127"
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/onnx/clip_dyn_min_max_test.onnx
0 → 100644
View file @
d7b1895a
File added
test/onnx/clip_dyn_min_only_test.onnx
0 → 100644
View file @
d7b1895a
File added
test/onnx/gen_onnx.py
View file @
d7b1895a
...
...
@@ -743,6 +743,33 @@ def clip_test_args_type_mismatch():
return
([
node
],
[
x
],
[
y
],
[
min_val
,
max_val
])
@
onnx_test
()
def
clip_dyn_min_max_test
():
x
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT
,
[
None
])
y
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
FLOAT
,
[
None
])
min_val
=
helper
.
make_tensor
(
'min'
,
TensorProto
.
FLOAT
,
[],
[
0.0
])
max_val
=
helper
.
make_tensor
(
'max'
,
TensorProto
.
FLOAT
,
[],
[
6.0
])
node
=
onnx
.
helper
.
make_node
(
'Clip'
,
inputs
=
[
'0'
,
'min'
,
'max'
],
outputs
=
[
'1'
])
return
([
node
],
[
x
],
[
y
],
[
min_val
,
max_val
])
@
onnx_test
()
def
clip_dyn_min_only_test
():
x
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT
,
[
None
])
y
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
FLOAT
,
[
None
])
min_val
=
helper
.
make_tensor
(
'min'
,
TensorProto
.
FLOAT
,
[],
[
0.0
])
node
=
onnx
.
helper
.
make_node
(
'Clip'
,
inputs
=
[
'0'
,
'min'
],
outputs
=
[
'1'
])
return
([
node
],
[
x
],
[
y
],
[
min_val
])
@
onnx_test
()
def
concat_test
():
x
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT
,
[
2
,
4
,
3
])
...
...
test/onnx/onnx_test.cpp
View file @
d7b1895a
...
...
@@ -823,6 +823,47 @@ TEST_CASE(clip_test_args_type_mismatch)
EXPECT(p == prog);
}
TEST_CASE(clip_dyn_min_max_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto min_val = mm->add_literal(0.0f);
auto max_val = mm->add_literal(6.0f);
std::vector<migraphx::shape::dynamic_dimension> dds = {{2, 8, {3}}};
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, dds});
min_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_dyn_dims", to_value(dds)}}), min_val, l0);
max_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_dyn_dims", to_value(dds)}}), max_val, l0);
auto ret = mm->add_instruction(migraphx::make_op("clip"), l0, min_val, max_val);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {2, 8, {3}};
auto prog = parse_onnx("clip_dyn_min_max_test.onnx", options);
EXPECT(p == prog);
}
TEST_CASE(clip_dyn_min_only_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto min_val = mm->add_literal(0.0f);
std::vector<migraphx::shape::dynamic_dimension> dds = {{2, 8, {3}}};
auto l0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::float_type, dds});
min_val = mm->add_instruction(
migraphx::make_op("multibroadcast", {{"out_dyn_dims", to_value(dds)}}), min_val, l0);
auto ret = mm->add_instruction(migraphx::make_op("max"), l0, min_val);
mm->add_return({ret});
migraphx::onnx_options options;
options.default_dyn_dim_value = {2, 8, {3}};
auto prog = parse_onnx("clip_dyn_min_only_test.onnx", options);
EXPECT(p == prog);
}
TEST_CASE(concat_test)
{
migraphx::program p;
...
...
test/propagate_constant_test.cpp
View file @
d7b1895a
...
...
@@ -40,12 +40,12 @@ TEST_CASE(const_add)
auto
one
=
m1
.
add_literal
(
1
);
auto
two
=
m1
.
add_literal
(
2
);
auto
sum
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
one
,
two
);
m1
.
add_instruction
(
pass_op
{},
sum
);
m1
.
add_instruction
(
non_const_
pass_op
{},
sum
);
run_pass
(
m1
);
migraphx
::
module
m2
;
auto
total
=
m2
.
add_literal
(
3
);
m2
.
add_instruction
(
pass_op
{},
total
);
m2
.
add_instruction
(
non_const_
pass_op
{},
total
);
EXPECT
(
m1
==
m2
);
}
...
...
@@ -55,12 +55,12 @@ TEST_CASE(const_add_parameter)
auto
one
=
m1
.
add_parameter
(
"one"
,
{
migraphx
::
shape
::
int32_type
,
{
1
}});
auto
two
=
m1
.
add_literal
(
2
);
auto
sum
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
one
,
two
);
m1
.
add_instruction
(
pass_op
{},
sum
);
m1
.
add_instruction
(
non_const_
pass_op
{},
sum
);
run_pass
(
m1
);
migraphx
::
module
m2
;
auto
total
=
m2
.
add_literal
(
3
);
m2
.
add_instruction
(
pass_op
{},
total
);
m2
.
add_instruction
(
non_const_
pass_op
{},
total
);
EXPECT
(
m1
!=
m2
);
}
...
...
@@ -71,12 +71,12 @@ TEST_CASE(const_multiadd)
auto
two
=
m1
.
add_literal
(
2
);
auto
sum1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
one
,
two
);
auto
sum2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
sum1
,
two
);
m1
.
add_instruction
(
pass_op
{},
sum2
);
m1
.
add_instruction
(
non_const_
pass_op
{},
sum2
);
run_pass
(
m1
);
migraphx
::
module
m2
;
auto
total
=
m2
.
add_literal
(
5
);
m2
.
add_instruction
(
pass_op
{},
total
);
m2
.
add_instruction
(
non_const_
pass_op
{},
total
);
EXPECT
(
m1
==
m2
);
}
...
...
@@ -88,12 +88,12 @@ TEST_CASE(const_add_mul)
auto
mul
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"mul"
),
two
,
two
);
auto
sum1
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
one
,
mul
);
auto
sum2
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
sum1
,
two
);
m1
.
add_instruction
(
pass_op
{},
sum2
);
m1
.
add_instruction
(
non_const_
pass_op
{},
sum2
);
run_pass
(
m1
);
migraphx
::
module
m2
;
auto
total
=
m2
.
add_literal
(
7
);
m2
.
add_instruction
(
pass_op
{},
total
);
m2
.
add_instruction
(
non_const_
pass_op
{},
total
);
EXPECT
(
m1
==
m2
);
}
...
...
@@ -105,13 +105,13 @@ TEST_CASE(const_add_scalar)
auto
two
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"scalar"
,
{{
"scalar_bcst_dims"
,
{
2
,
2
}}}),
m1
.
add_literal
(
2
));
auto
sum
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"add"
),
one
,
two
);
m1
.
add_instruction
(
pass_op
{},
sum
);
m1
.
add_instruction
(
non_const_
pass_op
{},
sum
);
run_pass
(
m1
);
migraphx
::
module
m2
;
auto
total
=
m2
.
add_literal
(
migraphx
::
literal
{{
migraphx
::
shape
::
int32_type
,
{
2
,
2
}},
{
3
,
3
,
3
,
3
}});
m2
.
add_instruction
(
pass_op
{},
total
);
m2
.
add_instruction
(
non_const_
pass_op
{},
total
);
EXPECT
(
m1
==
m2
);
}
...
...
@@ -121,7 +121,7 @@ TEST_CASE(const_scalar)
{
auto
one
=
m1
.
add_instruction
(
migraphx
::
make_op
(
"scalar"
,
{{
"scalar_bcst_dims"
,
{
2
,
2
}}}),
m1
.
add_literal
(
1
));
m1
.
add_instruction
(
pass_op
{},
one
);
m1
.
add_instruction
(
non_const_
pass_op
{},
one
);
}
run_pass
(
m1
);
...
...
@@ -129,7 +129,7 @@ TEST_CASE(const_scalar)
{
auto
one
=
m2
.
add_instruction
(
migraphx
::
make_op
(
"scalar"
,
{{
"scalar_bcst_dims"
,
{
2
,
2
}}}),
m2
.
add_literal
(
1
));
m2
.
add_instruction
(
pass_op
{},
one
);
m2
.
add_instruction
(
non_const_
pass_op
{},
one
);
}
EXPECT
(
m1
==
m2
);
}
...
...
test/quantization.cpp
View file @
d7b1895a
...
...
@@ -82,13 +82,17 @@ TEST_CASE(param_add)
auto
hp1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convert"
),
p1
);
auto
hp2
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convert"
),
p2
);
auto
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
hp1
,
hp2
);
auto
res
=
mm
->
add_instruction
(
auto
fs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
to_value
(
migraphx
::
shape
::
float_type
)}}),
hs
);
if
(
add_return
)
{
mm
->
add_return
({
res
});
mm
->
add_return
({
fs
});
}
else
{
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
{
fs
});
}
return
p
;
...
...
@@ -159,10 +163,10 @@ TEST_CASE(param_add_sub)
auto
diff
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"sub"
),
sum
,
p2
);
auto
hdiff
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
half_type
}}),
diff
);
auto
res
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
hdiff
,
hp1
);
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
float_type
}}),
res
);
mm
->
add_return
({
r
});
auto
hadd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
hdiff
,
hp1
);
auto
fadd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
shape
::
float_type
}}),
hadd
);
mm
->
add_return
({
fadd
});
return
p
;
};
...
...
@@ -258,7 +262,8 @@ TEST_CASE(param_add_sub)
};
auto
p0
=
create_program_float
();
migraphx
::
run_passes
(
p0
,
{
migraphx
::
quantize_fp16_pass
{{
"all"
}}});
migraphx
::
run_passes
(
p0
,
{
migraphx
::
quantize_fp16_pass
{{
"all"
}},
migraphx
::
dead_code_elimination
{}});
EXPECT
(
p0
==
create_program_fp16
());
auto
p1
=
create_program_float
();
...
...
@@ -278,7 +283,6 @@ TEST_CASE(literal_add)
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
(
s
,
data
));
auto
l2
=
mm
->
add_literal
(
migraphx
::
literal
(
s
,
data
));
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
l1
,
l2
);
return
p
;
};
...
...
@@ -291,11 +295,11 @@ TEST_CASE(literal_add)
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
(
s
,
data
));
auto
l2
=
mm
->
add_literal
(
migraphx
::
literal
(
s
,
data
));
auto
hs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
l1
,
l2
);
mm
->
add_instruction
(
auto
fs
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"convert"
,
{{
"target_type"
,
migraphx
::
to_value
(
migraphx
::
shape
::
float_type
)}}),
hs
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
fs
);
return
p
;
};
...
...
test/ref_ops_test.cpp
View file @
d7b1895a
...
...
@@ -850,6 +850,31 @@ TEST_CASE(clip_test)
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(clip_dyn_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
std::vector<migraphx::shape::dynamic_dimension> dds = {{2, 8, {3}}};
migraphx::shape s{migraphx::shape::float_type, dds};
auto l = mm->add_parameter("X", s);
auto min_val = mm->add_literal(0.0f);
auto max_val = mm->add_literal(6.0f);
min_val = mm->add_instruction(migraphx::make_op("multibroadcast"), min_val, l);
max_val = mm->add_instruction(migraphx::make_op("multibroadcast"), max_val, l);
mm->add_instruction(migraphx::make_op("clip"), l, min_val, max_val);
p.compile(migraphx::make_target("ref"));
migraphx::shape static_shape{migraphx::shape::float_type, {3}};
migraphx::parameter_map params;
std::vector<float> data = {-1.0, 0.0, 10.0};
params["X"] = migraphx::argument(static_shape, data.data());
auto result = p.eval(params).back();
std::vector<float> results_vector(3);
result.visit([&](auto output) { results_vector.assign(output.begin(), output.end()); });
std::vector<float> gold = {0.0, 0.0, 6.0};
EXPECT(migraphx::verify_range(results_vector, gold));
}
TEST_CASE(concat_test)
{
{
...
...
@@ -7511,7 +7536,7 @@ TEST_CASE(select_module_not_found_error)
migraphx::parameter_map params;
migraphx::shape input_fixed_shape{migraphx::shape::float_type, {5, 2, 2}};
params["data"] = migraphx::argument(input_fixed_shape, input_data.data());
EXPECT(test::throws([&] { p.eval(params).back(); }));
EXPECT(test::throws([&] {
std::ignore =
p.eval(params).back(); }));
}
TEST_CASE(scatternd_reduction_dyn_test)
...
...
test/validate.cpp
View file @
d7b1895a
...
...
@@ -23,6 +23,7 @@
*/
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/make_op.hpp>
#include <basic_ops.hpp>
#include <test.hpp>
#include <rob.hpp>
...
...
@@ -33,7 +34,7 @@ TEST_CASE(simple_test)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
EXPECT
(
bool
{
mm
->
validate
()
==
mm
->
end
()});
auto
result
=
p
.
eval
({});
EXPECT
(
result
.
back
()
==
migraphx
::
literal
{
3
});
...
...
@@ -46,7 +47,7 @@ TEST_CASE(out_of_order)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
ins
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
ins
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
mm
->
move_instruction
(
two
,
mm
->
end
());
EXPECT
(
bool
{
p
.
validate
()
==
ins
});
}
...
...
@@ -57,7 +58,7 @@ TEST_CASE(incomplete_args)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
ins
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
ins
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
ins
->
clear_arguments
();
EXPECT
(
bool
{
p
.
validate
()
==
ins
});
}
...
...
@@ -73,7 +74,7 @@ TEST_CASE(invalid_args)
auto
*
mm
=
p
.
get_main_module
();
auto
one
=
mm
->
add_literal
(
1
);
auto
two
=
mm
->
add_literal
(
2
);
auto
ins
=
mm
->
add_instruction
(
sum_op
{}
,
one
,
two
);
auto
ins
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
)
,
one
,
two
);
access_ins_arguments
(
*
ins
).
clear
();
EXPECT
(
bool
{
mm
->
validate
()
==
mm
->
begin
()});
}
...
...
test/verify/gemm_add_broadcast_half.cpp
0 → 100644
View file @
d7b1895a
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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>
#include <migraphx/apply_alpha_beta.hpp>
struct
gemm_add_broadcast_half
:
verify_program
<
gemm_add_broadcast_half
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
m1_shape
{
migraphx
::
shape
::
half_type
,
{
1
,
2
,
3
}};
migraphx
::
shape
m2_shape
{
migraphx
::
shape
::
half_type
,
{
1
,
3
,
4
}};
migraphx
::
shape
m3_shape
{
migraphx
::
shape
::
half_type
,
{
1
,
1
,
4
}};
auto
l1
=
mm
->
add_parameter
(
"1"
,
m1_shape
);
auto
l2
=
mm
->
add_parameter
(
"2"
,
m2_shape
);
auto
l3
=
mm
->
add_parameter
(
"3"
,
m3_shape
);
auto
l3_b
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
1
,
2
,
4
}}}),
l3
);
auto
dot
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"dot"
),
l1
,
l2
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
dot
,
l3_b
);
return
p
;
}
};
test/verify/gemm_add_half.cpp
0 → 100644
View file @
d7b1895a
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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>
#include <migraphx/apply_alpha_beta.hpp>
struct
gemm_add_half
:
verify_program
<
gemm_add_half
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
m1_shape
{
migraphx
::
shape
::
half_type
,
{
1
,
2
,
3
}};
migraphx
::
shape
m2_shape
{
migraphx
::
shape
::
half_type
,
{
1
,
3
,
4
}};
migraphx
::
shape
m3_shape
{
migraphx
::
shape
::
half_type
,
{
1
,
2
,
4
}};
auto
l1
=
mm
->
add_parameter
(
"1"
,
m1_shape
);
auto
l2
=
mm
->
add_parameter
(
"2"
,
m2_shape
);
auto
l3
=
mm
->
add_parameter
(
"3"
,
m3_shape
);
auto
dot
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"dot"
),
l1
,
l2
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"add"
),
dot
,
l3
);
return
p
;
}
};
test/verify/run_verify.cpp
View file @
d7b1895a
...
...
@@ -49,7 +49,7 @@ std::future<typename std::result_of<Function()>::type> detach_async(Function&& f
{
if
(
parallel
)
{
using
result_type
=
typename
std
::
result
_of
<
Function
()
>::
type
;
using
result_type
=
typename
std
::
invoke_
result
<
Function
>::
type
;
std
::
packaged_task
<
result_type
()
>
task
(
std
::
forward
<
Function
>
(
f
));
auto
fut
=
task
.
get_future
();
std
::
thread
(
std
::
move
(
task
)).
detach
();
...
...
Prev
1
2
3
4
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