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
d6b4ae77
Commit
d6b4ae77
authored
Mar 10, 2022
by
Shucai Xiao
Browse files
merge optimization to print flops branch
parents
bdf91961
abe2a889
Changes
106
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
736 additions
and
7 deletions
+736
-7
test/gpu/context_serialize.cpp
test/gpu/context_serialize.cpp
+7
-1
test/include/test.hpp
test/include/test.hpp
+1
-1
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+79
-0
test/onnx/gen_onnx.pyc
test/onnx/gen_onnx.pyc
+0
-0
test/onnx/isnan_float_test.onnx
test/onnx/isnan_float_test.onnx
+11
-0
test/onnx/isnan_half_test.onnx
test/onnx/isnan_half_test.onnx
+13
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+77
-0
test/onnx/scatternd_add_test.onnx
test/onnx/scatternd_add_test.onnx
+26
-0
test/onnx/scatternd_mul_test.onnx
test/onnx/scatternd_mul_test.onnx
+26
-0
test/onnx/scatternd_test.onnx
test/onnx/scatternd_test.onnx
+25
-0
test/op_shape_test.cpp
test/op_shape_test.cpp
+23
-0
test/program_test.cpp
test/program_test.cpp
+3
-3
test/py/onnx_backend_test.py
test/py/onnx_backend_test.py
+1
-1
test/ref_ops_nonstd_shape_test.cpp
test/ref_ops_nonstd_shape_test.cpp
+20
-0
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+349
-0
test/shape_test.cpp
test/shape_test.cpp
+11
-0
test/verify/CMakeLists.txt
test/verify/CMakeLists.txt
+1
-1
test/verify/test_isnan_broadcast.cpp
test/verify/test_isnan_broadcast.cpp
+24
-0
test/verify/test_isnan_float.cpp
test/verify/test_isnan_float.cpp
+19
-0
test/verify/test_isnan_half.cpp
test/verify/test_isnan_half.cpp
+20
-0
No files found.
test/gpu/context_serialize.cpp
View file @
d6b4ae77
...
...
@@ -5,7 +5,7 @@
#include <migraphx/context.hpp>
#include "test.hpp"
TEST_CASE
(
gpu_context
)
TEST_CASE
(
gpu_context
_serialize
)
{
migraphx
::
context
ctx
=
migraphx
::
gpu
::
context
{
0
,
3
};
...
...
@@ -25,4 +25,10 @@ TEST_CASE(gpu_context)
EXPECT
(
v
==
v1
);
}
TEST_CASE
(
context_queue
)
{
migraphx
::
context
ctx
=
migraphx
::
gpu
::
context
{
0
,
3
};
EXPECT
(
ctx
.
get_queue
().
get
<
hipStream_t
>
()
!=
nullptr
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/include/test.hpp
View file @
d6b4ae77
...
...
@@ -197,7 +197,7 @@ struct lhs_expression
TEST_LHS_REOPERATOR
(
%
)
TEST_LHS_REOPERATOR
(
&
)
TEST_LHS_REOPERATOR
(
|
)
TEST_LHS_REOPERATOR
(
^
)
TEST_LHS_REOPERATOR
(
^
)
};
template
<
class
F
>
...
...
test/onnx/gen_onnx.py
View file @
d6b4ae77
...
...
@@ -2307,6 +2307,32 @@ def instance_norm_val_3d_test():
return
([
node
],
[],
[
y
],
[
x_tensor
,
scale_tensor
,
bias_tensor
])
@
onnx_test
def
isnan_float_test
():
t1
=
helper
.
make_tensor_value_info
(
't1'
,
TensorProto
.
FLOAT
,
[
2
,
3
])
t2
=
helper
.
make_tensor_value_info
(
't2'
,
TensorProto
.
FLOAT
,
[
2
,
3
])
node
=
onnx
.
helper
.
make_node
(
'IsNaN'
,
inputs
=
[
't1'
],
outputs
=
[
't2'
],
)
return
([
node
],
[
t1
],
[
t2
])
@
onnx_test
def
isnan_half_test
():
t1
=
helper
.
make_tensor_value_info
(
't1'
,
TensorProto
.
FLOAT16
,
[
2
,
3
])
t2
=
helper
.
make_tensor_value_info
(
't2'
,
TensorProto
.
FLOAT16
,
[
2
,
3
])
node
=
onnx
.
helper
.
make_node
(
'IsNaN'
,
inputs
=
[
't1'
],
outputs
=
[
't2'
],
)
return
([
node
],
[
t1
],
[
t2
])
@
onnx_test
def
layernorm_test
():
x
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT
,
[
1
,
1
,
5
])
...
...
@@ -4126,6 +4152,59 @@ def scatter_test():
return
([
node
],
[
x
,
i
,
u
],
[
y
])
@
onnx_test
def
scatternd_add_test
():
data
=
helper
.
make_tensor_value_info
(
'data'
,
TensorProto
.
FLOAT
,
[
2
,
2
,
2
])
indices
=
helper
.
make_tensor_value_info
(
'indices'
,
TensorProto
.
INT64
,
[
2
,
1
,
2
])
updates
=
helper
.
make_tensor_value_info
(
'updates'
,
TensorProto
.
FLOAT
,
[
2
,
1
,
2
])
output
=
helper
.
make_tensor_value_info
(
'output'
,
TensorProto
.
FLOAT
,
[
2
,
2
,
2
])
node
=
onnx
.
helper
.
make_node
(
'ScatterND'
,
inputs
=
[
'data'
,
'indices'
,
'updates'
],
outputs
=
[
'output'
],
reduction
=
"add"
)
return
([
node
],
[
data
,
indices
,
updates
],
[
output
])
@
onnx_test
def
scatternd_mul_test
():
data
=
helper
.
make_tensor_value_info
(
'data'
,
TensorProto
.
FLOAT
,
[
2
,
2
,
2
])
indices
=
helper
.
make_tensor_value_info
(
'indices'
,
TensorProto
.
INT64
,
[
2
,
1
,
2
])
updates
=
helper
.
make_tensor_value_info
(
'updates'
,
TensorProto
.
FLOAT
,
[
2
,
1
,
2
])
output
=
helper
.
make_tensor_value_info
(
'output'
,
TensorProto
.
FLOAT
,
[
2
,
2
,
2
])
node
=
onnx
.
helper
.
make_node
(
'ScatterND'
,
inputs
=
[
'data'
,
'indices'
,
'updates'
],
outputs
=
[
'output'
],
reduction
=
"mul"
)
return
([
node
],
[
data
,
indices
,
updates
],
[
output
])
@
onnx_test
def
scatternd_test
():
data
=
helper
.
make_tensor_value_info
(
'data'
,
TensorProto
.
FLOAT
,
[
2
,
2
,
2
])
indices
=
helper
.
make_tensor_value_info
(
'indices'
,
TensorProto
.
INT64
,
[
2
,
1
,
2
])
updates
=
helper
.
make_tensor_value_info
(
'updates'
,
TensorProto
.
FLOAT
,
[
2
,
1
,
2
])
output
=
helper
.
make_tensor_value_info
(
'output'
,
TensorProto
.
FLOAT
,
[
2
,
2
,
2
])
node
=
onnx
.
helper
.
make_node
(
'ScatterND'
,
inputs
=
[
'data'
,
'indices'
,
'updates'
],
outputs
=
[
'output'
])
return
([
node
],
[
data
,
indices
,
updates
],
[
output
])
@
onnx_test
def
selu_test
():
x
=
helper
.
make_tensor_value_info
(
'x'
,
TensorProto
.
DOUBLE
,
[
2
,
3
])
...
...
test/onnx/gen_onnx.pyc
deleted
100644 → 0
View file @
bdf91961
File deleted
test/onnx/isnan_float_test.onnx
0 → 100644
View file @
d6b4ae77
isnan_float_test:O
t1t2"IsNaNisnan_float_testZ
t1
b
t2
B
\ No newline at end of file
test/onnx/isnan_half_test.onnx
0 → 100644
View file @
d6b4ae77
isnan_half_test:N
t1t2"IsNaNisnan_half_testZ
t1
b
t2
B
\ No newline at end of file
test/onnx/onnx_test.cpp
View file @
d6b4ae77
...
...
@@ -1929,6 +1929,32 @@ TEST_CASE(if_tuple_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
isnan_float_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
auto
t1
=
mm
->
add_parameter
(
"t1"
,
s
);
auto
ret
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
t1
);
mm
->
add_return
({
ret
});
auto
prog
=
migraphx
::
parse_onnx
(
"isnan_float_test.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
isnan_half_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
half_type
,
{
2
,
3
}};
auto
t1
=
mm
->
add_parameter
(
"t1"
,
s
);
auto
ret
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
t1
);
mm
->
add_return
({
ret
});
auto
prog
=
migraphx
::
parse_onnx
(
"isnan_half_test.onnx"
);
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
imagescaler_test
)
{
migraphx
::
program
p
;
...
...
@@ -3970,6 +3996,57 @@ TEST_CASE(scatter_test)
EXPECT
(
p
==
prog
);
}
TEST_CASE
(
scatternd_test
)
{
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
l0
=
mm
->
add_parameter
(
"data"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
}});
auto
l1
=
mm
->
add_parameter
(
"indices"
,
migraphx
::
shape
{
migraphx
::
shape
::
int64_type
,
{
2
,
1
,
2
}});
auto
l2
=
mm
->
add_parameter
(
"updates"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
1
,
2
}});
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
l0
,
l1
,
l2
);
mm
->
add_return
({
r
});
auto
prog
=
migraphx
::
parse_onnx
(
"scatternd_test.onnx"
);
EXPECT
(
p
==
prog
);
}
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
l0
=
mm
->
add_parameter
(
"data"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
}});
auto
l1
=
mm
->
add_parameter
(
"indices"
,
migraphx
::
shape
{
migraphx
::
shape
::
int64_type
,
{
2
,
1
,
2
}});
auto
l2
=
mm
->
add_parameter
(
"updates"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
1
,
2
}});
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_add"
),
l0
,
l1
,
l2
);
mm
->
add_return
({
r
});
auto
prog
=
migraphx
::
parse_onnx
(
"scatternd_add_test.onnx"
);
EXPECT
(
p
==
prog
);
}
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
l0
=
mm
->
add_parameter
(
"data"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
,
2
}});
auto
l1
=
mm
->
add_parameter
(
"indices"
,
migraphx
::
shape
{
migraphx
::
shape
::
int64_type
,
{
2
,
1
,
2
}});
auto
l2
=
mm
->
add_parameter
(
"updates"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
1
,
2
}});
auto
r
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_mul"
),
l0
,
l1
,
l2
);
mm
->
add_return
({
r
});
auto
prog
=
migraphx
::
parse_onnx
(
"scatternd_mul_test.onnx"
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
selu_test
)
{
migraphx
::
program
p
;
...
...
test/onnx/scatternd_add_test.onnx
0 → 100644
View file @
d6b4ae77
scatternd_add_test:Î
@
data
indices
updatesoutput" ScatterND*
reduction"add scatternd_add_testZ
data
Z
indices
Z
updates
b
output
B
\ No newline at end of file
test/onnx/scatternd_mul_test.onnx
0 → 100644
View file @
d6b4ae77
scatternd_mul_test:
@
data
indices
updatesoutput" ScatterND*
reduction"mulscatternd_mul_testZ
data
Z
indices
Z
updates
b
output
B
\ No newline at end of file
test/onnx/scatternd_test.onnx
0 → 100644
View file @
d6b4ae77
scatternd_test:
+
data
indices
updatesoutput" ScatterNDscatternd_testZ
data
Z
indices
Z
updates
b
output
B
\ No newline at end of file
test/op_shape_test.cpp
View file @
d6b4ae77
...
...
@@ -1432,6 +1432,29 @@ TEST_CASE(test_scalar_nelemnts)
throws_shape
(
migraphx
::
make_op
(
"scalar"
,
{{
"scalar_bcst_dims"
,
{
2
,
3
,
4
,
5
}}}),
input
);
}
TEST_CASE
(
test_scatternd
)
{
{
// k > r
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
8
}};
migraphx
::
shape
is
{
itype
,
{
4
,
2
}};
migraphx
::
shape
us
{
dtype
,
{
4
}};
throws_shape
(
migraphx
::
make_op
(
"scatternd_none"
),
ds
,
is
,
us
);
}
{
// update.lens != indices.lens[0:q-1] ++ data.lens[k:r-1]
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
8
}};
migraphx
::
shape
is
{
itype
,
{
4
,
1
}};
migraphx
::
shape
us
{
dtype
,
{
2
,
2
}};
throws_shape
(
migraphx
::
make_op
(
"scatternd_none"
),
ds
,
is
,
us
);
}
}
TEST_CASE
(
test_squeeze
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
4
,
1
,
3
,
1
,
3
}};
...
...
test/program_test.cpp
View file @
d6b4ae77
...
...
@@ -66,17 +66,17 @@ TEST_CASE(program_print)
auto
in1
=
mm
->
end
();
// print end instruction
p
.
debug_print
(
in1
);
p
.
debug_print
(
in1
,
{}
);
// print instruction not in the program
auto
p2
=
p
;
auto
*
mm2
=
p2
.
get_main_module
();
auto
in2
=
mm2
->
begin
();
p
.
debug_print
(
in2
);
p
.
debug_print
(
in2
,
{}
);
// print last instruction
auto
in3
=
std
::
prev
(
in1
);
p
.
debug_print
(
in3
);
p
.
debug_print
(
in3
,
{}
);
}
TEST_CASE
(
program_annotate
)
...
...
test/py/onnx_backend_test.py
View file @
d6b4ae77
...
...
@@ -122,6 +122,7 @@ def create_backend_test(testname=None, target_device=None):
backend_test
.
include
(
r
'.*test_hardswish.*'
)
backend_test
.
include
(
r
'.*test_identity.*'
)
backend_test
.
include
(
r
'.*test_if.*'
)
backend_test
.
include
(
r
'.*test_isnan.*'
)
backend_test
.
include
(
r
'.*test_LeakyReLU*'
)
backend_test
.
include
(
r
'.*test_leakyrelu.*'
)
backend_test
.
include
(
r
'.*test_less.*'
)
...
...
@@ -270,7 +271,6 @@ def create_backend_test(testname=None, target_device=None):
backend_test
.
exclude
(
r
'test_identity_sequence_cpu'
)
backend_test
.
exclude
(
r
'test_maxpool_2d_uint8_cpu'
)
backend_test
.
exclude
(
r
'test_negative_log_likelihood_loss_*'
)
backend_test
.
exclude
(
r
'test_scatternd_*'
)
# all reduce ops have dynamic axes inputs
backend_test
.
exclude
(
r
'test_size_cpu'
)
...
...
test/ref_ops_nonstd_shape_test.cpp
View file @
d6b4ae77
...
...
@@ -47,6 +47,26 @@ TEST_CASE(argmin_test_nonstd_shape)
EXPECT
(
migraphx
::
verify_range
(
result_vec
,
res_gold_vec
));
}
TEST_CASE
(
isnan_broadcast_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s0
{
migraphx
::
shape
::
float_type
,
{
3
}};
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
3
,
2
}};
auto
nan_val
=
std
::
numeric_limits
<
float
>::
quiet_NaN
();
std
::
vector
<
float
>
data0
=
{
1.2
,
5.2
,
nan_val
};
auto
l0
=
mm
->
add_literal
(
migraphx
::
literal
{
s0
,
data0
});
auto
l1
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
0
},
{
"out_lens"
,
s1
.
lens
()}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
l1
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
correct
=
{
0
,
0
,
0
,
0
,
1
,
1
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
correct
));
}
TEST_CASE
(
squeeze_transpose_test
)
{
migraphx
::
program
p
;
...
...
test/ref_ops_test.cpp
View file @
d6b4ae77
...
...
@@ -2,6 +2,7 @@
#include <vector>
#include <cmath>
#include <random>
#include <limits>
#include <migraphx/literal.hpp>
#include <migraphx/op/pooling.hpp>
#include <migraphx/op/batch_norm_inference.hpp>
...
...
@@ -1946,6 +1947,45 @@ TEST_CASE(if_pl_test)
}
}
TEST_CASE
(
isnan_test
)
{
// float test
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
auto
nan_val
=
std
::
numeric_limits
<
float
>::
quiet_NaN
();
std
::
vector
<
float
>
data0
=
{
1.2
,
5.2
,
nan_val
,
nan_val
,
0.
,
100.
};
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
{
s
,
data0
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
l1
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
correct
=
{
0
,
0
,
1
,
1
,
0
,
0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
correct
));
}
// half test
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
half_type
,
{
2
,
3
}};
auto
nan_val
=
std
::
numeric_limits
<
migraphx
::
half
>::
quiet_NaN
();
migraphx
::
half
a
{
1.2
};
migraphx
::
half
b
{
5.2
};
std
::
vector
<
migraphx
::
half
>
data0
=
{
a
,
b
,
nan_val
,
nan_val
,
b
,
a
};
auto
l1
=
mm
->
add_literal
(
migraphx
::
literal
{
s
,
data0
});
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
l1
);
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
correct
=
{
0
,
0
,
1
,
1
,
0
,
0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
correct
));
}
}
TEST_CASE
(
im2col_3x3_no_pad_identity_test
)
{
std
::
size_t
f
[
2
]
=
{
3
,
3
};
...
...
@@ -4215,6 +4255,315 @@ TEST_CASE(scatter_test)
}
}
TEST_CASE
(
scatternd_shapes_test
)
{
{
// broadcasted input
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
is
{
itype
,
{
4
,
1
}};
migraphx
::
shape
us
{
dtype
,
{
4
}};
std
::
vector
<
int64_t
>
ind_vec
{
4
,
3
,
1
,
7
};
std
::
vector
<
float
>
upd_vec
{
9
,
10
,
11
,
12
};
auto
data
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
8
}}}),
mm
->
add_literal
(
migraphx
::
literal
{
0.0
f
}));
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
0
,
11
,
0
,
10
,
9
,
0
,
0
,
12
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
// non-standard shape input
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
2
,
2
}};
migraphx
::
shape
is
{
itype
,
{
2
,
2
}};
migraphx
::
shape
us
{
dtype
,
{
2
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
};
std
::
vector
<
int64_t
>
ind_vec
{
0
,
0
,
0
,
1
};
std
::
vector
<
float
>
upd_vec
{
5
,
6
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
td
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
0
}}}),
data
);
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
td
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
5
,
6
,
2
,
4
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
// non-standard updates shape
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
2
,
2
,
2
}};
migraphx
::
shape
is
{
itype
,
{
2
,
1
,
3
}};
migraphx
::
shape
us
{
dtype
,
{
1
,
2
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
int64_t
>
ind_vec
{
0
,
0
,
0
,
1
,
1
,
1
};
std
::
vector
<
float
>
upd_vec
{
9
,
10
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
tu
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
0
}}}),
updates
);
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
data
,
indices
,
tu
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
9
,
2
,
3
,
4
,
5
,
6
,
7
,
10
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
scatternd_test
)
{
{
// r=1, q=2, k=1
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
8
}};
migraphx
::
shape
is
{
itype
,
{
4
,
1
}};
migraphx
::
shape
us
{
dtype
,
{
4
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
int64_t
>
ind_vec
{
4
,
3
,
1
,
7
};
std
::
vector
<
float
>
upd_vec
{
9
,
10
,
11
,
12
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
1
,
11
,
3
,
10
,
9
,
6
,
7
,
12
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
// r=2, q=2, k=2
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
2
,
2
}};
migraphx
::
shape
is
{
itype
,
{
2
,
2
}};
migraphx
::
shape
us
{
dtype
,
{
2
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
};
std
::
vector
<
int64_t
>
ind_vec
{
0
,
0
,
0
,
1
};
std
::
vector
<
float
>
upd_vec
{
5
,
6
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
5
,
6
,
3
,
4
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
// r=3, q=3, k=3
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
2
,
2
,
2
}};
migraphx
::
shape
is
{
itype
,
{
2
,
1
,
3
}};
migraphx
::
shape
us
{
dtype
,
{
2
,
1
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
int64_t
>
ind_vec
{
0
,
0
,
0
,
1
,
1
,
1
};
std
::
vector
<
float
>
upd_vec
{
9
,
10
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
9
,
2
,
3
,
4
,
5
,
6
,
7
,
10
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
// r=3, q=2, k=1
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
4
,
4
,
4
}};
migraphx
::
shape
is
{
itype
,
{
2
,
1
}};
migraphx
::
shape
us
{
dtype
,
{
2
,
4
,
4
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
int64_t
>
ind_vec
{
0
,
2
};
std
::
vector
<
float
>
upd_vec
{
5
,
5
,
5
,
5
,
6
,
6
,
6
,
6
,
7
,
7
,
7
,
7
,
8
,
8
,
8
,
8
,
1
,
1
,
1
,
1
,
2
,
2
,
2
,
2
,
3
,
3
,
3
,
3
,
4
,
4
,
4
,
4
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
5
,
5
,
5
,
5
,
6
,
6
,
6
,
6
,
7
,
7
,
7
,
7
,
8
,
8
,
8
,
8
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
1
,
1
,
1
,
1
,
2
,
2
,
2
,
2
,
3
,
3
,
3
,
3
,
4
,
4
,
4
,
4
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
// r=5, q=1, k=1
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
2
,
2
,
2
,
2
,
2
}};
migraphx
::
shape
is
{
itype
,
{
1
}};
migraphx
::
shape
us
{
dtype
,
{
2
,
2
,
2
,
2
}};
std
::
vector
<
float
>
data_vec
(
32
,
1
);
std
::
vector
<
int64_t
>
ind_vec
{
1
};
std
::
vector
<
float
>
upd_vec
(
16
,
0
);
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_none"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
(
32
,
0
);
std
::
copy
(
data_vec
.
begin
(),
data_vec
.
begin
()
+
16
,
gold
.
begin
());
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
scatternd_reduction_test
)
{
{
// reduction = add
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
8
}};
migraphx
::
shape
is
{
itype
,
{
8
,
1
}};
migraphx
::
shape
us
{
dtype
,
{
8
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
int64_t
>
ind_vec
{
4
,
3
,
1
,
7
,
4
,
3
,
1
,
7
};
std
::
vector
<
float
>
upd_vec
{
9
,
10
,
11
,
12
,
-
8
,
-
9
,
-
10
,
-
11
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_add"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
1
,
3
,
3
,
5
,
6
,
6
,
7
,
9
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
{
// reduction = mul
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
dtype
=
migraphx
::
shape
::
float_type
;
auto
itype
=
migraphx
::
shape
::
int64_type
;
migraphx
::
shape
ds
{
dtype
,
{
8
}};
migraphx
::
shape
is
{
itype
,
{
4
,
1
}};
migraphx
::
shape
us
{
dtype
,
{
4
}};
std
::
vector
<
float
>
data_vec
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
int64_t
>
ind_vec
{
4
,
3
,
1
,
7
};
std
::
vector
<
float
>
upd_vec
{
9
,
10
,
11
,
12
};
auto
data
=
mm
->
add_literal
(
migraphx
::
literal
{
ds
,
data_vec
});
auto
indices
=
mm
->
add_literal
(
migraphx
::
literal
{
is
,
ind_vec
});
auto
updates
=
mm
->
add_literal
(
migraphx
::
literal
{
us
,
upd_vec
});
auto
scatternd
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"scatternd_mul"
),
data
,
indices
,
updates
);
mm
->
add_return
({
scatternd
});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
1
,
22
,
3
,
40
,
45
,
6
,
7
,
96
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
sigmoid_test
)
{
migraphx
::
program
p
;
...
...
test/shape_test.cpp
View file @
d6b4ae77
...
...
@@ -608,4 +608,15 @@ TEST_CASE(cpp_type_name)
EXPECT
(
test
::
throws
([
&
]
{
migraphx
::
shape
::
cpp_type
(
migraphx
::
shape
::
tuple_type
);
}));
}
TEST_CASE
(
test_with_type
)
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
2
},
{
1
,
0
}};
EXPECT
(
s
.
type
()
==
migraphx
::
shape
::
float_type
);
auto
new_s
=
s
.
with_type
(
migraphx
::
shape
::
half_type
);
EXPECT
(
s
.
type
()
==
migraphx
::
shape
::
float_type
);
EXPECT
(
s
.
type
()
!=
new_s
.
type
());
EXPECT
(
s
.
lens
()
==
new_s
.
lens
());
EXPECT
(
s
.
strides
()
==
new_s
.
strides
());
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
test/verify/CMakeLists.txt
View file @
d6b4ae77
file
(
GLOB VERIFY_TESTS *.cpp
)
file
(
GLOB VERIFY_TESTS
${
CONFIGURE_DEPENDS
}
*.cpp
)
add_executable
(
test_verify
${
VERIFY_TESTS
}
)
add_dependencies
(
tests test_verify
)
...
...
test/verify/test_isnan_broadcast.cpp
0 → 100644
View file @
d6b4ae77
#include <limits>
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_isnan_broadcast
:
verify_program
<
test_isnan_broadcast
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
}});
auto
s0
=
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}};
x
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"broadcast"
,
{{
"axis"
,
0
},
{
"out_lens"
,
s0
.
lens
()}}),
x
);
std
::
vector
<
float
>
data0
{
2
,
std
::
numeric_limits
<
float
>::
quiet_NaN
()};
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
1
,
2
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
literal
{
s1
,
data0
});
x
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"concat"
,
{{
"axis"
,
0
}}),
x
,
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
x
);
return
p
;
}
};
test/verify/test_isnan_float.cpp
0 → 100644
View file @
d6b4ae77
#include <limits>
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
struct
test_isnan_float
:
verify_program
<
test_isnan_float
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
}});
auto
l0
=
mm
->
add_literal
(
std
::
numeric_limits
<
float
>::
quiet_NaN
());
x
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"concat"
,
{{
"axis"
,
0
}}),
x
,
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
x
);
return
p
;
}
};
test/verify/test_isnan_half.cpp
0 → 100644
View file @
d6b4ae77
#include <limits>
#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/half.hpp>
struct
test_isnan_half
:
verify_program
<
test_isnan_half
>
{
migraphx
::
program
create_program
()
const
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
x
=
mm
->
add_parameter
(
"x"
,
migraphx
::
shape
{
migraphx
::
shape
::
half_type
,
{
2
}});
auto
l0
=
mm
->
add_literal
(
std
::
numeric_limits
<
migraphx
::
half
>::
quiet_NaN
());
x
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"concat"
,
{{
"axis"
,
0
}}),
x
,
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
x
);
return
p
;
}
};
Prev
1
2
3
4
5
6
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