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
42a7e55d
Unverified
Commit
42a7e55d
authored
Oct 04, 2023
by
Zakor Gyula
Committed by
GitHub
Oct 04, 2023
Browse files
Add support for CastLike operator (#2261)
parent
9660c64c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
26 deletions
+130
-26
src/onnx/parse_castlike.cpp
src/onnx/parse_castlike.cpp
+53
-0
test/onnx/castlike_error_test.onnx
test/onnx/castlike_error_test.onnx
+14
-0
test/onnx/castlike_test.onnx
test/onnx/castlike_test.onnx
+20
-0
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+23
-0
test/onnx/onnx_test.cpp
test/onnx/onnx_test.cpp
+20
-0
test/py/onnx_backend_test.py
test/py/onnx_backend_test.py
+0
-26
No files found.
src/onnx/parse_castlike.cpp
0 → 100644
View file @
42a7e55d
/*
* 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/onnx/op_parser.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/instruction.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
onnx
{
struct
parse_castlike
:
op_parser
<
parse_castlike
>
{
std
::
vector
<
op_desc
>
operators
()
const
{
return
{{
"CastLike"
}};
}
instruction_ref
parse
(
const
op_desc
&
/*opd*/
,
const
onnx_parser
&
/*parser*/
,
const
onnx_parser
::
node_info
&
info
,
const
std
::
vector
<
instruction_ref
>&
args
)
const
{
if
(
not
(
args
.
size
()
==
2
))
{
MIGRAPHX_THROW
(
"PARSE_CASTLIKE: CastLike must have exactly 2 inputs!"
);
}
shape
::
type_t
target_type
=
args
[
1
]
->
get_shape
().
type
();
return
info
.
add_instruction
(
make_op
(
"convert"
,
{{
"target_type"
,
target_type
}}),
args
[
0
]);
}
};
}
// namespace onnx
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
test/onnx/castlike_error_test.onnx
0 → 100644
View file @
42a7e55d
castlike_error_test:M
0out"CastLikecastlike_error_testZ
0
b
out
B
\ No newline at end of file
test/onnx/castlike_test.onnx
0 → 100644
View file @
42a7e55d
castlike_test:[
0
1out"CastLike castlike_testZ
0
Z
1
b
out
B
\ No newline at end of file
test/onnx/gen_onnx.py
View file @
42a7e55d
...
...
@@ -582,6 +582,29 @@ def cast_test():
return
([
node
],
[
x
],
[
y
])
@
onnx_test
()
def
castlike_test
():
input
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT16
,
[
10
])
target_type
=
helper
.
make_tensor_value_info
(
'1'
,
TensorProto
.
FLOAT
,
[
10
])
output
=
helper
.
make_tensor_value_info
(
'out'
,
TensorProto
.
FLOAT
,
[
10
])
node
=
onnx
.
helper
.
make_node
(
'CastLike'
,
inputs
=
[
'0'
,
'1'
],
outputs
=
[
'out'
])
return
([
node
],
[
input
,
target_type
],
[
output
])
@
onnx_test
()
def
castlike_error_test
():
input
=
helper
.
make_tensor_value_info
(
'0'
,
TensorProto
.
FLOAT16
,
[
10
])
output
=
helper
.
make_tensor_value_info
(
'out'
,
TensorProto
.
FLOAT
,
[
10
])
node
=
onnx
.
helper
.
make_node
(
'CastLike'
,
inputs
=
[
'0'
],
outputs
=
[
'out'
])
return
([
node
],
[
input
],
[
output
])
@
onnx_test
()
def
ceil_test
():
x
=
helper
.
make_tensor_value_info
(
'x'
,
TensorProto
.
FLOAT
,
[
10
])
...
...
test/onnx/onnx_test.cpp
View file @
42a7e55d
...
...
@@ -687,6 +687,26 @@ TEST_CASE(cast_test)
EXPECT(p == prog);
}
TEST_CASE(castlike_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l = mm->add_parameter("0", migraphx::shape{migraphx::shape::half_type, {10}});
mm->add_parameter("1", migraphx::shape{migraphx::shape::float_type, {10}});
mm->add_instruction(
migraphx::make_op("convert",
{{"target_type", migraphx::to_value(migraphx::shape::float_type)}}),
l);
auto prog = optimize_onnx("castlike_test.onnx");
EXPECT(p == prog);
}
TEST_CASE(castlike_error_test)
{
EXPECT(test::throws([&] { migraphx::parse_onnx("castlike_error_test.onnx"); }));
}
TEST_CASE(ceil_test)
{
migraphx::program p;
...
...
test/py/onnx_backend_test.py
View file @
42a7e55d
...
...
@@ -635,14 +635,8 @@ def disabled_tests_onnx_1_10_0(backend_test):
backend_test
.
exclude
(
r
'test_bernoulli_seed_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_BFLOAT16_to_FLOAT_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_BFLOAT16_to_FLOAT_expanded_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_DOUBLE_to_FLOAT16_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_DOUBLE_to_FLOAT_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT16_to_DOUBLE_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT16_to_FLOAT_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT_to_BFLOAT16_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT_to_BFLOAT16_expanded_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT_to_DOUBLE_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT_to_FLOAT16_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT_to_STRING_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_FLOAT_to_STRING_expanded_cpu'
)
backend_test
.
exclude
(
r
'test_castlike_STRING_to_FLOAT_cpu'
)
...
...
@@ -860,28 +854,8 @@ def disabled_tests_onnx_1_13_0(backend_test):
backend_test
.
exclude
(
r
'test_scatter_elements_with_reduction_min_cpu'
)
# The following tests fail due to the CastLike operator being unsupported
backend_test
.
exclude
(
r
'test_elu_default_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_elu_example_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_elu_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_hardsigmoid_default_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_hardsigmoid_example_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_hardsigmoid_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_leakyrelu_default_expanded_cpu'
)
backend_test
.
exclude
(
r
'test_leakyrelu_example_expanded_cpu'
)
backend_test
.
exclude
(
r
'test_leakyrelu_expanded_cpu'
)
backend_test
.
exclude
(
r
'test_selu_default_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_selu_example_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_selu_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_shrink_hard_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_shrink_soft_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_split_1d_uneven_split_opset18_cpu'
)
backend_test
.
exclude
(
r
'test_split_2d_uneven_split_opset18_cpu'
)
backend_test
.
exclude
(
r
'test_thresholdedrelu_default_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_thresholdedrelu_example_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_thresholdedrelu_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_relu_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_softsign_example_expanded_ver18_cpu'
)
backend_test
.
exclude
(
r
'test_softsign_expanded_ver18_cpu'
)
def
disabled_tests_onnx_1_14_0
(
backend_test
):
...
...
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