diff --git a/test/onnx/add_fp8_test.onnx b/test/onnx/add_fp8_test.onnx new file mode 100644 index 00000000000..734d503c79f --- /dev/null +++ b/test/onnx/add_fp8_test.onnx @@ -0,0 +1,16 @@ +  add_fp8_test:Q + +0 +12"Add add_fp8_testZ +0 + + +Z +1 + + +b +2 + + +B \ No newline at end of file diff --git a/test/onnx/binary_dyn_brcst_mul_fp8_test.onnx b/test/onnx/binary_dyn_brcst_mul_fp8_test.onnx new file mode 100644 index 00000000000..80178a7ed4e Binary files /dev/null and b/test/onnx/binary_dyn_brcst_mul_fp8_test.onnx differ diff --git a/test/onnx/conv_1d_fp8_test.onnx b/test/onnx/conv_1d_fp8_test.onnx new file mode 100644 index 00000000000..a6b910da71d --- /dev/null +++ b/test/onnx/conv_1d_fp8_test.onnx @@ -0,0 +1,19 @@ + conv_1d_fp8_test:n + +0 +12"Convconv_1d_fp8_testZ +0 + + + +Z +1 + + + +b +2 + + + +B \ No newline at end of file diff --git a/test/onnx/cos_fp8_test.onnx b/test/onnx/cos_fp8_test.onnx new file mode 100644 index 00000000000..d494bc558f5 --- /dev/null +++ b/test/onnx/cos_fp8_test.onnx @@ -0,0 +1,13 @@ +  cos_fp8_test:= + +xy"Cos cos_fp8_testZ +x + + + +b +y + + + +B \ No newline at end of file diff --git a/test/onnx/div_fp8_test.onnx b/test/onnx/div_fp8_test.onnx new file mode 100644 index 00000000000..4eb4923a296 --- /dev/null +++ b/test/onnx/div_fp8_test.onnx @@ -0,0 +1,16 @@ +  div_fp8_test:a + +0 +1out"Div div_fp8_testZ +0 +  + +Z +1 +  + +b +out +  + +B \ No newline at end of file diff --git a/test/onnx/gemm_fp8_test.onnx b/test/onnx/gemm_fp8_test.onnx new file mode 100644 index 00000000000..effebfeaa37 Binary files /dev/null and b/test/onnx/gemm_fp8_test.onnx differ diff --git a/test/onnx/gen_onnx.py b/test/onnx/gen_onnx.py index 641714e5af4..cf489c9d267 100644 --- a/test/onnx/gen_onnx.py +++ b/test/onnx/gen_onnx.py @@ -124,6 +124,21 @@ def add_fp16_test(): ]) +@onnx_test() +def add_fp8_test(): + x = helper.make_tensor_value_info('0', TensorProto.FLOAT8E4M3FNUZ, [1]) + y = helper.make_tensor_value_info('1', TensorProto.FLOAT8E4M3FNUZ, [1]) + z = helper.make_tensor_value_info('2', TensorProto.FLOAT8E4M3FNUZ, [1]) + + node = onnx.helper.make_node( + 'Add', + inputs=['0', '1'], + outputs=['2'], + ) + + return ([node], [x, y], [z]) + + @onnx_test() def add_scalar_test(): x = helper.make_tensor_value_info('0', TensorProto.UINT8, [2, 3, 4, 5]) @@ -618,6 +633,42 @@ 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]) @@ -1252,6 +1303,20 @@ def conv_3d_test(): return ([node], [x, y], [out]) +@onnx_test() +def conv_1d_fp8_test(): + x = helper.make_tensor_value_info('0', TensorProto.FLOAT8E4M3FNUZ, + [1, 3, 5]) + y = helper.make_tensor_value_info('1', TensorProto.FLOAT8E4M3FNUZ, + [1, 3, 3]) + out = helper.make_tensor_value_info('2', TensorProto.FLOAT8E4M3FNUZ, + [1, 1, 3]) + + node = onnx.helper.make_node('Conv', inputs=['0', '1'], outputs=['2']) + + return ([node], [x, y], [out]) + + @onnx_test() def conv_attr_fail_test(): x = helper.make_tensor_value_info('0', TensorProto.FLOAT, [1, 3, 5]) @@ -1688,6 +1753,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]) @@ -3626,6 +3705,23 @@ def gemm_half_test(): return ([node], [A, B, C], [Y]) +@onnx_test() +def gemm_fp8_test(): + A = helper.make_tensor_value_info('A', TensorProto.FLOAT8E4M3FNUZ, [8, 6]) + B = helper.make_tensor_value_info('B', TensorProto.FLOAT8E4M3FNUZ, [8, 7]) + C = helper.make_tensor_value_info('C', TensorProto.FLOAT8E4M3FNUZ, [6, 1]) + Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT8E4M3FNUZ, [6, 7]) + + node = onnx.helper.make_node('Gemm', + inputs=['A', 'B', 'C'], + outputs=['Y'], + alpha=0.5, + beta=0.8, + transA=1) + + return ([node], [A, B, C], [Y]) + + @onnx_test() def gemm_dyn_inner_test(): A = helper.make_tensor_value_info('A', TensorProto.FLOAT, [None, 6]) @@ -3705,6 +3801,22 @@ 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, @@ -3763,6 +3875,22 @@ 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, @@ -8610,6 +8738,24 @@ 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]) @@ -8699,6 +8845,22 @@ 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]) @@ -9962,6 +10124,22 @@ def shrink_int8_test(): return ([node], [x], [y]) +@onnx_test() +def shrink_fp8_test(): + x = helper.make_tensor_value_info('x', TensorProto.FLOAT8E4M3FNUZ, [3, 3]) + y = helper.make_tensor_value_info('y', TensorProto.FLOAT8E4M3FNUZ, [3, 3]) + + node = onnx.helper.make_node( + "Shrink", + inputs=["x"], + outputs=["y"], + lambd=1.5, + bias=1.5, + ) + + return ([node], [x], [y]) + + @onnx_test() def shrink_uint8_test(): x = helper.make_tensor_value_info('x', TensorProto.UINT8, [3, 3]) @@ -10006,6 +10184,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]) @@ -10070,6 +10262,19 @@ def size_int_test(): return ([node], [x], [y]) +@onnx_test() +def size_fp8_test(): + x = helper.make_tensor_value_info('x', TensorProto.FLOAT8E4M3FNUZ, + [2, 5, 3]) + y = helper.make_tensor_value_info('y', TensorProto.INT64, [1]) + node = onnx.helper.make_node( + 'Size', + inputs=['x'], + outputs=['y'], + ) + return ([node], [x], [y]) + + @onnx_test() def size_verify_test(): x = helper.make_tensor_value_info('x', TensorProto.FLOAT, [2, 5, 3]) @@ -10913,6 +11118,22 @@ 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]) diff --git a/test/onnx/globalavgpool_fp8_test.onnx b/test/onnx/globalavgpool_fp8_test.onnx new file mode 100644 index 00000000000..206578ab2c6 --- /dev/null +++ b/test/onnx/globalavgpool_fp8_test.onnx @@ -0,0 +1,15 @@ + globalavgpool_fp8_test:m + +01"GlobalAveragePoolglobalavgpool_fp8_testZ +0 + + + + +b +1 + + + + +B \ No newline at end of file diff --git a/test/onnx/globalmaxpool_fp8_test.onnx b/test/onnx/globalmaxpool_fp8_test.onnx new file mode 100644 index 00000000000..9d476245147 --- /dev/null +++ b/test/onnx/globalmaxpool_fp8_test.onnx @@ -0,0 +1,15 @@ + globalmaxpool_fp8_test:i + +01" GlobalMaxPoolglobalmaxpool_fp8_testZ +0 + + + + +b +1 + + + + +B \ No newline at end of file diff --git a/test/onnx/parse/add_fp8_test.cpp b/test/onnx/parse/add_fp8_test.cpp new file mode 100644 index 00000000000..f41deb4b289 --- /dev/null +++ b/test/onnx/parse/add_fp8_test.cpp @@ -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 + +TEST_CASE(add_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto p0 = mm->add_parameter("0", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {1}}); + auto p1 = mm->add_parameter("1", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {1}}); + + mm->add_instruction(migraphx::make_op("add"), p0, p1); + + auto prog = optimize_onnx("add_fp8_test.onnx"); + + EXPECT(p == prog); +} diff --git a/test/onnx/parse/binary_dyn_brcst_mul_fp8_test.cpp b/test/onnx/parse/binary_dyn_brcst_mul_fp8_test.cpp new file mode 100644 index 00000000000..3c31c86184e --- /dev/null +++ b/test/onnx/parse/binary_dyn_brcst_mul_fp8_test.cpp @@ -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 + +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 = read_onnx("binary_dyn_brcst_mul_fp8_test.onnx", options); + + EXPECT(p == prog); +} diff --git a/test/onnx/parse/conv_1d_fp8_test.cpp b/test/onnx/parse/conv_1d_fp8_test.cpp new file mode 100644 index 00000000000..d28abe6987b --- /dev/null +++ b/test/onnx/parse/conv_1d_fp8_test.cpp @@ -0,0 +1,40 @@ +/* + * 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 + +TEST_CASE(conv_1d_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto l0 = mm->add_parameter("0", {migraphx::shape::fp8e4m3fnuz_type, {1, 3, 5}}); + auto l1 = mm->add_parameter("1", {migraphx::shape::fp8e4m3fnuz_type, {1, 3, 3}}); + mm->add_instruction( + migraphx::make_op("convolution", {{"padding", {0}}, {"stride", {1}}, {"dilation", {1}}}), + l0, + l1); + + auto prog = optimize_onnx("conv_1d_fp8_test.onnx"); + EXPECT(p == prog); +} diff --git a/test/onnx/parse/cos_fp8_test.cpp b/test/onnx/parse/cos_fp8_test.cpp new file mode 100644 index 00000000000..409f0fa7d6f --- /dev/null +++ b/test/onnx/parse/cos_fp8_test.cpp @@ -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 + +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); +} diff --git a/test/onnx/parse/div_fp8_test.cpp b/test/onnx/parse/div_fp8_test.cpp new file mode 100644 index 00000000000..b3216421793 --- /dev/null +++ b/test/onnx/parse/div_fp8_test.cpp @@ -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 + +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); +} diff --git a/test/onnx/parse/gemm_fp8_test.cpp b/test/onnx/parse/gemm_fp8_test.cpp new file mode 100644 index 00000000000..54554d54420 --- /dev/null +++ b/test/onnx/parse/gemm_fp8_test.cpp @@ -0,0 +1,54 @@ +/* + * 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 +#include + +TEST_CASE(gemm_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto l0 = mm->add_parameter("A", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {8, 6}}); + auto l1 = mm->add_parameter("B", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {8, 7}}); + auto l2 = mm->add_parameter("C", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {6, 1}}); + + auto alpha = 0.5f; + auto beta = 0.8f; + auto a_l = mm->add_literal(alpha); + auto t_a = add_common_op(*mm, migraphx::make_op("mul"), {a_l, l0}); + t_a = mm->add_instruction( + migraphx::make_op("convert", {{"target_type", migraphx::shape::fp8e4m3fnuz_type}}), t_a); + t_a = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {1, 0}}}), t_a); + std::vector lens = {6, 7}; + auto dot = mm->add_instruction(migraphx::make_op("dot"), t_a, l1); + l2 = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), l2); + auto b_l = mm->add_literal(beta); + auto l2_b = add_common_op(*mm, migraphx::make_op("mul"), {l2, b_l}); + l2_b = mm->add_instruction( + migraphx::make_op("convert", {{"target_type", migraphx::shape::fp8e4m3fnuz_type}}), l2_b); + mm->add_instruction(migraphx::make_op("add"), dot, l2_b); + + auto prog = optimize_onnx("gemm_fp8_test.onnx"); + EXPECT(p == prog); +} diff --git a/test/onnx/parse/globalavgpool_fp8_test.cpp b/test/onnx/parse/globalavgpool_fp8_test.cpp new file mode 100644 index 00000000000..62c54ab4236 --- /dev/null +++ b/test/onnx/parse/globalavgpool_fp8_test.cpp @@ -0,0 +1,43 @@ +/* + * 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 +#include + +TEST_CASE(globalavgpool_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto input = + mm->add_parameter("0", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {1, 3, 16, 16}}); + auto op = migraphx::op::pooling{migraphx::op::pooling_mode::average}; + auto lens = input->get_shape().lens(); + op.lengths = {lens[2], lens[3]}; + op.padding = {0, 0, 0, 0}; + mm->add_instruction(op, input); + + auto prog = optimize_onnx("globalavgpool_fp8_test.onnx"); + + EXPECT(p == prog); +} diff --git a/test/onnx/parse/globalmaxpool_fp8_test.cpp b/test/onnx/parse/globalmaxpool_fp8_test.cpp new file mode 100644 index 00000000000..a11873970f5 --- /dev/null +++ b/test/onnx/parse/globalmaxpool_fp8_test.cpp @@ -0,0 +1,43 @@ +/* + * 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 +#include + +TEST_CASE(globalmaxpool_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto input = + mm->add_parameter("0", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {1, 3, 16, 16}}); + auto op = migraphx::op::pooling{migraphx::op::pooling_mode::max}; + auto lens = input->get_shape().lens(); + op.lengths = {lens[2], lens[3]}; + op.padding = {0, 0, 0, 0}; + mm->add_instruction(op, input); + + auto prog = optimize_onnx("globalmaxpool_fp8_test.onnx"); + + EXPECT(p == prog); +} diff --git a/test/onnx/parse/reducemax_fp8_test.cpp b/test/onnx/parse/reducemax_fp8_test.cpp new file mode 100644 index 00000000000..bcb2f660bb6 --- /dev/null +++ b/test/onnx/parse/reducemax_fp8_test.cpp @@ -0,0 +1,38 @@ +/* + * 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 + +TEST_CASE(reducemax_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto l0 = + mm->add_parameter("x", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {3, 4, 5, 6}}); + auto l1 = mm->add_instruction(migraphx::make_op("reduce_max", {{"axes", {2}}}), l0); + mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {2}}}), l1); + auto prog = optimize_onnx("reducemax_fp8_test.onnx"); + + EXPECT(p == prog); +} diff --git a/test/onnx/parse/reducesum_fp8_test.cpp b/test/onnx/parse/reducesum_fp8_test.cpp new file mode 100644 index 00000000000..b446d8e78af --- /dev/null +++ b/test/onnx/parse/reducesum_fp8_test.cpp @@ -0,0 +1,38 @@ +/* + * 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 + +TEST_CASE(reducesum_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto l0 = + mm->add_parameter("x", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {3, 4, 5, 6}}); + auto l1 = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {2}}}), l0); + mm->add_instruction(migraphx::make_op("squeeze", {{"axes", {2}}}), l1); + auto prog = optimize_onnx("reducesum_fp8_test.onnx"); + + EXPECT(p == prog); +} diff --git a/test/onnx/parse/shrink_fp8_test.cpp b/test/onnx/parse/shrink_fp8_test.cpp new file mode 100644 index 00000000000..76f51601805 --- /dev/null +++ b/test/onnx/parse/shrink_fp8_test.cpp @@ -0,0 +1,55 @@ +/* + * 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 + +TEST_CASE(shrink_fp8_test) +{ + migraphx::program p; + float bias = 1.5; + float lambd = 1.5; + std::vector lens{3, 3}; + auto* mm = p.get_main_module(); + auto x = mm->add_parameter("x", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, lens}); + auto lit_bias = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {bias}}); + auto lit_neg_lambd = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {-lambd}}); + auto lit_lambd = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {lambd}}); + + auto x_plus_bias = add_common_op(*mm, migraphx::make_op("add"), {x, lit_bias}); + auto x_min_bias = add_common_op(*mm, migraphx::make_op("sub"), {x, lit_bias}); + + auto cond1 = add_common_op(*mm, migraphx::make_op("less"), {x, lit_neg_lambd}); + auto cond2_a = add_common_op(*mm, migraphx::make_op("not"), {cond1}); + auto cond2_b = add_common_op(*mm, migraphx::make_op("greater"), {x, lit_lambd}); + auto cond2 = add_common_op(*mm, migraphx::make_op("logical_and"), {cond2_a, cond2_b}); + + auto first = add_common_op(*mm, migraphx::make_op("mul"), {cond1, x_plus_bias}); + auto second = add_common_op(*mm, migraphx::make_op("mul"), {cond2, x_min_bias}); + auto ret = add_common_op(*mm, migraphx::make_op("add"), {first, second}); + mm->add_instruction( + migraphx::make_op("convert", {{"target_type", migraphx::shape::fp8e4m3fnuz_type}}), ret); + auto prog = optimize_onnx("shrink_fp8_test.onnx"); + + EXPECT(p == prog); +} diff --git a/test/onnx/parse/sin_fp8_test.cpp b/test/onnx/parse/sin_fp8_test.cpp new file mode 100644 index 00000000000..dc006f036f3 --- /dev/null +++ b/test/onnx/parse/sin_fp8_test.cpp @@ -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 + +TEST_CASE(sin_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("sin"), input); + + auto prog = optimize_onnx("sin_fp8_test.onnx"); + EXPECT(p == prog); +} diff --git a/test/onnx/parse/size_fp8_test.cpp b/test/onnx/parse/size_fp8_test.cpp new file mode 100644 index 00000000000..76412b92181 --- /dev/null +++ b/test/onnx/parse/size_fp8_test.cpp @@ -0,0 +1,37 @@ +/* + * 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 + +TEST_CASE(size_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto s = migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {2, 5, 3}}; + mm->add_parameter("x", s); + mm->add_literal(migraphx::literal{migraphx::shape::int64_type, {s.elements()}}); + + auto prog = optimize_onnx("size_fp8_test.onnx"); + EXPECT(p == prog); +} diff --git a/test/onnx/parse/sqrt_fp8_test.cpp b/test/onnx/parse/sqrt_fp8_test.cpp new file mode 100644 index 00000000000..4345f50cb75 --- /dev/null +++ b/test/onnx/parse/sqrt_fp8_test.cpp @@ -0,0 +1,37 @@ +/* + * 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 + +TEST_CASE(sqrt_fp8_test) +{ + migraphx::program p; + auto* mm = p.get_main_module(); + auto input = + mm->add_parameter("x", migraphx::shape{migraphx::shape::fp8e4m3fnuz_type, {10, 15}}); + mm->add_instruction(migraphx::make_op("sqrt"), input); + + auto prog = optimize_onnx("sqrt_fp8_test.onnx"); + EXPECT(p == prog); +} diff --git a/test/onnx/reducemax_fp8_test.onnx b/test/onnx/reducemax_fp8_test.onnx new file mode 100644 index 00000000000..e5bd763dd13 Binary files /dev/null and b/test/onnx/reducemax_fp8_test.onnx differ diff --git a/test/onnx/reducesum_fp8_test.onnx b/test/onnx/reducesum_fp8_test.onnx new file mode 100644 index 00000000000..d4ddd628e75 Binary files /dev/null and b/test/onnx/reducesum_fp8_test.onnx differ diff --git a/test/onnx/shrink_fp8_test.onnx b/test/onnx/shrink_fp8_test.onnx new file mode 100644 index 00000000000..28f5f1a81d0 Binary files /dev/null and b/test/onnx/shrink_fp8_test.onnx differ diff --git a/test/onnx/sin_fp8_test.onnx b/test/onnx/sin_fp8_test.onnx new file mode 100644 index 00000000000..8225aa0e004 --- /dev/null +++ b/test/onnx/sin_fp8_test.onnx @@ -0,0 +1,13 @@ +  sin_fp8_test:= + +xy"Sin sin_fp8_testZ +x + + + +b +y + + + +B \ No newline at end of file diff --git a/test/onnx/size_fp8_test.onnx b/test/onnx/size_fp8_test.onnx new file mode 100644 index 00000000000..645302bba12 --- /dev/null +++ b/test/onnx/size_fp8_test.onnx @@ -0,0 +1,12 @@ +  size_fp8_test:G + +xy"Size size_fp8_testZ +x + + + +b +y + + +B \ No newline at end of file diff --git a/test/onnx/sqrt_fp8_test.onnx b/test/onnx/sqrt_fp8_test.onnx new file mode 100644 index 00000000000..9046a520423 --- /dev/null +++ b/test/onnx/sqrt_fp8_test.onnx @@ -0,0 +1,13 @@ +  sqrt_fp8_test:G + +xy"Sqrt sqrt_fp8_testZ +x +  + + +b +y +  + + +B \ No newline at end of file diff --git a/test/onnx/verify/add_fp8_test.cpp b/test/onnx/verify/add_fp8_test.cpp new file mode 100644 index 00000000000..0ef99140c44 --- /dev/null +++ b/test/onnx/verify/add_fp8_test.cpp @@ -0,0 +1,49 @@ +/* + * 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 +#include +#include +#include + +TEST_CASE(add_fp8_test) +{ + auto p = optimize_onnx("add_fp8_test.onnx"); + p.compile(migraphx::make_target("ref")); + + migraphx::shape s{migraphx::shape::fp8e4m3fnuz_type, {1}}; + + migraphx::parameter_map pp; + migraphx::literal l1{s, {3.25}}; + migraphx::literal l2{s, {2.25}}; + pp["0"] = l1.get_argument(); + pp["1"] = l2.get_argument(); + + auto result = p.eval(pp).back(); + std::vector result_vector; + result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); + std::vector gold{static_cast(5.5)}; + + EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); +} diff --git a/test/onnx/verify/gemm_fp8_test.cpp b/test/onnx/verify/gemm_fp8_test.cpp new file mode 100644 index 00000000000..b5aa56d99f0 --- /dev/null +++ b/test/onnx/verify/gemm_fp8_test.cpp @@ -0,0 +1,72 @@ +/* + * 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 +#include +#include +#include + +TEST_CASE(gemm_fp8_test) +{ + migraphx::program p = optimize_onnx("gemm_fp8_test.onnx"); + p.compile(migraphx::make_target("ref")); + + migraphx::shape a_shape{migraphx::shape::fp8e4m3fnuz_type, {8, 6}}; + std::vector tmp = {0.2646, 0.8525, 0.4192, 0.1415, 0.4321, 0.675, 0.4248, 0.8203, + 0.978, 0.5796, 0.6626, 0.479, 0.924, 0.734, 0.674, 0.8716, + 0.3733, 0.3328, 0.4272, 0.0247, 0.7583, 0.4873, 0.5835, 0.694, + 0.4375, 0.2406, 0.269, 0.6763, 0.542, 0.8994, 0.657, 0.5425, + 0.1412, 0.8994, 0.2183, 0.812, 0.937, 0.3438, 0.712, 0.9033, + 0.266, 0.8013, 0.803, 0.4993, 0.07196, 0.635, 0.7344, 0.3213}; + std::vector a_data{tmp.cbegin(), tmp.cend()}; + + migraphx::shape b_shape{migraphx::shape::fp8e4m3fnuz_type, {8, 7}}; + tmp = {0.7095, 0.612, 0.741, 0.02121, 0.3872, 0.4482, 0.6235, 0.02249, 0.2332, 0.7656, + 0.8955, 0.8154, 0.2239, 0.9277, 0.4622, 0.708, 0.566, 0.0736, 0.138, 0.8574, + 0.4055, 0.382, 0.6206, 0.424, 0.3674, 0.435, 0.998, 0.3594, 0.701, 0.6216, + 0.01826, 0.6313, 0.514, 0.1095, 0.3203, 0.01636, 0.537, 0.01952, 0.4502, 0.8965, + 0.5415, 0.7456, 0.793, 0.756, 0.9, 0.5264, 0.05368, 0.4214, 0.276, 0.1517, + 0.08453, 0.83, 0.417, 0.1682, 0.845, 0.1729}; + std::vector b_data{tmp.cbegin(), tmp.cend()}; + + migraphx::shape c_shape{migraphx::shape::fp8e4m3fnuz_type, {6, 1}}; + tmp = {0.10846, 0.672, 0.527, 0.94, 0.429, 0.2291}; + std::vector c_data{tmp.cbegin(), tmp.cend()}; + + migraphx::parameter_map params; + params["A"] = migraphx::argument(a_shape, a_data.data()); + params["B"] = migraphx::argument(b_shape, b_data.data()); + params["C"] = migraphx::argument(c_shape, c_data.data()); + + auto result = p.eval(params).back(); + std::vector result_vector; + result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); + + tmp = {1.071, 1.378, 1.465, 1.093, 0.968, 1.542, 1.145, 1.287, 1.533, 1.75, 1.338, + 1.449, 1.592, 1.668, 1.265, 1.531, 1.656, 1.348, 1.2705, 1.525, 1.479, 1.754, + 2.143, 2.062, 1.921, 1.836, 2.203, 1.952, 1.055, 1.225, 1.418, 1.209, 1.155, + 1.42, 1.234, 1.302, 1.593, 1.368, 1.289, 1.327, 1.451, 1.394}; + std::vector gold{tmp.cbegin(), tmp.cend()}; + EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); +} diff --git a/test/onnx/verify/shrink_fp8_test.cpp b/test/onnx/verify/shrink_fp8_test.cpp new file mode 100644 index 00000000000..b1f541e415b --- /dev/null +++ b/test/onnx/verify/shrink_fp8_test.cpp @@ -0,0 +1,50 @@ +/* + * 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 +#include +#include +#include + +TEST_CASE(shrink_fp8_test) +{ + migraphx::program p = optimize_onnx("shrink_fp8_test.onnx"); + p.compile(migraphx::make_target("ref")); + + migraphx::shape s{migraphx::shape::fp8e4m3fnuz_type, {3, 3}}; + // TODO: Make FP8 vector work for initializer list. + std::vector tmp_data{-4, -3, -2, -1, 0, 1, 2, 3, 4}; + std::vector data{tmp_data.cbegin(), tmp_data.cend()}; + + migraphx::parameter_map pp; + pp["x"] = migraphx::argument(s, data.data()); + + auto result = p.eval(pp).back(); + std::vector result_vector; + result.visit([&](auto output) { result_vector.assign(output.begin(), output.end()); }); + // TODO: Make FP8 vector work for initializer list. + std::vector tmp_gold = {-2, -1, 0, 0, 0, 0, 0, 1, 2}; + std::vector gold{tmp_gold.cbegin(), tmp_gold.cend()}; + EXPECT(migraphx::verify::verify_rms_range(result_vector, gold)); +} diff --git a/test/onnx/verify/size_fp8_test.cpp b/test/onnx/verify/size_fp8_test.cpp new file mode 100644 index 00000000000..7ae5d1d1647 --- /dev/null +++ b/test/onnx/verify/size_fp8_test.cpp @@ -0,0 +1,43 @@ +/* + * 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 +#include +#include +#include + +TEST_CASE(size_fp8_test) +{ + migraphx::program p = read_onnx("size_fp8_test.onnx"); + p.compile(migraphx::make_target("ref")); + + migraphx::shape s{migraphx::shape::fp8e4m3fnuz_type, {2, 5, 3}}; + std::vector data(30, 1.); + migraphx::parameter_map pp; + pp["x"] = migraphx::argument(s, data.data()); + + auto result = p.eval(pp).back(); + auto size_result = result.at(); + EXPECT(size_result == int64_t{30}); +}