From 307ca7c9964b440d1e4c00835d770a0971f79ad7 Mon Sep 17 00:00:00 2001 From: Ahsan Saghir Date: Mon, 15 Apr 2024 18:56:29 +0000 Subject: [PATCH] FP8 Onnx tests --- test/onnx/add_fp8_test.onnx | 16 ++++++ test/onnx/conv_1d_fp8_test.onnx | 19 +++++++ test/onnx/gemm_fp8_test.onnx | Bin 0 -> 191 bytes test/onnx/gen_onnx.py | 73 +++++++++++++++++++++++++++ test/onnx/parse/add_fp8_test.cpp | 39 ++++++++++++++ test/onnx/parse/conv_1d_fp8_test.cpp | 40 +++++++++++++++ test/onnx/parse/gemm_fp8_test.cpp | 56 ++++++++++++++++++++ test/onnx/parse/shrink_fp8_test.cpp | 60 ++++++++++++++++++++++ test/onnx/parse/size_fp8_test.cpp | 37 ++++++++++++++ test/onnx/shrink_fp8_test.onnx | Bin 0 -> 133 bytes test/onnx/size_fp8_test.onnx | 12 +++++ test/onnx/verify/add_fp8_test.cpp | 49 ++++++++++++++++++ test/onnx/verify/gemm_fp8_test.cpp | 72 ++++++++++++++++++++++++++ test/onnx/verify/shrink_fp8_test.cpp | 63 +++++++++++++++++++++++ test/onnx/verify/size_fp8_test.cpp | 43 ++++++++++++++++ 15 files changed, 579 insertions(+) create mode 100644 test/onnx/add_fp8_test.onnx create mode 100644 test/onnx/conv_1d_fp8_test.onnx create mode 100644 test/onnx/gemm_fp8_test.onnx create mode 100644 test/onnx/parse/add_fp8_test.cpp create mode 100644 test/onnx/parse/conv_1d_fp8_test.cpp create mode 100644 test/onnx/parse/gemm_fp8_test.cpp create mode 100644 test/onnx/parse/shrink_fp8_test.cpp create mode 100644 test/onnx/parse/size_fp8_test.cpp create mode 100644 test/onnx/shrink_fp8_test.onnx create mode 100644 test/onnx/size_fp8_test.onnx create mode 100644 test/onnx/verify/add_fp8_test.cpp create mode 100644 test/onnx/verify/gemm_fp8_test.cpp create mode 100644 test/onnx/verify/shrink_fp8_test.cpp create mode 100644 test/onnx/verify/size_fp8_test.cpp 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/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/gemm_fp8_test.onnx b/test/onnx/gemm_fp8_test.onnx new file mode 100644 index 0000000000000000000000000000000000000000..effebfeaa370893a80bfb57fa751750970a69745 GIT binary patch literal 191 zcmdwehLr92&i-`k- f*+7C$XoBn@L1!dEHlRwzB%oj + +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/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/gemm_fp8_test.cpp b/test/onnx/parse/gemm_fp8_test.cpp new file mode 100644 index 00000000000..e01d0143aa7 --- /dev/null +++ b/test/onnx/parse/gemm_fp8_test.cpp @@ -0,0 +1,56 @@ +/* + * 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 = migraphx::add_apply_alpha_beta(*mm, {t_a, l1}, migraphx::make_op("dot"), 1.0f, 0.0f); + l2 = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), l2); + l2 = mm->add_instruction( + migraphx::make_op("convert", {{"target_type", migraphx::shape::float_type}}), l2); + auto b_l = mm->add_literal(beta); + auto b_b = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", lens}}), b_l); + auto l2_b = mm->add_instruction(migraphx::make_op("mul"), l2, b_b); + 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/shrink_fp8_test.cpp b/test/onnx/parse/shrink_fp8_test.cpp new file mode 100644 index 00000000000..a4cdce940b7 --- /dev/null +++ b/test/onnx/parse/shrink_fp8_test.cpp @@ -0,0 +1,60 @@ +/* + * 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 mul1 = mm->add_instruction( + migraphx::make_op("convert", {{"target_type", migraphx::shape::fp8e4m3fnuz_type}}), cond1); + auto mul2 = mm->add_instruction( + migraphx::make_op("convert", {{"target_type", migraphx::shape::fp8e4m3fnuz_type}}), cond2); + + auto first = add_common_op(*mm, migraphx::make_op("mul"), {mul1, x_plus_bias}); + auto second = add_common_op(*mm, migraphx::make_op("mul"), {mul2, 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/size_fp8_test.cpp b/test/onnx/parse/size_fp8_test.cpp new file mode 100644 index 00000000000..993a82ee25b --- /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::float_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/shrink_fp8_test.onnx b/test/onnx/shrink_fp8_test.onnx new file mode 100644 index 0000000000000000000000000000000000000000..28f5f1a81d0b91db3c1c9ca65d9e1ea122e8069e GIT binary patch literal 133 zcmd +#include +#include +#include + +TEST_CASE(add_fp8_test) +{ + auto p = migraphx::parse_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.0}}; + migraphx::literal l2{s, {2.0}}; + 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 = {5.0}; + + 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..914789c74c2 --- /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 = migraphx::parse_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..3dc3be1e632 --- /dev/null +++ b/test/onnx/verify/shrink_fp8_test.cpp @@ -0,0 +1,63 @@ +/* + * 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 = migraphx::parse_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 data; + data.reserve(9); + // Use std::generate_n to generate values from -4 to 4 + // and push them into the vector + std::generate_n(std::back_inserter(data), 9, [n = -4]() mutable { + return migraphx::fp8::fp8e4m3fnuz(static_cast(n++)); + }); + 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 gold{ + migraphx::fp8::fp8e4m3fnuz(-2), + migraphx::fp8::fp8e4m3fnuz(-1), + migraphx::fp8::fp8e4m3fnuz(0), + migraphx::fp8::fp8e4m3fnuz(0), + migraphx::fp8::fp8e4m3fnuz(0), + migraphx::fp8::fp8e4m3fnuz(0), + migraphx::fp8::fp8e4m3fnuz(0), + migraphx::fp8::fp8e4m3fnuz(1), + migraphx::fp8::fp8e4m3fnuz(2) + }; + 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..ef4567ec36b --- /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 = migraphx::parse_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}); +}