print_graph_test.cpp 2.69 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.
 */
24
25
26
27
28
29
30
31
32
33
#include <migraphx/program.hpp>
#include <migraphx/ranges.hpp>
#include <sstream>
#include "test.hpp"
#include <basic_ops.hpp>

migraphx::program create_program()
{
    migraphx::program p;

34
    auto* mm = p.get_main_module();
35

36
37
38
39
40
41
    auto x = mm->add_parameter("x", {migraphx::shape::int64_type});
    auto y = mm->add_parameter("y", {migraphx::shape::int64_type});

    auto sum = mm->add_instruction(sum_op{}, x, y);
    auto one = mm->add_literal(1);
    mm->add_instruction(sum_op{}, sum, one);
42
43
44
45
46
47
48

    return p;
}

TEST_CASE(basic_graph_test)
{
    migraphx::program p = create_program();
49

50
51
52
    std::stringstream ss;
    p.print_graph(ss);
    std::string test = ss.str();
Shucai Xiao's avatar
Shucai Xiao committed
53
54
    std::cout << "test = " << test << std::endl;

Khalique's avatar
Khalique committed
55
56
    EXPECT(migraphx::contains(test, "digraph"));
    EXPECT(migraphx::contains(test, "rankdir=LR"));
Shucai Xiao's avatar
Shucai Xiao committed
57
    EXPECT(migraphx::contains(test, "\"main:@0\"[label=\"@literal\"]"));
Khalique's avatar
Khalique committed
58
59
    EXPECT(migraphx::contains(test, "\"y\"[label=\"@param:y\"]"));
    EXPECT(migraphx::contains(test, "\"x\"[label=\"@param:x\"]"));
Shucai Xiao's avatar
Shucai Xiao committed
60
61
62
63
64
65
    EXPECT(migraphx::contains(test, "\"main:@3\"[label=\"sum\"]"));
    EXPECT(migraphx::contains(test, "\"main:@4\"[label=\"sum\"]"));
    EXPECT(migraphx::contains(test, "\"x\" -> \"main:@3\""));
    EXPECT(migraphx::contains(test, "\"y\" -> \"main:@3\""));
    EXPECT(migraphx::contains(test, "\"main:@3\" -> \"main:@4\""));
    EXPECT(migraphx::contains(test, "\"main:@0\" -> \"main:@4\""));
Khalique's avatar
Khalique committed
66
    EXPECT(migraphx::contains(test, "[label=\"int64_type, {1}, {0}\"]"));
67
68
69
}

int main(int argc, const char* argv[]) { test::run(argc, argv); }