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
65e14286
Commit
65e14286
authored
Sep 28, 2022
by
charlie
Browse files
Unary ops changes and tests
parent
30243d2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
471 additions
and
72 deletions
+471
-72
src/include/migraphx/op/elu.hpp
src/include/migraphx/op/elu.hpp
+6
-7
src/include/migraphx/op/leaky_relu.hpp
src/include/migraphx/op/leaky_relu.hpp
+5
-4
src/targets/ref/lowering.cpp
src/targets/ref/lowering.cpp
+0
-61
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+460
-0
No files found.
src/include/migraphx/op/elu.hpp
View file @
65e14286
...
...
@@ -32,21 +32,20 @@ namespace migraphx {
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
elu
struct
elu
:
unary
<
elu
>
{
std
::
string
name
()
const
{
return
"elu"
;
}
float
alpha
=
1
;
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
return
inputs
.
front
();
}
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
pack
(
f
(
self
.
alpha
,
"alpha"
));
}
auto
apply
()
const
{
return
[
&
](
auto
x
)
{
return
x
>
0
?
x
:
alpha
*
std
::
expm1
(
x
);
};
}
};
}
// namespace op
...
...
src/include/migraphx/op/leaky_relu.hpp
View file @
65e14286
...
...
@@ -26,12 +26,13 @@
#include <migraphx/check_shapes.hpp>
#include <migraphx/config.hpp>
#include <migraphx/op/unary.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
op
{
struct
leaky_relu
struct
leaky_relu
:
unary
<
leaky_relu
>
{
float
alpha
=
0.01
;
...
...
@@ -42,10 +43,10 @@ struct leaky_relu
}
std
::
string
name
()
const
{
return
"leaky_relu"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
auto
apply
()
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
return
inputs
.
front
();
return
[
&
](
auto
x
)
{
return
x
>
0
?
x
:
x
*
alpha
;
};
}
};
...
...
src/targets/ref/lowering.cpp
View file @
65e14286
...
...
@@ -507,65 +507,6 @@ struct ref_quant_gemm
};
MIGRAPHX_REGISTER_OP
(
ref_gemm
)
struct
leaky_relu_op
{
op
::
leaky_relu
op
;
std
::
string
name
()
const
{
return
"ref::leaky_relu"
;
}
auto
fcn
()
const
{
auto
a
=
op
.
alpha
;
return
[
a
](
auto
x
)
{
return
x
>
0
?
x
:
x
*
a
;
};
}
};
struct
elu_op
{
op
::
elu
op
;
std
::
string
name
()
const
{
return
"ref::elu"
;
}
auto
fcn
()
const
{
auto
a
=
op
.
alpha
;
return
[
a
](
auto
x
)
{
return
x
>
0
?
x
:
a
*
std
::
expm1
(
x
);
};
}
};
template
<
typename
Op
>
struct
ref_unary
:
auto_register_op
<
ref_unary
<
Op
>>
{
ref_unary
()
=
default
;
template
<
class
T
>
ref_unary
(
T
pop
)
:
op
(
Op
{
std
::
move
(
pop
)})
{
}
Op
op
;
template
<
class
Self
,
class
F
>
static
auto
reflect
(
Self
&
self
,
F
f
)
{
return
migraphx
::
reflect
(
self
.
op
.
op
,
f
);
}
std
::
string
name
()
const
{
return
op
.
name
();
}
shape
compute_shape
(
const
std
::
vector
<
shape
>&
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
const
auto
&
s
=
inputs
.
at
(
0
);
return
{
s
.
type
(),
s
.
lens
()};
}
argument
compute
(
context
&
,
const
shape
&
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
argument
result
{
output_shape
};
visit_all
(
result
,
args
[
0
])([
&
](
auto
output
,
auto
input
)
{
assert
(
input
.
get_shape
().
standard
());
std
::
transform
(
input
.
begin
(),
input
.
end
(),
output
.
begin
(),
op
.
fcn
());
});
return
result
;
}
};
template
<
class
Op
>
struct
ref_softmax
:
auto_register_op
<
ref_softmax
<
Op
>>
{
...
...
@@ -708,9 +649,7 @@ struct ref_apply
apply_map
[
"quant_dot"
]
=
extend_op
<
ref_quant_gemm
,
op
::
quant_dot
>
();
apply_map
[
"quant_convolution"
]
=
extend_op
<
ref_convolution
<
op
::
quant_convolution
>
,
op
::
quant_convolution
>
();
apply_map
[
"elu"
]
=
extend_op
<
ref_unary
<
elu_op
>
,
op
::
elu
>
();
apply_map
[
"im2col"
]
=
extend_op
<
ref_im2col
,
op
::
im2col
>
();
apply_map
[
"leaky_relu"
]
=
extend_op
<
ref_unary
<
leaky_relu_op
>
,
op
::
leaky_relu
>
();
apply_map
[
"logsoftmax"
]
=
extend_op
<
ref_softmax
<
op
::
logsoftmax
>
,
op
::
logsoftmax
>
();
apply_map
[
"lrn"
]
=
extend_op
<
ref_lrn
,
op
::
lrn
>
();
apply_map
[
"pad"
]
=
extend_op
<
ref_pad
,
op
::
pad
>
();
...
...
test/ref_ops_test.cpp
View file @
65e14286
...
...
@@ -1826,6 +1826,29 @@ TEST_CASE(cos_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
cos_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"cos"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
cosf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
cosh_test
)
{
migraphx
::
program
p
;
...
...
@@ -1844,6 +1867,29 @@ TEST_CASE(cosh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
cosh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"cosh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
coshf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
deconv_1d_test
)
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
,
1
,
3
}};
...
...
@@ -2028,6 +2074,28 @@ TEST_CASE(elu_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
elu_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
float
alpha
=
0.5
;
mm
->
add_instruction
(
migraphx
::
make_op
(
"elu"
,
{{
"alpha"
,
alpha
}}),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
elu
(
alpha
,
-
1
),
elu
(
alpha
,
2
),
elu
(
alpha
,
-
3
),
elu
(
alpha
,
4
)};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
equal_brcst_test
)
{
migraphx
::
program
p
;
...
...
@@ -2095,6 +2163,29 @@ TEST_CASE(erf_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
erf_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
0.73785057
,
1.58165966
,
-
0.43597795
,
-
0.01677432
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"erf"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
erff
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
exp_test
)
{
migraphx
::
program
p
;
...
...
@@ -2113,6 +2204,29 @@ TEST_CASE(exp_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
exp_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"exp"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
expf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
floor_test
)
{
migraphx
::
program
p
;
...
...
@@ -2131,6 +2245,29 @@ TEST_CASE(floor_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
floor_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
5
,
12
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
1.1
,
1.5
,
0.6
,
-
1.1
,
-
1.5
,
-
0.6
,
0.0
,
2.0
,
-
2.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"floor"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
9
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
floor
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
fp16_test
)
{
migraphx
::
program
p
;
...
...
@@ -2683,6 +2820,25 @@ TEST_CASE(identity_test)
EXPECT
(
std
::
equal
(
data
.
begin
(),
data
.
end
(),
results_vector
.
begin
()));
}
TEST_CASE
(
identity_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
0
},
{
2
,
4
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
int
>
input_data
{
1
,
2
,
3
,
4
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"identity"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
int32_type
,
{
2
,
2
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
int
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
EXPECT
(
std
::
equal
(
input_data
.
begin
(),
input_data
.
end
(),
results_vector
.
begin
()));
}
TEST_CASE
(
if_literal_test
)
{
auto
create_program
=
[]
{
...
...
@@ -2910,6 +3066,27 @@ TEST_CASE(isnan_test)
}
}
TEST_CASE
(
isnan_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
2
,
0
},
{
3
,
8
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
auto
nan_val
=
std
::
numeric_limits
<
float
>::
quiet_NaN
();
std
::
vector
<
float
>
input_data
=
{
1.2
,
5.2
,
nan_val
,
nan_val
,
0.
,
100.
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"isnan"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
2
,
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
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
};
...
...
@@ -3226,6 +3403,29 @@ TEST_CASE(log_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
log_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
1
,
2
,
3
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"log"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
logf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
logical_and_test
)
{
migraphx
::
program
p
;
...
...
@@ -4267,6 +4467,27 @@ TEST_CASE(not_test)
}
}
TEST_CASE
(
not_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
0
,
8
,
1
,
-
32
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"not"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
char
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
char
>
gold
{
1
,
0
,
0
,
0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
pad_test
)
{
migraphx
::
program
p
;
...
...
@@ -4917,6 +5138,27 @@ TEST_CASE(recip_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
recip_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
0.5
f
,
0.1
f
,
0.5
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"recip"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
-
2.0
f
,
10.0
f
,
2.0
f
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
reduce_max_axis0
)
{
migraphx
::
program
p
;
...
...
@@ -5204,6 +5446,27 @@ TEST_CASE(relu_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
relu_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.
f
,
0.
f
,
1.
f
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"relu"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0.
f
,
0.
f
,
1.
f
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
reshape_test
)
{
migraphx
::
shape
a_shape
{
migraphx
::
shape
::
float_type
,
{
24
,
1
,
1
,
1
}};
...
...
@@ -5488,6 +5751,27 @@ TEST_CASE(round_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
round_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
4
,
10
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
1.1
,
1.5
,
1.6
,
-
1.1
,
-
1.5
,
-
1.6
,
0.0
,
2.0
,
-
2.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"round"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
9
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
;
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
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
rsqrt_test
)
{
migraphx
::
program
p
;
...
...
@@ -5503,6 +5787,27 @@ TEST_CASE(rsqrt_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
rsqrt_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
4.0
,
16.0
,
64.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"rsqrt"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
0.5
,
0.25
,
0.125
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
// reduction_mode: "scatter_none", "scatter_add", "scatter_mul"
migraphx
::
program
create_scatter_program
(
const
std
::
string
&
reduction_mode
,
int
axis
)
{
...
...
@@ -6051,6 +6356,26 @@ TEST_CASE(sigmoid_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sigmoid_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
0
},
{
2
,
2
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
2
,
-
3
,
4
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sigmoid"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
{
sigmoid
(
-
1
),
sigmoid
(
2
),
sigmoid
(
-
3
),
sigmoid
(
4
)};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sign_test
)
{
migraphx
::
program
p
;
...
...
@@ -6067,6 +6392,27 @@ TEST_CASE(sign_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sign_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
1.02481645
,
0.85643062
,
-
0.03404123
,
-
0.92791926
,
0.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sign"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
5
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
{
1.0
,
1.0
,
-
1.0
,
-
1.0
,
0.0
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sin_test
)
{
migraphx
::
program
p
;
...
...
@@ -6085,6 +6431,29 @@ TEST_CASE(sin_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sin_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
=
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sin"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
sinf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sinh_test
)
{
migraphx
::
program
p
;
...
...
@@ -6103,6 +6472,28 @@ TEST_CASE(sinh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sinh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{{
2
,
4
,
0
},
{
2
,
4
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sinh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
sinhf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
slice_test
)
{
{
...
...
@@ -6259,6 +6650,29 @@ TEST_CASE(sqrt_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
sqrt_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
1.02481645
,
0.85643062
,
0.03404123
,
0.92791926
,
0.10569184
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"sqrt"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
5
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
;
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
sqrtf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
squeeze_test
)
{
{
...
...
@@ -6371,6 +6785,29 @@ TEST_CASE(tan_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
tan_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1
,
0
,
1
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"tan"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
3
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
3
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
tanf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
tanh_test
)
{
migraphx
::
program
p
;
...
...
@@ -6389,6 +6826,29 @@ TEST_CASE(tanh_test)
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
tanh_dynamic_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
::
dynamic_dimension
dd
{
3
,
8
,
0
};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
dd
}};
auto
input
=
mm
->
add_parameter
(
"X"
,
s
);
std
::
vector
<
float
>
input_data
{
-
1.0
,
2.0
,
-
3.0
,
4.0
};
mm
->
add_instruction
(
migraphx
::
make_op
(
"tanh"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
parameter_map
params0
;
migraphx
::
shape
input_fixed_shape0
{
migraphx
::
shape
::
float_type
,
{
4
}};
params0
[
"X"
]
=
migraphx
::
argument
(
input_fixed_shape0
,
input_data
.
data
());
auto
result
=
p
.
eval
(
params0
).
back
();
std
::
vector
<
float
>
results_vector
(
4
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
float
>
gold
=
input_data
;
std
::
transform
(
gold
.
begin
(),
gold
.
end
(),
gold
.
begin
(),
[](
float
n
)
->
float
{
return
tanhf
(
n
);
});
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
topk_test
)
{
auto
create_program
=
[](
int64_t
k
,
int64_t
axis
,
int
largest
)
{
...
...
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