Skip to content

Commit

Permalink
Add tests for more operators
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsan-ca committed May 29, 2024
1 parent f978c8c commit 21c00e7
Show file tree
Hide file tree
Showing 20 changed files with 580 additions and 3 deletions.
Binary file added test/onnx/binary_dyn_brcst_mul_fp8_test.onnx
Binary file not shown.
13 changes: 13 additions & 0 deletions test/onnx/cos_fp8_test.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
  cos_fp8_test:=

xy"Cos cos_fp8_testZ
x



b
y



B
16 changes: 16 additions & 0 deletions test/onnx/div_fp8_test.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
  div_fp8_test:a

0
1out"Div div_fp8_testZ
0


Z
1


b
out


B
132 changes: 132 additions & 0 deletions test/onnx/gen_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,38 @@ def binary_dyn_brcst_mul_test():
return ([node], [arg0, arg1], [arg_out])


@onnx_test()
def binary_dyn_brcst_mul_fp8_test():
arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT8E4M3FNUZ,
[None, 3, 4, 5])
arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT8E4M3FNUZ, [4, 1])
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT8E4M3FNUZ,
[None, 3, 4, 5])

node = onnx.helper.make_node(
'Mul',
inputs=['0', '1'],
outputs=['out'],
)

return ([node], [arg0, arg1], [arg_out])


@onnx_test()
def div_fp8_test():
arg0 = helper.make_tensor_value_info('0', TensorProto.FLOAT8E4M3FNUZ, [2, 3])
arg1 = helper.make_tensor_value_info('1', TensorProto.FLOAT8E4M3FNUZ, [2, 3])
arg_out = helper.make_tensor_value_info('out', TensorProto.FLOAT8E4M3FNUZ, [2, 3])

node = onnx.helper.make_node(
'Div',
inputs=['0', '1'],
outputs=['out'],
)

return ([node], [arg0, arg1], [arg_out])


@onnx_test()
def cast_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT16, [10])
Expand Down Expand Up @@ -1588,6 +1620,20 @@ def cos_test():
return ([node], [x], [y])


@onnx_test()
def cos_fp8_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT8E4M3FNUZ, [10])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT8E4M3FNUZ, [10])

node = onnx.helper.make_node(
'Cos',
inputs=['x'],
outputs=['y'],
)

return ([node], [x], [y])


@onnx_test()
def cosh_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [1])
Expand Down Expand Up @@ -2844,6 +2890,20 @@ def globalavgpool_test():
return ([node], [x], [y])


@onnx_test()
def globalavgpool_fp8_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT8E4M3FNUZ, [1, 3, 16, 16])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT8E4M3FNUZ, [1, 3, 1, 1])

node = onnx.helper.make_node(
'GlobalAveragePool',
inputs=['0'],
outputs=['1'],
)

return ([node], [x], [y])


@onnx_test()
def globalavgpool_dyn_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT,
Expand Down Expand Up @@ -2902,6 +2962,20 @@ def globalmaxpool_test():
return ([node], [x], [y])


@onnx_test()
def globalmaxpool_fp8_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT8E4M3FNUZ, [1, 3, 16, 16])
y = helper.make_tensor_value_info('1', TensorProto.FLOAT8E4M3FNUZ, [1, 3, 1, 1])

node = onnx.helper.make_node(
'GlobalMaxPool',
inputs=['0'],
outputs=['1'],
)

return ([node], [x], [y])


@onnx_test()
def globalmaxpool_dyn_test():
x = helper.make_tensor_value_info('0', TensorProto.FLOAT,
Expand Down Expand Up @@ -7749,6 +7823,22 @@ def reducemax_test():
return ([node], [x], [y])


@onnx_test()
def reducemax_fp8_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT8E4M3FNUZ, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT8E4M3FNUZ, [3, 4, 6])

axes = [2]

node = onnx.helper.make_node('ReduceMax',
inputs=['x'],
outputs=['y'],
axes=axes,
keepdims=0)

return ([node], [x], [y])


@onnx_test
def reducemax_dyn_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [None, 4, 5, 6])
Expand Down Expand Up @@ -7838,6 +7928,20 @@ def reducesum_test():
return ([node], [x], [y])


@onnx_test()
def reducesum_fp8_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT8E4M3FNUZ, [3, 4, 5, 6])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT8E4M3FNUZ, [3, 4, 1, 6])

node = onnx.helper.make_node('ReduceSum',
inputs=['x'],
outputs=['y'],
axes=[2],
keepdims=0)

return ([node], [x], [y])


@onnx_test()
def reducesum_empty_axes_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 4, 5, 6])
Expand Down Expand Up @@ -9161,6 +9265,20 @@ def sin_test():
return ([node], [x], [y])


@onnx_test()
def sin_fp8_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT8E4M3FNUZ, [10])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT8E4M3FNUZ, [10])

node = onnx.helper.make_node(
'Sin',
inputs=['x'],
outputs=['y'],
)

return ([node], [x], [y])


@onnx_test()
def sinh_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [10])
Expand Down Expand Up @@ -10010,6 +10128,20 @@ def sqrt_test():
return ([node], [x], [y])


@onnx_test()
def sqrt_fp8_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT8E4M3FNUZ, [10, 15])
y = helper.make_tensor_value_info('y', TensorProto.FLOAT8E4M3FNUZ, [10, 15])

node = onnx.helper.make_node(
'Sqrt',
inputs=['x'],
outputs=['y'],
)

return ([node], [x], [y])


@onnx_test()
def squeeze_axes_input_test():
x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [3, 1, 5, 1])
Expand Down
15 changes: 15 additions & 0 deletions test/onnx/globalavgpool_fp8_test.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
 globalavgpool_fp8_test:m

01"GlobalAveragePoolglobalavgpool_fp8_testZ
0




b
1




B
15 changes: 15 additions & 0 deletions test/onnx/globalmaxpool_fp8_test.onnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
 globalmaxpool_fp8_test:i

01"GlobalMaxPoolglobalmaxpool_fp8_testZ
0




b
1




B
Expand Down
53 changes: 53 additions & 0 deletions test/onnx/parse/binary_dyn_brcst_mul_fp8_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 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 <onnx_test.hpp>

TEST_CASE(binary_dyn_brcst_mul_fp8_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto l0 = mm->add_parameter(
"0", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {{1, 4}, {3, 3}, {4, 4}, {5, 5}}});
auto l1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {4, 1}});

auto bl0 = mm->add_instruction(
migraphx::make_op("multibroadcast",
{{"out_dyn_dims", to_value(l0->get_shape().dyn_dims())}}),
l0,
l1);
auto bl1 = mm->add_instruction(
migraphx::make_op("multibroadcast",
{{"out_dyn_dims", to_value(l0->get_shape().dyn_dims())}}),
l1,
bl0);
auto ret = mm->add_instruction(migraphx::make_op("mul"), bl0, bl1);
mm->add_return({ret});

migraphx::onnx_options options;
options.default_dyn_dim_value = {1, 4};
auto prog = migraphx::parse_onnx("binary_dyn_brcst_mul_fp8_test.onnx", options);

EXPECT(p == prog);
}
36 changes: 36 additions & 0 deletions test/onnx/parse/cos_fp8_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 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 <onnx_test.hpp>

TEST_CASE(cos_fp8_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto input = mm->add_parameter("x", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {10}});
mm->add_instruction(migraphx::make_op("cos"), input);

auto prog = optimize_onnx("cos_fp8_test.onnx");
EXPECT(p == prog);
}
39 changes: 39 additions & 0 deletions test/onnx/parse/div_fp8_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 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 <onnx_test.hpp>

TEST_CASE(div_fp8_test)
{
migraphx::program p;
auto* mm = p.get_main_module();
auto p0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {2, 3}});
auto p1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {2, 3}});

mm->add_instruction(migraphx::make_op("div"), p0, p1);

auto prog = optimize_onnx("div_fp8_test.onnx");

EXPECT(p == prog);
}
Loading

0 comments on commit 21c00e7

Please sign in to comment.