|  | 
|  | 1 | +/* | 
|  | 2 | + * The MIT License (MIT) | 
|  | 3 | + * | 
|  | 4 | + * Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved. | 
|  | 5 | + * | 
|  | 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | 
|  | 7 | + * of this software and associated documentation files (the "Software"), to deal | 
|  | 8 | + * in the Software without restriction, including without limitation the rights | 
|  | 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
|  | 10 | + * copies of the Software, and to permit persons to whom the Software is | 
|  | 11 | + * furnished to do so, subject to the following conditions: | 
|  | 12 | + * | 
|  | 13 | + * The above copyright notice and this permission notice shall be included in | 
|  | 14 | + * all copies or substantial portions of the Software. | 
|  | 15 | + * | 
|  | 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
|  | 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
|  | 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE | 
|  | 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
|  | 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
|  | 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
|  | 22 | + * THE SOFTWARE. | 
|  | 23 | + */ | 
|  | 24 | + | 
|  | 25 | +#include <onnx_test.hpp> | 
|  | 26 | + | 
|  | 27 | +/* IR for the test case below: | 
|  | 28 | +module: "main" | 
|  | 29 | +@0 = @literal{0.333008, 0.333008} -> half_type, {1, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 30 | +@1 = @literal{0.5, 0.5, 0.5, 0.5} -> half_type, {2, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 31 | +@2 = @literal{0, 2, 4, 6, 1, 3, 5, 7} -> int32_type, {4, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 32 | +X = @param:X -> half_type, {1, 1, 2, 4}, {8, 8, 4, 1} | 
|  | 33 | +@4 = @literal{1, 1, 0.600098, 0.5} -> half_type, {4}, {1} | 
|  | 34 | +@5 = undefined -> float_type, {}, {} | 
|  | 35 | +@6 = reshape[dims={8}](X) -> half_type, {8}, {1} | 
|  | 36 | +@7 = gather[axis=0](@6,@2) -> half_type, {4, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 37 | +@8 = slice[axes={0},starts={0},ends={2}](@7) -> half_type, {2, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 38 | +@9 = slice[axes={0},starts={2},ends={4}](@7) -> half_type, {2, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 39 | +@10 = sub(@9,@8) -> half_type, {2, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 40 | +@11 = mul(@10,@1) -> half_type, {2, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 41 | +@12 = add(@11,@8) -> half_type, {2, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 42 | +@13 = slice[axes={0},starts={0},ends={1}](@12) -> half_type, {1, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 43 | +@14 = slice[axes={0},starts={1},ends={2}](@12) -> half_type, {1, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 44 | +@15 = sub(@14,@13) -> half_type, {1, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 45 | +@16 = mul(@15,@0) -> half_type, {1, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 46 | +@17 = add(@16,@13) -> half_type, {1, 1, 1, 2}, {2, 2, 2, 1} | 
|  | 47 | +@18 = @return(@17) | 
|  | 48 | +*/ | 
|  | 49 | + | 
|  | 50 | +TEST_CASE(resize_downsample_linear_half_test) | 
|  | 51 | +{ | 
|  | 52 | +    using migraphx::half; | 
|  | 53 | +    migraphx::program p; | 
|  | 54 | +    auto* mm = p.get_main_module(); | 
|  | 55 | +    migraphx::shape ss{migraphx::shape::half_type, {4}}; | 
|  | 56 | +    std::vector<half> ds = {half{1}, half{1}, half{0.60009765625}, half{0.5}}; | 
|  | 57 | +    mm->add_literal(migraphx::literal(ss, ds)); | 
|  | 58 | + | 
|  | 59 | +    migraphx::shape sx{migraphx::shape::half_type, {1, 1, 2, 4}}; | 
|  | 60 | +    auto x = mm->add_parameter("X", sx); | 
|  | 61 | + | 
|  | 62 | +    migraphx::shape s_ind{migraphx::shape::int32_type, {4, 1, 1, 2}}; | 
|  | 63 | +    std::vector<int> d_ind = {0, 2, 4, 6, 1, 3, 5, 7}; | 
|  | 64 | +    auto l_ind             = mm->add_literal(migraphx::literal(s_ind, d_ind)); | 
|  | 65 | + | 
|  | 66 | +    migraphx::shape s2{migraphx::shape::half_type, {2, 1, 1, 2}}; | 
|  | 67 | +    std::vector<float> d2(4, 0.5f); | 
|  | 68 | +    auto l2 = mm->add_literal(migraphx::literal(s2, d2)); | 
|  | 69 | + | 
|  | 70 | +    migraphx::shape s1{migraphx::shape::half_type, {1, 1, 1, 2}}; | 
|  | 71 | +    std::vector<float> d1(2, 0.5 / 0.60009765625 - 0.5); | 
|  | 72 | +    auto l1 = mm->add_literal(migraphx::literal(s1, d1)); | 
|  | 73 | + | 
|  | 74 | +    mm->add_instruction(migraphx::make_op("undefined")); | 
|  | 75 | + | 
|  | 76 | +    auto rsp   = mm->add_instruction(migraphx::make_op("reshape", {{"dims", {8}}}), x); | 
|  | 77 | +    auto data  = mm->add_instruction(migraphx::make_op("gather", {{"axis", 0}}), rsp, l_ind); | 
|  | 78 | +    auto slc20 = mm->add_instruction( | 
|  | 79 | +        migraphx::make_op("slice", {{"axes", {0}}, {"starts", {0}}, {"ends", {2}}}), data); | 
|  | 80 | +    auto slc21 = mm->add_instruction( | 
|  | 81 | +        migraphx::make_op("slice", {{"axes", {0}}, {"starts", {2}}, {"ends", {4}}}), data); | 
|  | 82 | +    auto diff2 = mm->add_instruction(migraphx::make_op("sub"), slc21, slc20); | 
|  | 83 | +    auto mul2  = mm->add_instruction(migraphx::make_op("mul"), diff2, l2); | 
|  | 84 | +    auto add2  = mm->add_instruction(migraphx::make_op("add"), mul2, slc20); | 
|  | 85 | + | 
|  | 86 | +    auto slc10 = mm->add_instruction( | 
|  | 87 | +        migraphx::make_op("slice", {{"axes", {0}}, {"starts", {0}}, {"ends", {1}}}), add2); | 
|  | 88 | +    auto slc11 = mm->add_instruction( | 
|  | 89 | +        migraphx::make_op("slice", {{"axes", {0}}, {"starts", {1}}, {"ends", {2}}}), add2); | 
|  | 90 | +    auto diff1 = mm->add_instruction(migraphx::make_op("sub"), slc11, slc10); | 
|  | 91 | +    auto mul1  = mm->add_instruction(migraphx::make_op("mul"), diff1, l1); | 
|  | 92 | +    auto add1  = mm->add_instruction(migraphx::make_op("add"), mul1, slc10); | 
|  | 93 | +    mm->add_return({add1}); | 
|  | 94 | + | 
|  | 95 | +    auto prog = read_onnx("resize_downsample_linear_half_test.onnx"); | 
|  | 96 | +    EXPECT(p == prog); | 
|  | 97 | +} | 
0 commit comments