test_arg_ops.cpp 8.7 KB
Newer Older
1
2
3
/*
 * The MIT License (MIT)
 *
4
 * Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * 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

#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
28
#include <migraphx/make_op.hpp>
Paul's avatar
Paul committed
29
30
#include <migraphx/op/argmax.hpp>
#include <migraphx/op/argmin.hpp>
31

32
33
template <class T, int Axis, bool LastIndex, int NonStdShape>
struct test_arg_ops : verify_program<test_arg_ops<T, Axis, LastIndex, NonStdShape>>
34
35
36
37
{
    migraphx::program create_program() const
    {
        migraphx::program p;
38
        auto* mm = p.get_main_module();
39
        migraphx::shape s{migraphx::shape::float_type, {2, 1, 4, 1025}};
40
        auto param = mm->add_parameter("data", s);
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        switch(NonStdShape)
        {
        case 0:
            param = mm->add_instruction(
                migraphx::make_op("transpose", {{"permutation", {0, 2, 3, 1}}}), param);
            break;
        case 1:
            param = mm->add_instruction(
                migraphx::make_op("multibroadcast", {{"out_lens", {2, 3, 4, 1025}}}), param);
            break;
        case 2:
            param = mm->add_instruction(
                migraphx::make_op("slice", {{"axes", {2}}, {"starts", {1}}, {"ends", {3}}}), param);
            break;
        default: break;
        }
57
        mm->add_instruction(T{Axis, LastIndex}, param);
58
59
60
        return p;
    }
};
61
// transpose argmax tests
62
63
64
65
66
67
68
69
70
71
72
73
template struct test_arg_ops<migraphx::op::argmax, 0, true, 0>;
template struct test_arg_ops<migraphx::op::argmax, 0, false, 0>;
template struct test_arg_ops<migraphx::op::argmax, 1, true, 0>;
template struct test_arg_ops<migraphx::op::argmax, 1, false, 0>;
template struct test_arg_ops<migraphx::op::argmax, 2, true, 0>;
template struct test_arg_ops<migraphx::op::argmax, 2, false, 0>;
template struct test_arg_ops<migraphx::op::argmax, 3, true, 0>;
template struct test_arg_ops<migraphx::op::argmax, 3, false, 0>;
template struct test_arg_ops<migraphx::op::argmax, -1, true, 0>;
template struct test_arg_ops<migraphx::op::argmax, -1, false, 0>;
template struct test_arg_ops<migraphx::op::argmax, -2, true, 0>;
template struct test_arg_ops<migraphx::op::argmax, -2, false, 0>;
74
// transpose argmin tests
75
76
77
78
79
80
81
82
83
84
85
86
template struct test_arg_ops<migraphx::op::argmin, 0, true, 0>;
template struct test_arg_ops<migraphx::op::argmin, 0, false, 0>;
template struct test_arg_ops<migraphx::op::argmin, 1, true, 0>;
template struct test_arg_ops<migraphx::op::argmin, 1, false, 0>;
template struct test_arg_ops<migraphx::op::argmin, 2, true, 0>;
template struct test_arg_ops<migraphx::op::argmin, 2, false, 0>;
template struct test_arg_ops<migraphx::op::argmin, 3, true, 0>;
template struct test_arg_ops<migraphx::op::argmin, 3, false, 0>;
template struct test_arg_ops<migraphx::op::argmin, -3, true, 0>;
template struct test_arg_ops<migraphx::op::argmin, -3, false, 0>;
template struct test_arg_ops<migraphx::op::argmin, -4, true, 0>;
template struct test_arg_ops<migraphx::op::argmin, -4, false, 0>;
87
// broadcast argmax tests
88
89
90
91
92
93
94
95
96
97
98
99
template struct test_arg_ops<migraphx::op::argmax, 0, true, 1>;
template struct test_arg_ops<migraphx::op::argmax, 0, false, 1>;
template struct test_arg_ops<migraphx::op::argmax, 1, true, 1>;
template struct test_arg_ops<migraphx::op::argmax, 1, false, 1>;
template struct test_arg_ops<migraphx::op::argmax, 2, true, 1>;
template struct test_arg_ops<migraphx::op::argmax, 2, false, 1>;
template struct test_arg_ops<migraphx::op::argmax, 3, true, 1>;
template struct test_arg_ops<migraphx::op::argmax, 3, false, 1>;
template struct test_arg_ops<migraphx::op::argmax, -1, true, 1>;
template struct test_arg_ops<migraphx::op::argmax, -1, false, 1>;
template struct test_arg_ops<migraphx::op::argmax, -2, true, 1>;
template struct test_arg_ops<migraphx::op::argmax, -2, false, 1>;
100
// broadcast argmin tests
101
102
103
104
105
106
107
108
109
110
111
112
template struct test_arg_ops<migraphx::op::argmin, 0, true, 1>;
template struct test_arg_ops<migraphx::op::argmin, 0, false, 1>;
template struct test_arg_ops<migraphx::op::argmin, 1, true, 1>;
template struct test_arg_ops<migraphx::op::argmin, 1, false, 1>;
template struct test_arg_ops<migraphx::op::argmin, 2, true, 1>;
template struct test_arg_ops<migraphx::op::argmin, 2, false, 1>;
template struct test_arg_ops<migraphx::op::argmin, 3, true, 1>;
template struct test_arg_ops<migraphx::op::argmin, 3, false, 1>;
template struct test_arg_ops<migraphx::op::argmin, -3, true, 1>;
template struct test_arg_ops<migraphx::op::argmin, -3, false, 1>;
template struct test_arg_ops<migraphx::op::argmin, -4, true, 1>;
template struct test_arg_ops<migraphx::op::argmin, -4, false, 1>;
113
// slice argmax tests
114
115
116
117
118
119
120
121
122
123
124
125
template struct test_arg_ops<migraphx::op::argmax, 0, true, 2>;
template struct test_arg_ops<migraphx::op::argmax, 0, false, 2>;
template struct test_arg_ops<migraphx::op::argmax, 1, true, 2>;
template struct test_arg_ops<migraphx::op::argmax, 1, false, 2>;
template struct test_arg_ops<migraphx::op::argmax, 2, true, 2>;
template struct test_arg_ops<migraphx::op::argmax, 2, false, 2>;
template struct test_arg_ops<migraphx::op::argmax, 3, true, 2>;
template struct test_arg_ops<migraphx::op::argmax, 3, false, 2>;
template struct test_arg_ops<migraphx::op::argmax, -1, true, 2>;
template struct test_arg_ops<migraphx::op::argmax, -1, false, 2>;
template struct test_arg_ops<migraphx::op::argmax, -2, true, 2>;
template struct test_arg_ops<migraphx::op::argmax, -2, false, 2>;
126
// slice argmin tests
127
128
129
130
131
132
133
134
135
136
137
138
template struct test_arg_ops<migraphx::op::argmin, 0, true, 2>;
template struct test_arg_ops<migraphx::op::argmin, 0, false, 2>;
template struct test_arg_ops<migraphx::op::argmin, 1, true, 2>;
template struct test_arg_ops<migraphx::op::argmin, 1, false, 2>;
template struct test_arg_ops<migraphx::op::argmin, 2, true, 2>;
template struct test_arg_ops<migraphx::op::argmin, 2, false, 2>;
template struct test_arg_ops<migraphx::op::argmin, 3, true, 2>;
template struct test_arg_ops<migraphx::op::argmin, 3, false, 2>;
template struct test_arg_ops<migraphx::op::argmin, -3, true, 2>;
template struct test_arg_ops<migraphx::op::argmin, -3, false, 2>;
template struct test_arg_ops<migraphx::op::argmin, -4, true, 2>;
template struct test_arg_ops<migraphx::op::argmin, -4, false, 2>;
139
// default case, standard shape argmax tests
140
141
142
143
144
145
146
147
148
149
150
151
template struct test_arg_ops<migraphx::op::argmax, 0, true, 3>;
template struct test_arg_ops<migraphx::op::argmax, 0, false, 3>;
template struct test_arg_ops<migraphx::op::argmax, 1, true, 3>;
template struct test_arg_ops<migraphx::op::argmax, 1, false, 3>;
template struct test_arg_ops<migraphx::op::argmax, 2, true, 3>;
template struct test_arg_ops<migraphx::op::argmax, 2, false, 3>;
template struct test_arg_ops<migraphx::op::argmax, 3, true, 3>;
template struct test_arg_ops<migraphx::op::argmax, 3, false, 3>;
template struct test_arg_ops<migraphx::op::argmax, -1, true, 3>;
template struct test_arg_ops<migraphx::op::argmax, -1, false, 3>;
template struct test_arg_ops<migraphx::op::argmax, -2, true, 3>;
template struct test_arg_ops<migraphx::op::argmax, -2, false, 3>;
152
// default case, standard shape argmin tests
153
154
155
156
157
158
159
160
161
162
163
164
template struct test_arg_ops<migraphx::op::argmin, 0, true, 3>;
template struct test_arg_ops<migraphx::op::argmin, 0, false, 3>;
template struct test_arg_ops<migraphx::op::argmin, 1, true, 3>;
template struct test_arg_ops<migraphx::op::argmin, 1, false, 3>;
template struct test_arg_ops<migraphx::op::argmin, 2, true, 3>;
template struct test_arg_ops<migraphx::op::argmin, 2, false, 3>;
template struct test_arg_ops<migraphx::op::argmin, 3, true, 3>;
template struct test_arg_ops<migraphx::op::argmin, 3, false, 3>;
template struct test_arg_ops<migraphx::op::argmin, -3, true, 3>;
template struct test_arg_ops<migraphx::op::argmin, -3, false, 3>;
template struct test_arg_ops<migraphx::op::argmin, -4, true, 3>;
template struct test_arg_ops<migraphx::op::argmin, -4, false, 3>;