validate.cpp 2.83 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>
26
#include <migraphx/make_op.hpp>
Paul's avatar
Paul committed
27
28
#include <basic_ops.hpp>
#include <test.hpp>
29
#include <rob.hpp>
Paul's avatar
Paul committed
30

Paul's avatar
Paul committed
31
TEST_CASE(simple_test)
Paul's avatar
Paul committed
32
{
Paul's avatar
Paul committed
33
    migraphx::program p;
34
35
36
    auto* mm = p.get_main_module();
    auto one = mm->add_literal(1);
    auto two = mm->add_literal(2);
37
    mm->add_instruction(migraphx::make_op("add"), one, two);
Shucai Xiao's avatar
Shucai Xiao committed
38
    EXPECT(bool{mm->validate() == mm->end()});
Paul's avatar
Paul committed
39
    auto result = p.eval({});
40
41
    EXPECT(result.back() == migraphx::literal{3});
    EXPECT(result.back() != migraphx::literal{4});
Paul's avatar
Paul committed
42
43
}

Paul's avatar
Paul committed
44
TEST_CASE(out_of_order)
Paul's avatar
Paul committed
45
{
Paul's avatar
Paul committed
46
    migraphx::program p;
47
48
49
    auto* mm = p.get_main_module();
    auto one = mm->add_literal(1);
    auto two = mm->add_literal(2);
50
    auto ins = mm->add_instruction(migraphx::make_op("add"), one, two);
Shucai Xiao's avatar
Shucai Xiao committed
51
    mm->move_instruction(two, mm->end());
Paul's avatar
Paul committed
52
53
54
    EXPECT(bool{p.validate() == ins});
}

Paul's avatar
Paul committed
55
TEST_CASE(incomplete_args)
Paul's avatar
Paul committed
56
{
Paul's avatar
Paul committed
57
    migraphx::program p;
58
59
60
    auto* mm = p.get_main_module();
    auto one = mm->add_literal(1);
    auto two = mm->add_literal(2);
61
    auto ins = mm->add_instruction(migraphx::make_op("add"), one, two);
Paul's avatar
Paul committed
62
63
64
65
    ins->clear_arguments();
    EXPECT(bool{p.validate() == ins});
}

Paul's avatar
Paul committed
66
MIGRAPHX_ROB(access_ins_arguments,
Paul's avatar
Paul committed
67
68
69
             std::vector<migraphx::instruction_ref>,
             migraphx::instruction,
             arguments)
70

Paul's avatar
Paul committed
71
TEST_CASE(invalid_args)
Paul's avatar
Paul committed
72
{
Paul's avatar
Paul committed
73
    migraphx::program p;
74
75
76
    auto* mm = p.get_main_module();
    auto one = mm->add_literal(1);
    auto two = mm->add_literal(2);
77
    auto ins = mm->add_instruction(migraphx::make_op("add"), one, two);
78
    access_ins_arguments(*ins).clear();
Shucai Xiao's avatar
Shucai Xiao committed
79
    EXPECT(bool{mm->validate() == mm->begin()});
Paul's avatar
Paul committed
80
81
}

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