program_test.cpp 1.61 KB
Newer Older
Paul's avatar
Paul committed
1

Paul's avatar
Paul committed
2
3
4
#include <migraphx/program.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/instruction.hpp>
5
6
#include <migraphx/op/add.hpp>
#include <migraphx/op/mul.hpp>
Paul's avatar
Paul committed
7
8
9
10
#include <sstream>
#include "test.hpp"
#include <basic_ops.hpp>

Paul's avatar
Paul committed
11
migraphx::program create_program()
Paul's avatar
Paul committed
12
{
Paul's avatar
Paul committed
13
    migraphx::program p;
Paul's avatar
Paul committed
14

Paul's avatar
Paul committed
15
16
    auto x = p.add_parameter("x", {migraphx::shape::int64_type});
    auto y = p.add_parameter("y", {migraphx::shape::int64_type});
Paul's avatar
Paul committed
17
18

    auto sum = p.add_instruction(sum_op{}, x, y);
Paul's avatar
Paul committed
19
    auto one = p.add_literal(1);
Paul's avatar
Paul committed
20
21
22
23
24
    p.add_instruction(sum_op{}, sum, one);

    return p;
}

Paul's avatar
Paul committed
25
TEST_CASE(program_equality)
Paul's avatar
Paul committed
26
{
Paul's avatar
Paul committed
27
28
    migraphx::program x = create_program();
    migraphx::program y = create_program();
Paul's avatar
Paul committed
29
30
31
    EXPECT(x == y);
}

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
TEST_CASE(program_copy)
{
    auto create_program_1 = [] {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3, 4, 5}};
        std::vector<float> data(3 * 4 * 5);
        std::iota(data.begin(), data.end(), 1.0f);
        auto l2 = p.add_literal(migraphx::literal(s, data));
        auto p1 = p.add_parameter("x", s);
        auto po = p.add_outline(s);
        auto sum = p.add_instruction(migraphx::op::add{}, l2, p1);
        p.add_instruction(migraphx::op::mul{}, sum, po);

        return p;
    };

    {
        auto p1 = create_program_1();
        auto p2 = p1;
        EXPECT(p1 == p2);
    }

    {
        auto p1 = create_program_1();
        auto p2(p1);
        EXPECT(p1 == p2);
    }

    {
        auto p1 = create_program_1();
        auto p2 = create_program();
        p2 = p1;

        EXPECT(p1 == p2);
    }
}

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