output_alias.cpp 2.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015-2022 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.
 */
Paul's avatar
Paul committed
24
25
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
Paul's avatar
Paul committed
26
27
28
#include <test.hpp>
#include <basic_ops.hpp>

Paul's avatar
Paul committed
29
TEST_CASE(simple_alias)
Paul's avatar
Paul committed
30
{
Paul's avatar
Paul committed
31
    migraphx::program p;
32
33
34
    auto* mm = p.get_main_module();
    auto l   = mm->add_literal(1);
    auto p1  = mm->add_instruction(pass_op{}, l);
Paul's avatar
Paul committed
35
36
    EXPECT(bool{migraphx::instruction::get_output_alias(l) == l});
    EXPECT(bool{migraphx::instruction::get_output_alias(p1) == l});
Paul's avatar
Paul committed
37
38
}

Paul's avatar
Paul committed
39
TEST_CASE(cascade_alias)
Paul's avatar
Paul committed
40
{
Paul's avatar
Paul committed
41
    migraphx::program p;
42
43
44
45
46
    auto* mm = p.get_main_module();
    auto l   = mm->add_literal(1);
    auto p1  = mm->add_instruction(pass_op{}, l);
    auto p2  = mm->add_instruction(pass_op{}, p1);
    auto p3  = mm->add_instruction(pass_op{}, p2);
Paul's avatar
Paul committed
47
48
49
50
    EXPECT(bool{migraphx::instruction::get_output_alias(l) == l});
    EXPECT(bool{migraphx::instruction::get_output_alias(p1) == l});
    EXPECT(bool{migraphx::instruction::get_output_alias(p2) == l});
    EXPECT(bool{migraphx::instruction::get_output_alias(p3) == l});
Paul's avatar
Paul committed
51
52
}

Paul's avatar
Paul committed
53
TEST_CASE(no_alias)
Paul's avatar
Paul committed
54
{
Paul's avatar
Paul committed
55
    migraphx::program p;
56
57
58
59
    auto* mm = p.get_main_module();
    auto x   = mm->add_literal(1);
    auto y   = mm->add_literal(2);
    auto sum = mm->add_instruction(sum_op{}, x, y);
Paul's avatar
Paul committed
60
    EXPECT(bool{migraphx::instruction::get_output_alias(sum) == sum});
Paul's avatar
Paul committed
61
62
}

Paul's avatar
Paul committed
63
int main(int argc, const char* argv[]) { test::run(argc, argv); }