miopen.cpp 113 KB
Newer Older
Paul's avatar
Paul committed
1

Paul's avatar
Paul committed
2
3
4
5
6
7
8
9
10
11
12
#include <migraphx/program.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/generate.hpp>
#include <migraphx/cpu/target.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/miopen.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/type_name.hpp>
#include <migraphx/verify_args.hpp>
#include <migraphx/instruction.hpp>
Paul's avatar
Paul committed
13
14
15

#include <miopen/miopen.h>

Paul's avatar
Paul committed
16
17
18
#include <future>
#include <thread>

Paul's avatar
Paul committed
19
20
#include "test.hpp"

Paul's avatar
Paul committed
21
22
23
24
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
Paul's avatar
Paul committed
25

Paul's avatar
Paul committed
26
27
// An improved async, that doesn't block
template <class Function>
Paul's avatar
Paul committed
28
29
std::future<typename std::result_of<Function()>::type> detach_async(Function&& f,
                                                                    bool parallel = true)
Paul's avatar
Paul committed
30
{
Paul's avatar
Paul committed
31
32
33
34
35
36
37
38
    if(parallel)
    {
        using result_type = typename std::result_of<Function()>::type;
        std::packaged_task<result_type()> task(std::forward<Function>(f));
        auto fut = task.get_future();
        std::thread(std::move(task)).detach();
        return std::move(fut);
    }
39
    return std::async(std::launch::deferred, std::forward<Function>(f));
Paul's avatar
Paul committed
40
41
}

Paul's avatar
Paul committed
42
43
struct auto_print
{
Paul's avatar
Paul committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    static void set_terminate_handler(const std::string& name)
    {
        static std::string pname;
        pname = name;
        std::set_terminate(+[] {
            std::cout << "FAILED: " << pname << std::endl;
            try
            {
                std::rethrow_exception(std::current_exception());
            }
            catch(const std::exception& e)
            {
                std::cout << "    what(): " << e.what() << std::endl;
            }
            std::cout << std::endl;
            for(auto&& handle : auto_print::handlers)
                handle();
        });
    }
Paul's avatar
Paul committed
63
    static std::array<std::function<void()>, 2> handlers;
Paul's avatar
Paul committed
64
    int index;
Paul's avatar
Paul committed
65
    template <class T>
Paul's avatar
Paul committed
66
    auto_print(T& x, int i) : index(i)
Paul's avatar
Paul committed
67
    {
Paul's avatar
Paul committed
68
        handlers[index] = [&x] { std::cout << x << std::endl; };
Paul's avatar
Paul committed
69
    }
Paul's avatar
Paul committed
70

Paul's avatar
Paul committed
71
    ~auto_print()
Paul's avatar
Paul committed
72
    {
Paul's avatar
Paul committed
73
        handlers[index] = [] {};
Paul's avatar
Paul committed
74
75
    }
};
Paul's avatar
Paul committed
76
std::array<std::function<void()>, 2> auto_print::handlers = {};
Paul's avatar
Paul committed
77

Paul's avatar
Paul committed
78
template <class T>
Paul's avatar
Latest  
Paul committed
79
80
81
82
83
auto get_hash(const T& x)
{
    return std::hash<T>{}(x);
}

Paul's avatar
Paul committed
84
void compile_check(migraphx::program& p, const migraphx::target& t)
Paul's avatar
Paul committed
85
86
{
    auto name = t.name();
Paul's avatar
Paul committed
87
    auto s    = p.get_shape();
Paul's avatar
Paul committed
88
    std::stringstream ss;
Paul's avatar
Paul committed
89
    p.compile(t, migraphx::tracer{ss});
Paul's avatar
Paul committed
90
    if(p.get_shape() != s)
Paul's avatar
Paul committed
91
92
93
94
95
96
    {
        std::cout << ss.str() << std::endl;
        throw std::runtime_error("Compiling program with " + name + " alters its shape");
    }
}

Paul's avatar
Paul committed
97
template <class V>
Paul's avatar
Paul committed
98
migraphx::argument run_cpu(migraphx::program& p)
Paul's avatar
Paul committed
99
{
Paul's avatar
Paul committed
100
    V v;
Paul's avatar
Paul committed
101
    p = v.create_program();
Paul's avatar
Paul committed
102
    auto_print pp{p, 0};
Paul's avatar
Paul committed
103
104
    compile_check(p, migraphx::cpu::target{});
    migraphx::program::parameter_map m;
Paul's avatar
Paul committed
105
    for(auto&& x : p.get_parameter_shapes())
Paul's avatar
Paul committed
106
    {
Paul's avatar
Paul committed
107
        m[x.first] = migraphx::generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
108
    }
Paul's avatar
Paul committed
109
    return p.eval(m);
Paul's avatar
Paul committed
110
111
}

Paul's avatar
Paul committed
112
template <class V>
Paul's avatar
Paul committed
113
migraphx::argument run_gpu(migraphx::program& p)
Paul's avatar
Paul committed
114
{
Paul's avatar
Paul committed
115
    V v;
Paul's avatar
Paul committed
116
    p = v.create_program();
Paul's avatar
Paul committed
117
    auto_print pp{p, 1};
Paul's avatar
Paul committed
118
119
    compile_check(p, migraphx::gpu::target{});
    migraphx::program::parameter_map m;
Paul's avatar
Paul committed
120
    for(auto&& x : p.get_parameter_shapes())
Paul's avatar
Paul committed
121
    {
Paul's avatar
Paul committed
122
123
        m[x.first] =
            migraphx::gpu::to_gpu(migraphx::generate_argument(x.second, get_hash(x.first)));
Paul's avatar
Paul committed
124
    }
Paul's avatar
Paul committed
125
    // Program should have an output parameter
Paul's avatar
Paul committed
126
    EXPECT(bool{m.find("output") != m.end()});
Paul's avatar
Paul committed
127
128
129
130
131
132
    // Ensure the program doesn't modify the context in a dry run
    auto ctx = p.get_context();
    assert(&ctx != &p.get_context());
    EXPECT(is_shared(ctx, p.get_context()));
    p.dry_run(m);
    EXPECT(is_shared(ctx, p.get_context()));
Paul's avatar
Paul committed
133
    return migraphx::gpu::from_gpu(p.eval(m));
Paul's avatar
Paul committed
134
135
}

Paul's avatar
Paul committed
136
137
138
template <class V>
void verify_program()
{
Paul's avatar
Paul committed
139
140
141
142
    auto_print::set_terminate_handler(migraphx::get_type_name<V>());
    // std::cout << migraphx::get_type_name<V>() << std::endl;
    migraphx::program cpu_prog;
    migraphx::program gpu_prog;
Paul's avatar
Paul committed
143
144
    auto cpu_arg_f = detach_async([&] { return run_cpu<V>(cpu_prog); });
    auto gpu_arg   = run_gpu<V>(gpu_prog);
Paul's avatar
Paul committed
145
    auto cpu_arg   = cpu_arg_f.get();
Paul's avatar
Paul committed
146
    bool passed    = verify_args(migraphx::get_type_name<V>(), cpu_arg, gpu_arg);
Paul's avatar
Paul committed
147
148
149
150
151
152
153
154
155
    if(not passed)
    {
        V v;
        auto p = v.create_program();
        std::cout << p << std::endl;
        std::cout << "cpu:\n" << cpu_prog << std::endl;
        std::cout << "gpu:\n" << gpu_prog << std::endl;
        std::cout << std::endl;
    }
Paul's avatar
Paul committed
156
    std::set_terminate(nullptr);
Paul's avatar
Paul committed
157
158
}

Paul's avatar
Paul committed
159
160
struct test_literals
{
Paul's avatar
Paul committed
161
    migraphx::program create_program() const
Paul's avatar
Paul committed
162
    {
Paul's avatar
Paul committed
163
        migraphx::program p;
Paul's avatar
Paul committed
164
        auto input = p.add_literal(
Paul's avatar
Paul committed
165
            generate_literal(migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}));
Paul's avatar
Paul committed
166
        auto weights = p.add_literal(
Paul's avatar
Paul committed
167
168
169
            generate_literal(migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}}));
        auto conv = p.add_instruction(migraphx::op::convolution{}, input, weights);
        p.add_instruction(migraphx::op::relu{}, conv);
Paul's avatar
Paul committed
170
171
172
173
        return p;
    }
};

Paul's avatar
Paul committed
174
175
struct test_add
{
Paul's avatar
Paul committed
176
    migraphx::program create_program() const
Paul's avatar
Paul committed
177
    {
Paul's avatar
Paul committed
178
179
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
Paul's avatar
Paul committed
180
181
        auto x = p.add_parameter("x", s);
        auto y = p.add_parameter("y", s);
Paul's avatar
Paul committed
182
        p.add_instruction(migraphx::op::add{}, x, y);
Paul's avatar
Paul committed
183
184
185
186
        return p;
    }
};

Paul's avatar
Paul committed
187
188
struct test_add_half
{
Paul's avatar
Paul committed
189
    migraphx::program create_program() const
Paul's avatar
Paul committed
190
    {
Paul's avatar
Paul committed
191
192
        migraphx::program p;
        migraphx::shape s{migraphx::shape::half_type, {3}};
Paul's avatar
Paul committed
193
194
        auto x = p.add_parameter("x", s);
        auto y = p.add_parameter("y", s);
Paul's avatar
Paul committed
195
        p.add_instruction(migraphx::op::add{}, x, y);
Paul's avatar
Paul committed
196
197
198
199
        return p;
    }
};

Khalique's avatar
Khalique committed
200
201
struct test_mul
{
Paul's avatar
Paul committed
202
    migraphx::program create_program() const
Khalique's avatar
Khalique committed
203
    {
Paul's avatar
Paul committed
204
205
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
Khalique's avatar
Khalique committed
206
207
        auto x = p.add_parameter("x", s);
        auto y = p.add_parameter("y", s);
Paul's avatar
Paul committed
208
        p.add_instruction(migraphx::op::mul{}, x, y);
Khalique's avatar
Khalique committed
209
210
211
212
        return p;
    }
};

Shucai Xiao's avatar
Shucai Xiao committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
struct test_exp
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {6}};
        std::vector<float> data{0.1f, 0.2f, 1.f, 2.f, 0.6f, 10.f};
        auto x = p.add_literal(s, data);
        p.add_instruction(migraphx::op::exp{}, x);
        return p;
    }
};

struct test_log
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {6}};
        std::vector<float> data{0.1f, 0.2f, 1.f, 2.f, 0.6f, 100.f};
        auto x = p.add_literal(s, data);
        p.add_instruction(migraphx::op::log{}, x);
        return p;
    }
};

239
240
241
242
243
244
245
246
247
248
249
250
struct test_sin
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {10}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::sin{}, x);
        return p;
    }
};

Shucai Xiao's avatar
Shucai Xiao committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
struct test_cos
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::double_type, {8}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::cos{}, x);
        return p;
    }
};

struct test_tan
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {16}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::tan{}, x);
        return p;
    }
};

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
struct test_sinh
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::double_type, {16}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::sinh{}, x);
        return p;
    }
};

struct test_cosh
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::double_type, {16}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::cosh{}, x);
        return p;
    }
};

299
300
301
302
303
304
305
306
307
308
309
struct test_tanh
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        p.add_instruction(migraphx::op::tanh{}, x);
        return p;
    }
};

310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
struct test_asin
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::double_type, {16}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::asin{}, x);
        return p;
    }
};

struct test_acos
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::double_type, {16}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::acos{}, x);
        return p;
    }
};

struct test_atan
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::double_type, {16}};
        auto x = p.add_parameter("x", s);
        p.add_instruction(migraphx::op::atan{}, x);
        return p;
    }
};

Khalique's avatar
Khalique committed
346
347
struct test_scale
{
Paul's avatar
Paul committed
348
    migraphx::program create_program() const
Khalique's avatar
Khalique committed
349
    {
Paul's avatar
Paul committed
350
351
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
Khalique's avatar
Khalique committed
352
        auto x     = p.add_parameter("x", s);
Paul's avatar
Paul committed
353
354
355
        auto y     = p.add_parameter("y", migraphx::shape::float_type);
        auto scale = p.add_instruction(migraphx::op::scalar{s}, y);
        p.add_instruction(migraphx::op::mul{}, x, scale);
Khalique's avatar
Khalique committed
356
357
358
359
        return p;
    }
};

360
361
struct test_slice
{
Paul's avatar
Paul committed
362
    migraphx::program create_program() const
363
    {
Paul's avatar
Paul committed
364
365
        migraphx::program p;
        migraphx::shape s{migraphx::shape::int32_type, {2, 2, 4}};
366
        auto x      = p.add_parameter("x", s);
Paul's avatar
Paul committed
367
368
369
        auto y      = p.add_parameter("y", {migraphx::shape::int32_type, {2, 2, 2}});
        auto slice0 = p.add_instruction(migraphx::op::slice{{2}, {0}, {2}}, x);
        p.add_instruction(migraphx::op::add{}, y, slice0);
370
371
372
373
374

        return p;
    }
};

Paul's avatar
Paul committed
375
376
struct test_triadd
{
Paul's avatar
Paul committed
377
    migraphx::program create_program() const
Paul's avatar
Paul committed
378
    {
Paul's avatar
Paul committed
379
380
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
Paul's avatar
Paul committed
381
382
383
        auto x   = p.add_parameter("x", s);
        auto y   = p.add_parameter("y", s);
        auto z   = p.add_parameter("z", s);
Paul's avatar
Paul committed
384
385
        auto sum = p.add_instruction(migraphx::op::add{}, x, y);
        p.add_instruction(migraphx::op::add{}, sum, z);
Paul's avatar
Paul committed
386
387
388
389
390
391
        return p;
    }
};

struct test_triadd2
{
Paul's avatar
Paul committed
392
    migraphx::program create_program() const
Paul's avatar
Paul committed
393
    {
Paul's avatar
Paul committed
394
395
396
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {2, 3}};
        migraphx::shape b{migraphx::shape::float_type, {3}};
Paul's avatar
Paul committed
397
398
399
        auto x   = p.add_parameter("x", s);
        auto y   = p.add_parameter("y", s);
        auto z   = p.add_parameter("z", b);
Paul's avatar
Paul committed
400
401
402
        auto zb  = p.add_instruction(migraphx::op::broadcast{1, s}, z);
        auto sum = p.add_instruction(migraphx::op::add{}, x, y);
        p.add_instruction(migraphx::op::add{}, sum, zb);
Paul's avatar
Paul committed
403
404
405
406
        return p;
    }
};

Paul's avatar
Paul committed
407
408
struct test_add_broadcast
{
Paul's avatar
Paul committed
409
    migraphx::program create_program() const
Paul's avatar
Paul committed
410
    {
Paul's avatar
Paul committed
411
412
413
414
415
416
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
        auto x  = p.add_parameter("x", {migraphx::shape::float_type, {2, 2, 3}});
        auto y  = p.add_parameter("y", {migraphx::shape::float_type, {2, 2}});
        auto by = p.add_instruction(migraphx::op::broadcast{0, x->get_shape()}, y);
        p.add_instruction(migraphx::op::add{}, x, by);
Paul's avatar
Paul committed
417
418
419
420
        return p;
    }
};

Paul's avatar
Paul committed
421
422
struct test_add_broadcast2
{
Paul's avatar
Paul committed
423
    migraphx::program create_program() const
Paul's avatar
Paul committed
424
    {
Paul's avatar
Paul committed
425
426
427
428
429
430
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
        auto x  = p.add_parameter("x", {migraphx::shape::float_type, {2, 3, 4}});
        auto y  = p.add_parameter("y", {migraphx::shape::float_type, {3}});
        auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
        p.add_instruction(migraphx::op::add{}, x, by);
Paul's avatar
Paul committed
431
432
433
434
        return p;
    }
};

Paul's avatar
Latest  
Paul committed
435
436
struct test_add_broadcast3
{
Paul's avatar
Paul committed
437
    migraphx::program create_program() const
Paul's avatar
Latest  
Paul committed
438
    {
Paul's avatar
Paul committed
439
440
441
442
443
444
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
        auto x  = p.add_parameter("x", {migraphx::shape::float_type, {2, 4, 5}});
        auto y  = p.add_parameter("y", {migraphx::shape::float_type, {4}});
        auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
        p.add_instruction(migraphx::op::add{}, x, by);
Paul's avatar
Latest  
Paul committed
445
446
447
448
449
450
        return p;
    }
};

struct test_add_broadcast4
{
Paul's avatar
Paul committed
451
    migraphx::program create_program() const
Paul's avatar
Latest  
Paul committed
452
    {
Paul's avatar
Paul committed
453
454
455
456
457
458
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
        auto x  = p.add_parameter("x", {migraphx::shape::float_type, {2, 3, 5}});
        auto y  = p.add_parameter("y", {migraphx::shape::float_type, {3}});
        auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
        p.add_instruction(migraphx::op::add{}, x, by);
Paul's avatar
Latest  
Paul committed
459
460
461
462
        return p;
    }
};

Paul's avatar
Paul committed
463
464
struct test_add_broadcast5
{
Paul's avatar
Paul committed
465
    migraphx::program create_program() const
Paul's avatar
Paul committed
466
    {
Paul's avatar
Paul committed
467
468
469
470
471
472
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
        auto x  = p.add_parameter("x", {migraphx::shape::float_type, {2, 4, 8}});
        auto y  = p.add_parameter("y", {migraphx::shape::float_type, {4}});
        auto by = p.add_instruction(migraphx::op::broadcast{1, x->get_shape()}, y);
        p.add_instruction(migraphx::op::add{}, x, by);
Paul's avatar
Paul committed
473
474
475
476
        return p;
    }
};

Paul's avatar
Paul committed
477
478
struct test_triadd_broadcast
{
Paul's avatar
Paul committed
479
    migraphx::program create_program() const
Paul's avatar
Paul committed
480
    {
Paul's avatar
Paul committed
481
482
483
484
485
486
487
488
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
        auto x   = p.add_parameter("x", {migraphx::shape::float_type, {2, 2, 3}});
        auto y   = p.add_parameter("y", {migraphx::shape::float_type, {2, 2}});
        auto z   = p.add_parameter("z", {migraphx::shape::float_type, {2, 2, 3}});
        auto by  = p.add_instruction(migraphx::op::broadcast{0, x->get_shape()}, y);
        auto sum = p.add_instruction(migraphx::op::add{}, x, by);
        p.add_instruction(migraphx::op::add{}, sum, z);
Paul's avatar
Paul committed
489
490
491
492
        return p;
    }
};

493
494
495
496
497
498
struct test_sub
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
Shucai Xiao's avatar
Shucai Xiao committed
499
500
501
        auto x    = p.add_parameter("x", s);
        auto y    = p.add_parameter("y", s);
        auto z    = p.add_parameter("z", s);
502
503
504
505
506
507
508
509
510
511
512
513
514
        auto diff = p.add_instruction(migraphx::op::sub{}, x, y);
        p.add_instruction(migraphx::op::sub{}, diff, z);
        return p;
    }
};

struct test_sub2
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {2, 3}};
        migraphx::shape b{migraphx::shape::float_type, {3}};
Shucai Xiao's avatar
Shucai Xiao committed
515
516
517
518
        auto x    = p.add_parameter("x", s);
        auto y    = p.add_parameter("y", s);
        auto z    = p.add_parameter("z", b);
        auto zb   = p.add_instruction(migraphx::op::broadcast{1, s}, z);
519
520
521
522
523
524
        auto diff = p.add_instruction(migraphx::op::sub{}, x, y);
        p.add_instruction(migraphx::op::sub{}, diff, zb);
        return p;
    }
};

Paul's avatar
Paul committed
525
526
struct test_softmax
{
Paul's avatar
Paul committed
527
    migraphx::program create_program() const
Paul's avatar
Paul committed
528
    {
Paul's avatar
Paul committed
529
530
531
        migraphx::program p;
        auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {5, 3, 4, 2}});
        p.add_instruction(migraphx::op::softmax{}, x);
Paul's avatar
Paul committed
532
533
534
535
536
537
        return p;
    }
};

struct test_softmax2
{
Paul's avatar
Paul committed
538
    migraphx::program create_program() const
Paul's avatar
Paul committed
539
    {
Paul's avatar
Paul committed
540
        migraphx::program p;
Paul's avatar
Paul committed
541
542
        auto x =
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 1000, 1, 1}});
Paul's avatar
Paul committed
543
        p.add_instruction(migraphx::op::softmax{}, x);
Paul's avatar
Paul committed
544
545
546
547
        return p;
    }
};

Paul's avatar
Paul committed
548
549
struct test_conv
{
Paul's avatar
Paul committed
550
    migraphx::program create_program() const
Paul's avatar
Paul committed
551
    {
Paul's avatar
Paul committed
552
        migraphx::program p;
Paul's avatar
Paul committed
553
554
        auto input =
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
Paul's avatar
Paul committed
555
        auto weights =
Paul's avatar
Paul committed
556
557
            p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        p.add_instruction(migraphx::op::convolution{}, input, weights);
Paul's avatar
Paul committed
558
559
560
561
        return p;
    }
};

Paul's avatar
Paul committed
562
563
struct test_conv2
{
Paul's avatar
Paul committed
564
    migraphx::program create_program() const
Paul's avatar
Paul committed
565
    {
Paul's avatar
Paul committed
566
        migraphx::program p;
Paul's avatar
Paul committed
567
        auto input =
Paul's avatar
Paul committed
568
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 512, 28, 28}});
Paul's avatar
Paul committed
569
        auto weights =
Paul's avatar
Paul committed
570
571
            p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {256, 512, 1, 1}});
        p.add_instruction(migraphx::op::convolution{{0, 0}, {1, 1}, {1, 1}}, input, weights);
Paul's avatar
Paul committed
572
573
574
575
        return p;
    }
};

Khalique's avatar
Khalique committed
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
struct test_group_conv
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        auto input =
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 4, 16, 16}});
        auto weights =
            p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 1, 3, 3}});
        migraphx::op::convolution op;
        op.group = 4;
        p.add_instruction(op, input, weights);
        return p;
    }
};

Paul's avatar
Paul committed
592
struct test_conv_relu
Paul's avatar
Paul committed
593
{
Paul's avatar
Paul committed
594
    migraphx::program create_program() const
Paul's avatar
Paul committed
595
    {
Paul's avatar
Paul committed
596
        migraphx::program p;
Paul's avatar
Paul committed
597
598
        auto input =
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
Paul's avatar
Paul committed
599
        auto weights =
Paul's avatar
Paul committed
600
601
602
            p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        auto conv = p.add_instruction(migraphx::op::convolution{}, input, weights);
        p.add_instruction(migraphx::op::relu{}, conv);
Paul's avatar
Paul committed
603
604
605
606
        return p;
    }
};

Paul's avatar
Paul committed
607
608
struct test_conv_relu_half
{
Paul's avatar
Paul committed
609
    migraphx::program create_program() const
Paul's avatar
Paul committed
610
    {
Paul's avatar
Paul committed
611
        migraphx::program p;
Paul's avatar
Paul committed
612
613
        auto input =
            p.add_parameter("x", migraphx::shape{migraphx::shape::half_type, {4, 3, 3, 3}});
Paul's avatar
Paul committed
614
        auto weights =
Paul's avatar
Paul committed
615
616
617
            p.add_parameter("w", migraphx::shape{migraphx::shape::half_type, {4, 3, 3, 3}});
        auto conv = p.add_instruction(migraphx::op::convolution{}, input, weights);
        p.add_instruction(migraphx::op::relu{}, conv);
Paul's avatar
Paul committed
618
619
620
621
        return p;
    }
};

Paul's avatar
Paul committed
622
623
struct test_add_relu
{
Paul's avatar
Paul committed
624
    migraphx::program create_program() const
Paul's avatar
Paul committed
625
    {
Paul's avatar
Paul committed
626
627
628
629
630
        migraphx::program p;
        auto x   = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        auto y   = p.add_parameter("y", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        auto add = p.add_instruction(migraphx::op::add{}, x, y);
        p.add_instruction(migraphx::op::relu{}, add);
Paul's avatar
Paul committed
631
632
633
634
        return p;
    }
};

Khalique's avatar
Khalique committed
635
636
637
638
639
struct test_sigmoid
{
    migraphx::program create_program() const
    {
        migraphx::program p;
Khalique's avatar
Khalique committed
640
        auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
Khalique's avatar
Khalique committed
641
642
643
644
645
646
647
648
649
650
        p.add_instruction(migraphx::op::sigmoid{}, x);
        return p;
    }
};

struct test_abs
{
    migraphx::program create_program() const
    {
        migraphx::program p;
Khalique's avatar
Khalique committed
651
        auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
Khalique's avatar
Khalique committed
652
653
654
655
656
        p.add_instruction(migraphx::op::abs{}, x);
        return p;
    }
};

657
658
struct test_leaky_relu
{
Paul's avatar
Paul committed
659
    migraphx::program create_program() const
660
    {
Paul's avatar
Paul committed
661
662
663
        migraphx::program p;
        auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        p.add_instruction(migraphx::op::leaky_relu{0.01}, x);
664
665
666
667
        return p;
    }
};

Khalique's avatar
Khalique committed
668
669
670
671
672
673
674
675
676
677
678
struct test_elu
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        p.add_instruction(migraphx::op::leaky_relu{1.0}, x);
        return p;
    }
};

Khalique's avatar
Khalique committed
679
struct test_relu_lrn
Khalique's avatar
Khalique committed
680
{
Khalique's avatar
Khalique committed
681
    migraphx::program create_program() const
Khalique's avatar
Khalique committed
682
    {
Khalique's avatar
Khalique committed
683
684
685
686
        migraphx::program p;
        auto x = p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 5, 2, 2}});
        auto y = p.add_instruction(migraphx::op::relu{}, x);
        p.add_instruction(migraphx::op::lrn{0.0001, 0.75, 1.0, 5}, y);
Khalique's avatar
Khalique committed
687
688
689
690
        return p;
    }
};

Paul's avatar
Paul committed
691
692
struct test_conv_pooling
{
Paul's avatar
Paul committed
693
    migraphx::program create_program() const
Paul's avatar
Paul committed
694
    {
Paul's avatar
Paul committed
695
        migraphx::program p;
Paul's avatar
Paul committed
696
        auto input =
Paul's avatar
Paul committed
697
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {4, 3, 32, 32}});
Paul's avatar
Paul committed
698
        auto weights =
Paul's avatar
Paul committed
699
700
701
702
            p.add_parameter("w", migraphx::shape{migraphx::shape::float_type, {4, 3, 3, 3}});
        auto conv    = p.add_instruction(migraphx::op::convolution{}, input, weights);
        auto pooling = p.add_instruction(migraphx::op::pooling{"max"}, conv);
        p.add_instruction(migraphx::op::relu{}, pooling);
Paul's avatar
Paul committed
703
704
705
706
        return p;
    }
};

707
708
struct test_global_avg_pooling
{
Paul's avatar
Paul committed
709
    migraphx::program create_program() const
710
    {
Paul's avatar
Paul committed
711
        migraphx::program p;
712
        auto input =
Paul's avatar
Paul committed
713
714
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 16, 16}});
        auto op    = migraphx::op::pooling{"average"};
715
        auto lens  = input->get_shape().lens();
Khalique's avatar
Khalique committed
716
        op.lengths = {lens[2], lens[3]};
717
718
719
720
721
722
723
        p.add_instruction(op, input);
        return p;
    }
};

struct test_global_max_pooling
{
Paul's avatar
Paul committed
724
    migraphx::program create_program() const
725
    {
Paul's avatar
Paul committed
726
        migraphx::program p;
727
        auto input =
Paul's avatar
Paul committed
728
729
            p.add_parameter("x", migraphx::shape{migraphx::shape::float_type, {1, 3, 16, 16}});
        auto op    = migraphx::op::pooling{"max"};
730
        auto lens  = input->get_shape().lens();
Khalique's avatar
Khalique committed
731
        op.lengths = {lens[2], lens[3]};
732
733
734
735
736
        p.add_instruction(op, input);
        return p;
    }
};

Paul's avatar
Paul committed
737
738
struct test_gemm
{
Paul's avatar
Paul committed
739
    migraphx::program create_program() const
Paul's avatar
Paul committed
740
    {
Paul's avatar
Paul committed
741
742
743
744
        migraphx::program p;
        auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {4, 5}});
        auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {5, 3}});
        p.add_instruction(migraphx::op::dot{}, a, b);
Paul's avatar
Paul committed
745
746
747
748
        return p;
    }
};

749
750
751
752
753
754
755
756
757
758
759
760
struct test_gemm_ex
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {1, 1, 4, 5}});
        auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 3}});
        p.add_instruction(migraphx::op::dot{}, a, b);
        return p;
    }
};

Paul's avatar
Paul committed
761
762
struct test_gemm_half
{
Paul's avatar
Paul committed
763
    migraphx::program create_program() const
Paul's avatar
Paul committed
764
    {
Paul's avatar
Paul committed
765
766
767
768
        migraphx::program p;
        auto a = p.add_parameter("a", migraphx::shape{migraphx::shape::half_type, {4, 5}});
        auto b = p.add_parameter("b", migraphx::shape{migraphx::shape::half_type, {5, 3}});
        p.add_instruction(migraphx::op::dot{}, a, b);
Paul's avatar
Paul committed
769
770
771
772
        return p;
    }
};

Paul's avatar
Paul committed
773
774
struct test_gemm_ld
{
Paul's avatar
Paul committed
775
    migraphx::program create_program() const
Paul's avatar
Paul committed
776
    {
Paul's avatar
Paul committed
777
        migraphx::program p;
Paul's avatar
Paul committed
778
779
780
781
        auto a =
            p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {4, 5}, {10, 1}});
        auto b =
            p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {5, 3}, {20, 1}});
Paul's avatar
Paul committed
782
        p.add_instruction(migraphx::op::dot{}, a, b);
Paul's avatar
Paul committed
783
784
785
786
        return p;
    }
};

787
788
struct test_gemm_transposeb
{
Paul's avatar
Paul committed
789
    migraphx::program create_program() const
790
    {
Paul's avatar
Paul committed
791
792
793
794
795
        migraphx::program p;
        auto a  = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {4, 5}});
        auto b  = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {3, 5}});
        auto bt = p.add_instruction(migraphx::op::transpose{{1, 0}}, b);
        p.add_instruction(migraphx::op::dot{}, a, bt);
796
797
798
799
        return p;
    }
};

800
801
802
803
804
805
806
807
808
809
810
811
812
struct test_gemm_transposeb_ex
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        auto a  = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {1, 4, 5}});
        auto b  = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {1, 3, 5}});
        auto bt = p.add_instruction(migraphx::op::transpose{{0, 2, 1}}, b);
        p.add_instruction(migraphx::op::dot{}, a, bt);
        return p;
    }
};

813
814
struct test_gemm_transposea
{
Paul's avatar
Paul committed
815
    migraphx::program create_program() const
816
    {
Paul's avatar
Paul committed
817
818
819
820
821
        migraphx::program p;
        auto a  = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {5, 4}});
        auto b  = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {5, 3}});
        auto at = p.add_instruction(migraphx::op::transpose{{1, 0}}, a);
        p.add_instruction(migraphx::op::dot{}, at, b);
822
823
824
825
        return p;
    }
};

826
827
828
829
830
831
832
833
834
835
836
837
838
struct test_gemm_transposea_ex
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        auto a  = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 4}});
        auto b  = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {1, 1, 5, 3}});
        auto at = p.add_instruction(migraphx::op::transpose{{0, 1, 3, 2}}, a);
        p.add_instruction(migraphx::op::dot{}, at, b);
        return p;
    }
};

839
840
struct test_gemm_transposeab
{
Paul's avatar
Paul committed
841
    migraphx::program create_program() const
842
    {
Paul's avatar
Paul committed
843
844
845
846
847
848
        migraphx::program p;
        auto a  = p.add_parameter("a", migraphx::shape{migraphx::shape::float_type, {5, 4}});
        auto b  = p.add_parameter("b", migraphx::shape{migraphx::shape::float_type, {3, 5}});
        auto at = p.add_instruction(migraphx::op::transpose{{1, 0}}, a);
        auto bt = p.add_instruction(migraphx::op::transpose{{1, 0}}, b);
        p.add_instruction(migraphx::op::dot{}, at, bt);
849
850
851
852
        return p;
    }
};

853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
struct gemm_mutli_dim_2
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape m1_shape{migraphx::shape::float_type, {2, 2, 3}};
        migraphx::shape m2_shape{migraphx::shape::float_type, {2, 3, 4}};
        auto l1 = p.add_parameter("1", m1_shape);
        auto l2 = p.add_parameter("2", m2_shape);

        p.add_instruction(migraphx::op::dot{}, l1, l2);

        return p;
    }
};

struct gemm_mutli_dim_2_3
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape m1_shape{migraphx::shape::float_type, {2, 3, 2, 3}};
        migraphx::shape m2_shape{migraphx::shape::float_type, {2, 3, 3, 2}};
        auto l1 = p.add_parameter("1", m1_shape);
        auto l2 = p.add_parameter("2", m2_shape);

        p.add_instruction(migraphx::op::dot{}, l1, l2);

        return p;
    }
};

885
886
887
888
889
890
891
892
893
struct gemm_mutli_3args
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape m1_shape{migraphx::shape::float_type, {2, 3, 2, 3}};
        migraphx::shape m2_shape{migraphx::shape::float_type, {2, 3, 3, 2}};
        migraphx::shape m3_shape{migraphx::shape::float_type, {2, 3, 2, 2}};

Shucai Xiao's avatar
Shucai Xiao committed
894
895
896
897
898
        auto l1     = p.add_parameter("1", m1_shape);
        auto l2     = p.add_parameter("2", m2_shape);
        auto l3     = p.add_parameter("3", m3_shape);
        float alpha = 0.35;
        float beta  = 0.41;
899
900
901
902
903
904
        p.add_instruction(migraphx::op::dot{alpha, beta}, l1, l2, l3);

        return p;
    }
};

905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
struct gemm_mutli_3args_beta0
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape m1_shape{migraphx::shape::float_type, {1, 2, 3}};
        migraphx::shape m2_shape{migraphx::shape::float_type, {1, 3, 4}};
        migraphx::shape m3_shape{migraphx::shape::float_type, {1, 2, 4}};
        auto l1 = p.add_parameter("1", m1_shape);
        auto l2 = p.add_parameter("2", m2_shape);
        auto l3 = p.add_parameter("3", m3_shape);
        
        float alpha = 1.0f;
        float beta = 0.0f;
        p.add_instruction(migraphx::op::dot{alpha, beta}, l1, l2, l3);

        return p;
    }
};

struct gemm_mutli_3args_alpha0
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape m1_shape{migraphx::shape::float_type, {1, 2, 3}};
        migraphx::shape m2_shape{migraphx::shape::float_type, {1, 3, 4}};
        migraphx::shape m3_shape{migraphx::shape::float_type, {1, 2, 4}};
        auto l1 = p.add_parameter("1", m1_shape);
        auto l2 = p.add_parameter("2", m2_shape);
        auto l3 = p.add_parameter("3", m3_shape);
        
        float alpha = 0.0f;
        float beta = 1.0f;
        p.add_instruction(migraphx::op::dot{alpha, beta}, l1, l2, l3);

        return p;
    }
};

945
946
struct test_contiguous
{
Paul's avatar
Paul committed
947
    migraphx::program create_program() const
948
    {
Paul's avatar
Paul committed
949
950
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {4, 4, 4, 3}, {48, 4, 1, 16}};
951
        auto x = p.add_parameter("x", s);
Paul's avatar
Paul committed
952
        p.add_instruction(migraphx::op::contiguous{}, x);
Paul's avatar
Paul committed
953
        EXPECT(p.get_shape().standard());
954
955
956
957
        return p;
    }
};

958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
struct test_eliminate_contiguous
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {2, 3, 4, 5}};
        auto seq = p.add_parameter("seq", s);
        std::vector<int64_t> perm{0, 2, 1, 3};
        auto tran_seq = p.add_instruction(migraphx::op::transpose{perm}, seq);
        std::vector<int64_t> out_shape{0, 0, -1};
        p.add_instruction(migraphx::op::reshape{out_shape}, tran_seq);

        return p;
    }
};

974
struct test_transpose
975
{
Paul's avatar
Paul committed
976
    migraphx::program create_program() const
977
    {
Paul's avatar
Paul committed
978
979
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {4, 3, 4, 4}};
980
981
        auto x                    = p.add_parameter("x", s);
        std::vector<int64_t> perm = {0, 2, 3, 1};
Paul's avatar
Paul committed
982
983
        auto l                    = p.add_instruction(migraphx::op::transpose{perm}, x);
        p.add_instruction(migraphx::op::contiguous{}, l);
984
985
986
        return p;
    }
};
987

Paul's avatar
Paul committed
988
989
990
991
992
993
994
struct test_batchnorm_inference_2
{
    const size_t width    = 14;
    const size_t height   = 14;
    const size_t channels = 256;
    const size_t batches  = 1;

Paul's avatar
Paul committed
995
    migraphx::program create_program() const
Paul's avatar
Paul committed
996
    {
Paul's avatar
Paul committed
997
        migraphx::program p;
Paul's avatar
Paul committed
998

Paul's avatar
Paul committed
999
1000
        migraphx::shape s{migraphx::shape::float_type, {batches, channels, height, width}};
        migraphx::shape vars{migraphx::shape::float_type, {channels}};
Paul's avatar
Paul committed
1001
        auto x        = p.add_parameter("x", s);
Paul's avatar
Paul committed
1002
1003
1004
1005
1006
        auto scale    = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
        auto bias     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
        auto mean     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
        auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
        p.add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
Paul's avatar
Paul committed
1007
1008
1009
1010
        return p;
    }
};

wsttiger's avatar
wsttiger committed
1011
1012
1013
1014
1015
1016
1017
struct test_batchnorm_inference
{
    const size_t width    = 3;
    const size_t height   = 3;
    const size_t channels = 3;
    const size_t batches  = 4;

Paul's avatar
Paul committed
1018
    migraphx::program create_program() const
wsttiger's avatar
wsttiger committed
1019
    {
Paul's avatar
Paul committed
1020
        migraphx::program p;
wsttiger's avatar
wsttiger committed
1021

Paul's avatar
Paul committed
1022
1023
        migraphx::shape s{migraphx::shape::float_type, {batches, channels, height, width}};
        migraphx::shape vars{migraphx::shape::float_type, {channels}};
wsttiger's avatar
wsttiger committed
1024
        auto x        = p.add_parameter("x", s);
Paul's avatar
Paul committed
1025
1026
1027
1028
1029
        auto scale    = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
        auto bias     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
        auto mean     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
        auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
        p.add_instruction(migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
wsttiger's avatar
wsttiger committed
1030
1031
1032
1033
        return p;
    }
};

Paul's avatar
Paul committed
1034
1035
struct test_conv_bn
{
Paul's avatar
Paul committed
1036
    migraphx::program create_program() const
Paul's avatar
Paul committed
1037
    {
Paul's avatar
Paul committed
1038
        migraphx::program p;
Paul's avatar
Paul committed
1039

Paul's avatar
Paul committed
1040
1041
1042
        migraphx::shape xs{migraphx::shape::float_type, {1, 3, 224, 224}};
        migraphx::shape ws{migraphx::shape::float_type, {64, 3, 7, 7}};
        migraphx::shape vars{migraphx::shape::float_type, {64}};
Paul's avatar
Paul committed
1043
1044
        auto x        = p.add_parameter("x", xs);
        auto w        = p.add_parameter("w", ws);
Paul's avatar
Paul committed
1045
1046
1047
1048
1049
1050
        auto conv     = p.add_instruction(migraphx::op::convolution{{3, 3}, {2, 2}, {1, 1}}, x, w);
        auto scale    = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
        auto bias     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
        auto mean     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
        auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
        p.add_instruction(migraphx::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
Paul's avatar
Paul committed
1051
1052
1053
1054
        return p;
    }
};

Paul's avatar
Paul committed
1055
1056
struct test_conv_bn_relu_pooling
{
Paul's avatar
Paul committed
1057
    migraphx::program create_program() const
Paul's avatar
Paul committed
1058
    {
Paul's avatar
Paul committed
1059
        migraphx::program p;
Paul's avatar
Paul committed
1060

Paul's avatar
Paul committed
1061
1062
1063
        migraphx::shape xs{migraphx::shape::float_type, {1, 3, 224, 224}};
        migraphx::shape ws{migraphx::shape::float_type, {64, 3, 7, 7}};
        migraphx::shape vars{migraphx::shape::float_type, {64}};
Paul's avatar
Paul committed
1064
1065
        auto x        = p.add_parameter("x", xs);
        auto w        = p.add_parameter("w", ws);
Paul's avatar
Paul committed
1066
1067
1068
1069
1070
        auto conv     = p.add_instruction(migraphx::op::convolution{{3, 3}, {2, 2}, {1, 1}}, x, w);
        auto scale    = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
        auto bias     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
        auto mean     = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
        auto variance = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
wsttiger's avatar
wsttiger committed
1071
        auto bn       = p.add_instruction(
Paul's avatar
Paul committed
1072
1073
1074
            migraphx::op::batch_norm_inference{}, conv, scale, bias, mean, variance);
        auto relu = p.add_instruction(migraphx::op::relu{}, bn);
        p.add_instruction(migraphx::op::pooling{"average", {1, 1}, {2, 2}, {3, 3}}, relu);
Paul's avatar
Paul committed
1075
1076
1077
1078
        return p;
    }
};

1079
1080
struct test_concat
{
Paul's avatar
Paul committed
1081
    migraphx::program create_program() const
1082
    {
Paul's avatar
Paul committed
1083
        migraphx::program p;
wsttiger's avatar
wsttiger committed
1084
        std::size_t axis = 1;
Paul's avatar
Paul committed
1085
1086
1087
        migraphx::shape s0{migraphx::shape::int32_type, {2, 2}};
        migraphx::shape s1{migraphx::shape::int32_type, {2, 3}};
        migraphx::shape s2{migraphx::shape::int32_type, {2, 1}};
1088
1089
1090
        auto l0 = p.add_parameter("x", s0);
        auto l1 = p.add_parameter("y", s1);
        auto l2 = p.add_parameter("z", s2);
Paul's avatar
Paul committed
1091
        p.add_instruction(migraphx::op::concat{axis}, l0, l1, l2);
1092
1093
1094
1095
1096
1097
        return p;
    }
};

struct test_concat2
{
Paul's avatar
Paul committed
1098
    migraphx::program create_program() const
1099
    {
Paul's avatar
Paul committed
1100
        migraphx::program p;
wsttiger's avatar
wsttiger committed
1101
        std::size_t axis = 0;
Paul's avatar
Paul committed
1102
1103
1104
        migraphx::shape s0{migraphx::shape::int32_type, {2, 2}};
        migraphx::shape s1{migraphx::shape::int32_type, {3, 2}};
        migraphx::shape s2{migraphx::shape::int32_type, {1, 2}};
1105
1106
1107
        auto l0 = p.add_parameter("x", s0);
        auto l1 = p.add_parameter("y", s1);
        auto l2 = p.add_parameter("z", s2);
Paul's avatar
Paul committed
1108
        p.add_instruction(migraphx::op::concat{axis}, l0, l1, l2);
1109
1110
1111
1112
        return p;
    }
};

wsttiger's avatar
wsttiger committed
1113
1114
struct test_concat_relu
{
Paul's avatar
Paul committed
1115
    migraphx::program create_program() const
wsttiger's avatar
wsttiger committed
1116
    {
Paul's avatar
Paul committed
1117
        migraphx::program p;
wsttiger's avatar
wsttiger committed
1118
        std::size_t axis = 0;
Paul's avatar
Paul committed
1119
1120
1121
        migraphx::shape s0{migraphx::shape::float_type, {2, 2}};
        migraphx::shape s1{migraphx::shape::float_type, {3, 2}};
        migraphx::shape s2{migraphx::shape::float_type, {1, 2}};
wsttiger's avatar
wsttiger committed
1122
1123
1124
        auto l0 = p.add_parameter("x", s0);
        auto l1 = p.add_parameter("y", s1);
        auto l2 = p.add_parameter("z", s2);
Paul's avatar
Paul committed
1125
1126
1127
1128
1129
        auto r0 = p.add_instruction(migraphx::op::relu{}, l0);
        auto r1 = p.add_instruction(migraphx::op::relu{}, l1);
        auto r2 = p.add_instruction(migraphx::op::relu{}, l2);
        auto c0 = p.add_instruction(migraphx::op::concat{axis}, r0, r1, r2);
        p.add_instruction(migraphx::op::relu{}, c0);
wsttiger's avatar
wsttiger committed
1130
1131
1132
1133
        return p;
    }
};

1134
1135
1136
1137
1138
1139
struct test_pad
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s0{migraphx::shape::int32_type, {1, 96, 165, 165}};
Khalique's avatar
Khalique committed
1140
1141
1142
1143
        std::vector<int64_t> pads0 = {0, 0, 0, 0, 0, 0, 1, 1};
        std::vector<int64_t> pads1 = {0, 0, 0, 0, 1, 1, 1, 1};
        std::vector<int64_t> pads2 = {1, 1, 1, 1, 0, 0, 0, 0};
        std::vector<int64_t> pads3 = {1, 0, 1, 0, 1, 0, 2, 0};
Khalique's avatar
Khalique committed
1144
        auto l0                    = p.add_parameter("x", s0);
Khalique's avatar
Khalique committed
1145
1146
1147
        p.add_instruction(migraphx::op::pad{pads0}, l0);
        p.add_instruction(migraphx::op::pad{pads1}, l0);
        p.add_instruction(migraphx::op::pad{pads2}, l0);
Khalique's avatar
Khalique committed
1148
        p.add_instruction(migraphx::op::pad{pads3}, l0);
Khalique's avatar
Khalique committed
1149
        return p;
Khalique's avatar
Khalique committed
1150
    }
Khalique's avatar
Khalique committed
1151
};
Khalique's avatar
Khalique committed
1152

1153
1154
1155
1156
1157
1158
1159
1160
1161
struct test_pooling_autopad
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s0{migraphx::shape::float_type, {1, 3, 63, 63}};
        auto l0 = p.add_parameter("x", s0);
        migraphx::op::pooling op{"max"};
        op.padding_mode = migraphx::op::padding_mode_t::same;
Khalique's avatar
Khalique committed
1162
1163
        op.lengths      = {2, 2};
        op.stride       = {2, 2};
1164
1165
1166
1167
1168
        p.add_instruction(op, l0);
        return p;
    }
};

1169
1170
1171
1172
1173
1174
1175
1176
struct test_gather
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3, 3}};
        migraphx::shape s_indices{migraphx::shape::int32_type, {2, 2}};
        std::vector<int> indices{1, 2, 2, 1};
Shucai Xiao's avatar
Shucai Xiao committed
1177
1178
        auto a0  = p.add_parameter("data", s);
        auto a1  = p.add_literal(migraphx::literal{s_indices, indices});
1179
        int axis = 0;
1180
        p.add_instruction(migraphx::op::gather{axis}, a0, a1);
1181
1182
1183
1184
        return p;
    }
};

1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
struct test_gather_neg_axis
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3, 3}};
        migraphx::shape s_indices{migraphx::shape::int32_type, {2, 2}};
        std::vector<int> indices{1, 2, 2, 1};
        auto a0  = p.add_parameter("data", s);
        auto a1  = p.add_literal(migraphx::literal{s_indices, indices});
        int axis = -1;
        p.add_instruction(migraphx::op::gather{axis}, a0, a1);
        return p;
    }
};

1201
1202
1203
1204
1205
1206
struct test_gather_scalar_output
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
1207
        migraphx::shape s_indices{migraphx::shape::int32_type};
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
        std::vector<int> indices{1};
        auto a0  = p.add_parameter("data", s);
        auto a1  = p.add_literal(migraphx::literal{s_indices, indices});
        int axis = 0;
        p.add_instruction(migraphx::op::gather{axis}, a0, a1);
        return p;
    }
};

struct test_gather_scalar_index
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3, 3}};
1223
        migraphx::shape s_indices{migraphx::shape::int32_type};
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
        std::vector<int> indices{1};
        auto a0  = p.add_parameter("data", s);
        auto a1  = p.add_literal(migraphx::literal{s_indices, indices});
        int axis = -1;
        p.add_instruction(migraphx::op::gather{axis}, a0, a1);
        return p;
    }
};

struct test_gather_1d_index
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3, 3}};
        migraphx::shape s_indices{migraphx::shape::int32_type, {1}};
        std::vector<int> indices{1};
        auto a0  = p.add_parameter("data", s);
        auto a1  = p.add_literal(migraphx::literal{s_indices, indices});
        int axis = -1;
        p.add_instruction(migraphx::op::gather{axis}, a0, a1);
        return p;
    }
};

wsttiger's avatar
wsttiger committed
1249
1250
void manual_identity()
{
Paul's avatar
Paul committed
1251
    migraphx::program p;
wsttiger's avatar
wsttiger committed
1252
    std::vector<float> data0 = {0, 1, 2, 3};
Paul's avatar
Paul committed
1253
1254
1255
1256
1257
    migraphx::shape s0{migraphx::shape::float_type, {2, 2}};
    auto l0 = p.add_literal(migraphx::literal{s0, data0});
    p.add_instruction(migraphx::op::identity{}, l0);
    p.compile(migraphx::gpu::target{});
    migraphx::program::parameter_map m;
wsttiger's avatar
wsttiger committed
1258
1259
    for(auto&& x : p.get_parameter_shapes())
    {
Paul's avatar
Paul committed
1260
        m[x.first] = migraphx::gpu::to_gpu(migraphx::generate_argument(x.second));
wsttiger's avatar
wsttiger committed
1261
    }
Paul's avatar
Paul committed
1262
    auto result = migraphx::gpu::from_gpu(p.eval(m));
wsttiger's avatar
wsttiger committed
1263
1264
1265
1266
1267
    std::cout << result << std::endl;
}

void manual_test_concat_relu()
{
Paul's avatar
Paul committed
1268
    migraphx::program p;
wsttiger's avatar
wsttiger committed
1269
    std::size_t axis         = 0;
wsttiger's avatar
wsttiger committed
1270
1271
1272
    std::vector<float> data0 = {0, 1, 2, 3};
    std::vector<float> data1 = {4, 5, 6, 7, 8, 9};
    std::vector<float> data2 = {10, 11};
Paul's avatar
Paul committed
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
    migraphx::shape s0{migraphx::shape::float_type, {2, 2}};
    migraphx::shape s1{migraphx::shape::float_type, {3, 2}};
    migraphx::shape s2{migraphx::shape::float_type, {1, 2}};
    auto l0 = p.add_literal(migraphx::literal{s0, data0});
    auto l1 = p.add_literal(migraphx::literal{s1, data1});
    auto l2 = p.add_literal(migraphx::literal{s2, data2});
    auto r0 = p.add_instruction(migraphx::op::relu{}, l0);
    auto r1 = p.add_instruction(migraphx::op::relu{}, l1);
    auto r2 = p.add_instruction(migraphx::op::relu{}, l2);
    auto c0 = p.add_instruction(migraphx::op::concat{axis}, r0, r1, r2);
    p.add_instruction(migraphx::op::relu{}, c0);

    p.compile(migraphx::gpu::target{});
    migraphx::program::parameter_map m;
wsttiger's avatar
wsttiger committed
1287
1288
    for(auto&& x : p.get_parameter_shapes())
    {
Paul's avatar
Paul committed
1289
        m[x.first] = migraphx::gpu::to_gpu(migraphx::generate_argument(x.second));
wsttiger's avatar
wsttiger committed
1290
    }
Paul's avatar
Paul committed
1291
    auto result = migraphx::gpu::from_gpu(p.eval(m));
wsttiger's avatar
wsttiger committed
1292
1293
1294
    std::cout << result << std::endl;
}

Paul's avatar
Paul committed
1295
1296
struct test_conv_bn_relu_pooling2
{
Paul's avatar
Paul committed
1297
1298
    static migraphx::instruction_ref
    add_bn(migraphx::program& p, migraphx::instruction_ref x, std::size_t channels)
Paul's avatar
Paul committed
1299
    {
Paul's avatar
Paul committed
1300
        migraphx::shape vars{migraphx::shape::float_type, {channels}};
Paul's avatar
Paul committed
1301
1302
1303
1304
1305
        auto scale = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 1 + channels)));
        auto bias  = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 2 + channels)));
        auto mean  = p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 3 + channels)));
        auto variance =
            p.add_literal(migraphx::abs(migraphx::generate_literal(vars, 4 + channels)));
wsttiger's avatar
wsttiger committed
1306
        return p.add_instruction(
Paul's avatar
Paul committed
1307
            migraphx::op::batch_norm_inference{}, x, scale, bias, mean, variance);
Paul's avatar
Paul committed
1308
    }
Paul's avatar
Paul committed
1309
    migraphx::program create_program() const
Paul's avatar
Paul committed
1310
    {
Paul's avatar
Paul committed
1311
        migraphx::program p;
Paul's avatar
Paul committed
1312

Paul's avatar
Paul committed
1313
1314
1315
1316
        migraphx::shape xs1{migraphx::shape::float_type, {1, 512, 7, 7}};
        migraphx::shape xs2{migraphx::shape::float_type, {1, 1024, 14, 14}};
        migraphx::shape ws1{migraphx::shape::float_type, {2048, 512, 1, 1}};
        migraphx::shape ws2{migraphx::shape::float_type, {2048, 1024, 1, 1}};
Paul's avatar
Paul committed
1317
1318
        auto x1    = p.add_parameter("x1", xs1);
        auto w1    = p.add_parameter("w1", ws1);
Paul's avatar
Paul committed
1319
        auto conv1 = p.add_instruction(migraphx::op::convolution{{0, 0}, {1, 1}, {1, 1}}, x1, w1);
Paul's avatar
Paul committed
1320
1321
1322
        auto bn1   = add_bn(p, conv1, 2048);
        auto x2    = p.add_parameter("x2", xs2);
        auto w2    = p.add_parameter("w2", ws2);
Paul's avatar
Paul committed
1323
        auto conv2 = p.add_instruction(migraphx::op::convolution{{0, 0}, {2, 2}, {1, 1}}, x2, w2);
Paul's avatar
Paul committed
1324
        auto bn2   = add_bn(p, conv2, 2048);
Paul's avatar
Paul committed
1325
1326
1327
        auto add   = p.add_instruction(migraphx::op::add{}, bn1, bn2);
        auto relu  = p.add_instruction(migraphx::op::relu{}, add);
        p.add_instruction(migraphx::op::pooling{"average", {1, 1}, {2, 2}, {3, 3}}, relu);
Paul's avatar
Paul committed
1328
1329
1330
1331
        return p;
    }
};

1332
1333
1334
1335
1336
struct test_rnn_forward
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
1337
        std::size_t seq_len     = 1;
1338
1339
1340
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 1;
Shucai Xiao's avatar
Shucai Xiao committed
1341
        float clip              = 0.0f;
1342
1343
1344
1345
1346
1347

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
1348
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
1349

Shucai Xiao's avatar
Shucai Xiao committed
1350
        auto seq  = p.add_parameter("seq", in_shape);
1351
1352
1353
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1354
        auto ih   = p.add_parameter("ih", ih_shape);
1355
        auto und  = p.add_instruction(migraphx::op::undefined{});
Shucai Xiao's avatar
Shucai Xiao committed
1356

1357
1358
1359
        auto output =
            p.add_instruction(migraphx::op::rnn{hidden_size,
                                                {migraphx::op::tanh{}, migraphx::op::tanh{}},
1360
                                                migraphx::op::rnn_direction::forward,
1361
1362
1363
1364
1365
                                                clip},
                              seq,
                              w,
                              r,
                              bias,
1366
                              und,
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
                              ih);
        p.add_instruction(migraphx::op::rnn_last_output{}, output);

        return p;
    }
};

struct test_rnn_forward10
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 10;
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1393
1394
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
1395
        auto bias = p.add_parameter("bias", b_shape);
1396
        auto ih   = p.add_parameter("ih", ih_shape);
1397
        auto und  = p.add_instruction(migraphx::op::undefined{});
1398

Shucai Xiao's avatar
Shucai Xiao committed
1399
1400
1401
        auto output =
            p.add_instruction(migraphx::op::rnn{hidden_size,
                                                {migraphx::op::tanh{}, migraphx::op::tanh{}},
1402
                                                migraphx::op::rnn_direction::forward,
Shucai Xiao's avatar
Shucai Xiao committed
1403
1404
1405
1406
1407
                                                clip},
                              seq,
                              w,
                              r,
                              bias,
1408
                              und,
Shucai Xiao's avatar
Shucai Xiao committed
1409
                              ih);
Shucai Xiao's avatar
Shucai Xiao committed
1410
        p.add_instruction(migraphx::op::rnn_last_output{}, output);
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420

        return p;
    }
};

struct test_rnn_reverse
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
1421
        std::size_t seq_len     = 1;
1422
1423
1424
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 1;
Shucai Xiao's avatar
Shucai Xiao committed
1425
        float clip              = 0.0f;
1426
1427
1428
1429
1430
1431

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
1432
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
1433

Shucai Xiao's avatar
Shucai Xiao committed
1434
        auto seq  = p.add_parameter("seq", in_shape);
1435
1436
1437
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1438
        auto ih   = p.add_parameter("ih", ih_shape);
1439
        auto und  = p.add_instruction(migraphx::op::undefined{});
1440
1441
1442

        p.add_instruction(migraphx::op::rnn{hidden_size,
                                            {migraphx::op::tanh{}, migraphx::op::tanh{}},
1443
                                            migraphx::op::rnn_direction::reverse,
1444
1445
1446
1447
1448
                                            clip},
                          seq,
                          w,
                          r,
                          bias,
1449
                          und,
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
                          ih);

        return p;
    }
};

struct test_rnn_reverse2
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 2;
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1475
1476
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
1477
        auto bias = p.add_parameter("bias", b_shape);
1478
        auto ih   = p.add_parameter("ih", ih_shape);
1479
        auto und  = p.add_instruction(migraphx::op::undefined{});
1480

Shucai Xiao's avatar
Shucai Xiao committed
1481
1482
        p.add_instruction(migraphx::op::rnn{hidden_size,
                                            {migraphx::op::tanh{}, migraphx::op::tanh{}},
1483
                                            migraphx::op::rnn_direction::reverse,
Shucai Xiao's avatar
Shucai Xiao committed
1484
1485
1486
1487
1488
                                            clip},
                          seq,
                          w,
                          r,
                          bias,
1489
                          und,
Shucai Xiao's avatar
Shucai Xiao committed
1490
                          ih);
Shucai Xiao's avatar
Shucai Xiao committed
1491

1492
1493
1494
1495
        return p;
    }
};

1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
struct test_rnn_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};

Shucai Xiao's avatar
Shucai Xiao committed
1512
1513
1514
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
1515
1516
1517

        p.add_instruction(migraphx::op::rnn{hidden_size,
                                            {migraphx::op::tanh{}, migraphx::op::tanh{}},
1518
                                            migraphx::op::rnn_direction::reverse,
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
                                            clip},
                          seq,
                          w,
                          r);

        return p;
    }
};

struct test_rnn_4args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 5;
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);

        p.add_instruction(migraphx::op::rnn{hidden_size,
                                            {migraphx::op::tanh{}, migraphx::op::tanh{}},
1552
                                            migraphx::op::rnn_direction::reverse,
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
                                            clip},
                          seq,
                          w,
                          r,
                          bias);

        return p;
    }
};

struct test_rnn_5args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 10;
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
1584
        auto und  = p.add_instruction(migraphx::op::undefined{});
1585
1586
1587
1588

        auto output =
            p.add_instruction(migraphx::op::rnn{hidden_size,
                                                {migraphx::op::tanh{}, migraphx::op::tanh{}},
1589
                                                migraphx::op::rnn_direction::forward,
1590
1591
1592
1593
                                                clip},
                              seq,
                              w,
                              r,
1594
1595
                              bias,
                              und);
1596
1597
1598
1599
1600
1601
        p.add_instruction(migraphx::op::rnn_last_output{}, output);

        return p;
    }
};

1602
1603
1604
1605
1606
struct test_rnn_bidirectional
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
1607
        std::size_t seq_len     = 1;
1608
1609
1610
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 2;
Shucai Xiao's avatar
Shucai Xiao committed
1611
        float clip              = 0.0f;
1612
1613
1614
1615
1616
1617

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
1618
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
1619

Shucai Xiao's avatar
Shucai Xiao committed
1620
        auto seq  = p.add_parameter("seq", in_shape);
1621
1622
1623
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1624
        auto ih   = p.add_parameter("ih", ih_shape);
1625
        auto und  = p.add_instruction(migraphx::op::undefined{});
1626
1627
1628
1629

        auto output =
            p.add_instruction(migraphx::op::rnn{hidden_size,
                                                {migraphx::op::tanh{}, migraphx::op::tanh{}},
1630
                                                migraphx::op::rnn_direction::bidirectional,
1631
1632
1633
1634
1635
                                                clip},
                              seq,
                              w,
                              r,
                              bias,
1636
                              und,
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
                              ih);
        p.add_instruction(migraphx::op::rnn_last_output{}, output);

        return p;
    }
};

struct test_rnn_bidirectional10
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 10;
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1663
1664
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
1665
        auto bias = p.add_parameter("bias", b_shape);
1666
        auto ih   = p.add_parameter("ih", ih_shape);
1667
        auto und  = p.add_instruction(migraphx::op::undefined{});
Shucai Xiao's avatar
Shucai Xiao committed
1668
1669
1670
        auto output =
            p.add_instruction(migraphx::op::rnn{hidden_size,
                                                {migraphx::op::tanh{}, migraphx::op::tanh{}},
1671
                                                migraphx::op::rnn_direction::bidirectional,
Shucai Xiao's avatar
Shucai Xiao committed
1672
1673
1674
1675
1676
                                                clip},
                              seq,
                              w,
                              r,
                              bias,
1677
                              und,
Shucai Xiao's avatar
Shucai Xiao committed
1678
                              ih);
Shucai Xiao's avatar
Shucai Xiao committed
1679
        p.add_instruction(migraphx::op::rnn_last_output{}, output);
Shucai Xiao's avatar
Shucai Xiao committed
1680

1681
1682
1683
1684
        return p;
    }
};

1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
struct test_rnn_bi_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 10;
        std::size_t hidden_size = 4;
        std::size_t input_size  = 3;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type, {num_dirct, hidden_size, hidden_size}};
1700
1701
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 2 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
1702

Shucai Xiao's avatar
Shucai Xiao committed
1703
1704
1705
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
1706
1707
1708
        auto output =
            p.add_instruction(migraphx::op::rnn{hidden_size,
                                                {migraphx::op::tanh{}, migraphx::op::tanh{}},
1709
                                                migraphx::op::rnn_direction::bidirectional,
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
                                                clip},
                              seq,
                              w,
                              r);
        p.add_instruction(migraphx::op::rnn_last_output{}, output);

        return p;
    }
};

Shucai Xiao's avatar
Shucai Xiao committed
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
struct test_gru_forward_last
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1733
1734
1735
1736
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        auto output =
            p.add_instruction(migraphx::op::gru{hidden_size,
                                                {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
1750
                                                migraphx::op::rnn_direction::forward,
Shucai Xiao's avatar
Shucai Xiao committed
1751
1752
1753
1754
1755
1756
1757
                                                clip},
                              seq,
                              w,
                              r,
                              bias,
                              und,
                              ih);
1758
        p.add_instruction(migraphx::op::rnn_last_output{}, output);
Shucai Xiao's avatar
Shucai Xiao committed
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776

        return p;
    }
};

struct test_gru_forward_hs
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1777
1778
1779
1780
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
1792
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
1793
                                            migraphx::op::rnn_direction::forward,
Shucai Xiao's avatar
Shucai Xiao committed
1794
1795
1796
1797
1798
1799
1800
                                            clip},
                          seq,
                          w,
                          r,
                          bias,
                          und,
                          ih);
Shucai Xiao's avatar
Shucai Xiao committed
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818

        return p;
    }
};

struct test_gru_forward_3args_und
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1819
1820
1821
1822
1823
1824
1825
1826
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        auto und = p.add_instruction(migraphx::op::undefined{});
Shucai Xiao's avatar
Shucai Xiao committed
1827
        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
1828
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
1829
                                            migraphx::op::rnn_direction::forward,
Shucai Xiao's avatar
Shucai Xiao committed
1830
1831
1832
1833
1834
1835
1836
                                            clip},
                          seq,
                          w,
                          r,
                          und,
                          und,
                          und);
Shucai Xiao's avatar
Shucai Xiao committed
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854

        return p;
    }
};

struct test_gru_forward_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1855
1856
1857
1858
1859
1860
1861
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1862
        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
1863
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
1864
                                            migraphx::op::rnn_direction::forward,
Shucai Xiao's avatar
Shucai Xiao committed
1865
1866
1867
1868
                                            clip},
                          seq,
                          w,
                          r);
Shucai Xiao's avatar
Shucai Xiao committed
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886

        return p;
    }
};

struct test_gru_forward_seq1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1887
1888
1889
1890
1891
1892
1893
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
1894
        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
1895
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
1896
                                            migraphx::op::rnn_direction::forward,
Shucai Xiao's avatar
Shucai Xiao committed
1897
1898
1899
1900
                                            clip},
                          seq,
                          w,
                          r);
Shucai Xiao's avatar
Shucai Xiao committed
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918

        return p;
    }
};

struct test_gru_forward_default_actv
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1919
1920
1921
1922
1923
1924
1925
1926
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        p.add_instruction(
Shucai Xiao's avatar
Shucai Xiao committed
1927
1928
1929
1930
            migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::forward, clip},
            seq,
            w,
            r);
Shucai Xiao's avatar
Shucai Xiao committed
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948

        return p;
    }
};

struct test_gru_forward_default_actv1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1949
1950
1951
1952
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

Shucai Xiao's avatar
Shucai Xiao committed
1963
1964
        p.add_instruction(
            migraphx::op::gru{
1965
                hidden_size, {migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::forward, clip},
Shucai Xiao's avatar
Shucai Xiao committed
1966
1967
1968
1969
1970
1971
            seq,
            w,
            r,
            bias,
            und,
            ih);
Shucai Xiao's avatar
Shucai Xiao committed
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989

        return p;
    }
};

struct test_gru_reverse_last
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1990
1991
1992
1993
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
Shucai Xiao's avatar
Shucai Xiao committed
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        auto output =
            p.add_instruction(migraphx::op::gru{hidden_size,
                                                {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
2007
                                                migraphx::op::rnn_direction::reverse,
Shucai Xiao's avatar
Shucai Xiao committed
2008
2009
2010
2011
2012
2013
2014
                                                clip},
                              seq,
                              w,
                              r,
                              bias,
                              und,
                              ih);
2015
        p.add_instruction(migraphx::op::rnn_last_output{}, output);
Shucai Xiao's avatar
Shucai Xiao committed
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033

        return p;
    }
};

struct test_gru_reverse_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2034
2035
2036
2037
2038
2039
2040
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2041
        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2042
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
2043
                                            migraphx::op::rnn_direction::reverse,
Shucai Xiao's avatar
Shucai Xiao committed
2044
2045
2046
2047
                                            clip},
                          seq,
                          w,
                          r);
Shucai Xiao's avatar
Shucai Xiao committed
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065

        return p;
    }
};

struct test_gru_bidirct_last
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2066
2067
2068
2069
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        auto output =
            p.add_instruction(migraphx::op::gru{hidden_size,
                                                {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
2083
                                                migraphx::op::rnn_direction::bidirectional,
Shucai Xiao's avatar
Shucai Xiao committed
2084
2085
2086
2087
2088
2089
2090
                                                clip},
                              seq,
                              w,
                              r,
                              bias,
                              und,
                              ih);
2091
        p.add_instruction(migraphx::op::rnn_last_output{}, output);
Shucai Xiao's avatar
Shucai Xiao committed
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109

        return p;
    }
};

struct test_gru_bidirct_hs
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2110
2111
2112
2113
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2125
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
2126
                                            migraphx::op::rnn_direction::bidirectional,
Shucai Xiao's avatar
Shucai Xiao committed
2127
2128
2129
2130
2131
2132
2133
                                            clip},
                          seq,
                          w,
                          r,
                          bias,
                          und,
                          ih);
Shucai Xiao's avatar
Shucai Xiao committed
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151

        return p;
    }
};

struct test_gru_bidirct_3args_und
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2152
2153
2154
2155
2156
2157
2158
2159
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        auto und = p.add_instruction(migraphx::op::undefined{});
Shucai Xiao's avatar
Shucai Xiao committed
2160
        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2161
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
2162
                                            migraphx::op::rnn_direction::bidirectional,
Shucai Xiao's avatar
Shucai Xiao committed
2163
2164
2165
2166
2167
2168
2169
                                            clip},
                          seq,
                          w,
                          r,
                          und,
                          und,
                          und);
Shucai Xiao's avatar
Shucai Xiao committed
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187

        return p;
    }
};

struct test_gru_bidirct_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2188
2189
2190
2191
2192
2193
2194
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2195
        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2196
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
2197
                                            migraphx::op::rnn_direction::bidirectional,
Shucai Xiao's avatar
Shucai Xiao committed
2198
2199
2200
2201
                                            clip},
                          seq,
                          w,
                          r);
Shucai Xiao's avatar
Shucai Xiao committed
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219

        return p;
    }
};

struct test_gru_bidirct_seq1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2220
2221
2222
2223
2224
2225
2226
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2227
        p.add_instruction(migraphx::op::gru{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2228
                                            {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
2229
                                            migraphx::op::rnn_direction::bidirectional,
Shucai Xiao's avatar
Shucai Xiao committed
2230
2231
2232
2233
                                            clip},
                          seq,
                          w,
                          r);
Shucai Xiao's avatar
Shucai Xiao committed
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251

        return p;
    }
};

struct test_gru_bidirct_default_actv
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2252
2253
2254
2255
2256
2257
2258
2259
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        p.add_instruction(
Shucai Xiao's avatar
Shucai Xiao committed
2260
2261
2262
2263
            migraphx::op::gru{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip},
            seq,
            w,
            r);
Shucai Xiao's avatar
Shucai Xiao committed
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281

        return p;
    }
};

struct test_gru_bidirct_default_actv1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2282
2283
2284
2285
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 3 * hidden_size, hidden_size}};
Shucai Xiao's avatar
Shucai Xiao committed
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 6 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

Shucai Xiao's avatar
Shucai Xiao committed
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
        p.add_instruction(migraphx::op::gru{hidden_size,
                                            {migraphx::op::sigmoid{}},
                                            migraphx::op::rnn_direction::bidirectional,
                                            clip},
                          seq,
                          w,
                          r,
                          bias,
                          und,
                          ih);
Shucai Xiao's avatar
Shucai Xiao committed
2306
2307
2308
2309
2310

        return p;
    }
};

2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
struct test_lstm_forward_last
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto ic   = p.add_parameter("ic", ic_shape);
        auto pph  = p.add_parameter("pph", pph_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

Shucai Xiao's avatar
Shucai Xiao committed
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
        auto output = p.add_instruction(
            migraphx::op::gru{hidden_size,
                              {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                              migraphx::op::rnn_direction::forward,
                              clip},
            seq,
            w,
            r,
            bias,
            und,
            ih,
            ic,
            pph);
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
        p.add_instruction(migraphx::op::rnn_last_output{}, output);

        return p;
    }
};

struct test_lstm_forward_hs
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto ic   = p.add_parameter("ic", ic_shape);
        auto pph  = p.add_parameter("pph", pph_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

Shucai Xiao's avatar
Shucai Xiao committed
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
        p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::forward,
                clip},
            seq,
            w,
            r,
            bias,
            und,
            ih,
            ic,
            pph);
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431

        return p;
    }
};

struct test_lstm_forward_3args_und
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        auto und = p.add_instruction(migraphx::op::undefined{});
Shucai Xiao's avatar
Shucai Xiao committed
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
        p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::forward,
                clip},
            seq,
            w,
            r,
            und,
            und,
            und,
            und,
            und);
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470

        return p;
    }
};

struct test_lstm_forward_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2471
2472
2473
2474
2475
2476
2477
2478
2479
        p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::forward,
                clip},
            seq,
            w,
            r);
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504

        return p;
    }
};

struct test_lstm_forward_seq1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2505
2506
2507
2508
2509
2510
2511
2512
2513
        p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::forward,
                clip},
            seq,
            w,
            r);
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620

        return p;
    }
};

struct test_lstm_forward_default_actv
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        p.add_instruction(
            migraphx::op::lstm{hidden_size, {}, migraphx::op::rnn_direction::forward, clip},
            seq,
            w,
            r);

        return p;
    }
};

struct test_lstm_forward_default_actv1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        p.add_instruction(
            migraphx::op::lstm{
                hidden_size, {migraphx::op::sigmoid{}}, migraphx::op::rnn_direction::forward, clip},
            seq,
            w,
            r,
            bias,
            und,
            ih);

        return p;
    }
};

struct test_lstm_reverse_last
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto ic   = p.add_parameter("ic", ic_shape);
        auto pph  = p.add_parameter("pph", pph_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

Shucai Xiao's avatar
Shucai Xiao committed
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
        auto output = p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::reverse,
                clip},
            seq,
            w,
            r,
            bias,
            und,
            ih,
            ic,
            pph);
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
        p.add_instruction(migraphx::op::rnn_last_output{}, output);

        return p;
    }
};

struct test_lstm_reverse_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2661
2662
2663
2664
2665
2666
2667
2668
2669
        p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::reverse,
                clip},
            seq,
            w,
            r);
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694

        return p;
    }
};

struct test_lstm_reverse_3args_cell_output
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 1;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2695
2696
2697
2698
2699
2700
2701
2702
2703
        auto hs  = p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::reverse,
                clip},
            seq,
            w,
            r);
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
        p.add_instruction(migraphx::op::lstm_last_cell_output{}, hs);

        return p;
    }
};

struct test_lstm_bidirct_last
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape ic_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};
        migraphx::shape pph_shape{migraphx::shape::float_type, {num_dirct, 3 * hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto ic   = p.add_parameter("ic", ic_shape);
Shucai Xiao's avatar
Shucai Xiao committed
2738
        auto pph  = p.add_parameter("pph", pph_shape);
2739
2740
        auto und  = p.add_instruction(migraphx::op::undefined{});

Shucai Xiao's avatar
Shucai Xiao committed
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
        auto output = p.add_instruction(
            migraphx::op::lstm{
                hidden_size,
                {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                migraphx::op::rnn_direction::bidirectional,
                clip},
            seq,
            w,
            r,
            bias,
            und,
            ih,
            ic,
            pph);
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
        p.add_instruction(migraphx::op::rnn_last_output{}, output);

        return p;
    }
};

struct test_lstm_bidirct_hs
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        p.add_instruction(migraphx::op::lstm{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2789
2790
2791
                                             {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
                                             migraphx::op::rnn_direction::bidirectional,
                                             clip},
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
                          seq,
                          w,
                          r,
                          bias,
                          und,
                          ih);

        return p;
    }
};

struct test_lstm_bidirct_3args_und
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        auto und = p.add_instruction(migraphx::op::undefined{});
Shucai Xiao's avatar
Shucai Xiao committed
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
        p.add_instruction(
            migraphx::op::gru{hidden_size,
                              {migraphx::op::sigmoid{}, migraphx::op::tanh{}, migraphx::op::tanh{}},
                              migraphx::op::rnn_direction::bidirectional,
                              clip},
            seq,
            w,
            r,
            und,
            und,
            und,
            und,
            und);
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862

        return p;
    }
};

struct test_lstm_bidirct_3args
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        p.add_instruction(migraphx::op::lstm{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2863
2864
2865
                                             {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
                                             migraphx::op::rnn_direction::bidirectional,
                                             clip},
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
                          seq,
                          w,
                          r);

        return p;
    }
};

struct test_lstm_bidirct_seq1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        p.add_instruction(migraphx::op::lstm{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2895
2896
2897
                                             {migraphx::op::sigmoid{}, migraphx::op::tanh{}},
                                             migraphx::op::rnn_direction::bidirectional,
                                             clip},
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
                          seq,
                          w,
                          r);

        return p;
    }
};

struct test_lstm_bidirct_default_actv
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 1;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        auto seq = p.add_parameter("seq", in_shape);
        auto w   = p.add_parameter("w", w_shape);
        auto r   = p.add_parameter("r", r_shape);
        p.add_instruction(
            migraphx::op::lstm{hidden_size, {}, migraphx::op::rnn_direction::bidirectional, clip},
            seq,
            w,
            r);

        return p;
    }
};

struct test_lstm_bidirct_default_actv1
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        p.add_instruction(migraphx::op::lstm{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
2964
2965
2966
                                             {migraphx::op::sigmoid{}},
                                             migraphx::op::rnn_direction::bidirectional,
                                             clip},
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
                          seq,
                          w,
                          r,
                          bias,
                          und,
                          ih);

        return p;
    }
};

struct test_lstm_bidirct_default_actv2
{
    migraphx::program create_program() const
    {
        std::size_t batch_size  = 2;
        std::size_t seq_len     = 3;
        std::size_t hidden_size = 5;
        std::size_t input_size  = 8;
        std::size_t num_dirct   = 2;
        float clip              = 0.0f;

        migraphx::program p;
        migraphx::shape in_shape{migraphx::shape::float_type, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, input_size}};
        migraphx::shape r_shape{migraphx::shape::float_type,
                                {num_dirct, 4 * hidden_size, hidden_size}};
        migraphx::shape b_shape{migraphx::shape::float_type, {num_dirct, 8 * hidden_size}};
        migraphx::shape ih_shape{migraphx::shape::float_type, {num_dirct, batch_size, hidden_size}};

        auto seq  = p.add_parameter("seq", in_shape);
        auto w    = p.add_parameter("w", w_shape);
        auto r    = p.add_parameter("r", r_shape);
        auto bias = p.add_parameter("bias", b_shape);
        auto ih   = p.add_parameter("ih", ih_shape);
        auto und  = p.add_instruction(migraphx::op::undefined{});

        p.add_instruction(migraphx::op::lstm{hidden_size,
Shucai Xiao's avatar
Shucai Xiao committed
3006
3007
3008
                                             {migraphx::op::tanh{}, migraphx::op::sigmoid{}},
                                             migraphx::op::rnn_direction::bidirectional,
                                             clip},
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
                          seq,
                          w,
                          r,
                          bias,
                          und,
                          ih);

        return p;
    }
};

Shucai Xiao's avatar
Shucai Xiao committed
3020
template <int Axis>
3021
3022
3023
3024
3025
3026
3027
struct test_logsoftmax
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3, 4, 5, 6}};
        auto param = p.add_parameter("0", s);
Shucai Xiao's avatar
Shucai Xiao committed
3028
        p.add_instruction(migraphx::op::logsoftmax{Axis}, param);
3029
3030
3031
3032
3033

        return p;
    }
};

Shucai Xiao's avatar
Shucai Xiao committed
3034
template <int Axis>
3035
3036
3037
3038
3039
3040
3041
struct test_logsoftmax_1
{
    migraphx::program create_program() const
    {
        migraphx::program p;
        migraphx::shape s{migraphx::shape::float_type, {3}};
        auto param = p.add_parameter("0", s);
Shucai Xiao's avatar
Shucai Xiao committed
3042
        p.add_instruction(migraphx::op::logsoftmax{Axis}, param);
3043
3044
3045
3046
3047

        return p;
    }
};

Paul's avatar
Paul committed
3048
3049
int main()
{
Khalique's avatar
Khalique committed
3050
    verify_program<test_relu_lrn>();
3051
    verify_program<test_pooling_autopad>();
Khalique's avatar
Khalique committed
3052
    verify_program<test_abs>();
3053
3054
    verify_program<test_concat>();
    verify_program<test_concat2>();
wsttiger's avatar
wsttiger committed
3055
    verify_program<test_concat_relu>();
3056
    verify_program<test_pad>();
Paul's avatar
Paul committed
3057
    verify_program<test_add>();
Paul's avatar
Paul committed
3058
    verify_program<test_add_half>();
Khalique's avatar
Khalique committed
3059
    verify_program<test_mul>();
Shucai Xiao's avatar
Shucai Xiao committed
3060
3061
    verify_program<test_exp>();
    verify_program<test_log>();
3062
    verify_program<test_sin>();
3063
3064
    verify_program<test_cos>();
    verify_program<test_tan>();
3065
3066
    verify_program<test_sinh>();
    verify_program<test_cosh>();
3067
    verify_program<test_tanh>();
3068
3069
3070
    verify_program<test_asin>();
    verify_program<test_acos>();
    verify_program<test_atan>();
Khalique's avatar
Khalique committed
3071
    verify_program<test_scale>();
Paul's avatar
Paul committed
3072
3073
    verify_program<test_triadd>();
    verify_program<test_triadd2>();
Paul's avatar
Paul committed
3074
    verify_program<test_add_broadcast>();
Paul's avatar
Paul committed
3075
    verify_program<test_add_broadcast2>();
Paul's avatar
Latest  
Paul committed
3076
3077
    verify_program<test_add_broadcast3>();
    verify_program<test_add_broadcast4>();
Paul's avatar
Paul committed
3078
    verify_program<test_add_broadcast5>();
Paul's avatar
Paul committed
3079
    verify_program<test_triadd_broadcast>();
3080
3081
    verify_program<test_sub>();
    verify_program<test_sub2>();
Paul's avatar
Paul committed
3082
    verify_program<test_softmax>();
Paul's avatar
Paul committed
3083
    verify_program<test_softmax2>();
Paul's avatar
Paul committed
3084
    verify_program<test_conv>();
Paul's avatar
Paul committed
3085
    verify_program<test_conv2>();
Khalique's avatar
Khalique committed
3086
    verify_program<test_group_conv>();
Paul's avatar
Paul committed
3087
    verify_program<test_conv_relu>();
Paul's avatar
Paul committed
3088
    verify_program<test_conv_relu_half>();
Paul's avatar
Paul committed
3089
    verify_program<test_add_relu>();
3090
    verify_program<test_leaky_relu>();
Khalique's avatar
Khalique committed
3091
3092
    verify_program<test_sigmoid>();
    verify_program<test_elu>();
Paul's avatar
Paul committed
3093
    verify_program<test_conv_pooling>();
3094
3095
    verify_program<test_global_avg_pooling>();
    verify_program<test_global_max_pooling>();
Paul's avatar
Paul committed
3096
    verify_program<test_gemm>();
3097
    verify_program<test_gemm_ex>();
Paul's avatar
Paul committed
3098
    verify_program<test_gemm_half>();
3099
    // verify_program<test_gemm_ld>();
3100
    verify_program<test_gemm_transposeb>();
3101
    verify_program<test_gemm_transposeb_ex>();
3102
    verify_program<test_gemm_transposea>();
3103
    verify_program<test_gemm_transposea_ex>();
3104
    verify_program<test_gemm_transposeab>();
3105
3106
    verify_program<gemm_mutli_dim_2>();
    verify_program<gemm_mutli_dim_2_3>();
3107
    verify_program<gemm_mutli_3args>();
3108
3109
    verify_program<gemm_mutli_3args_beta0>();
    verify_program<gemm_mutli_3args_alpha0>();
3110
    verify_program<test_contiguous>();
3111
    verify_program<test_eliminate_contiguous>();
3112
    verify_program<test_transpose>();
3113
    verify_program<test_batchnorm_inference>();
Paul's avatar
Paul committed
3114
    verify_program<test_batchnorm_inference_2>();
Paul's avatar
Paul committed
3115
    verify_program<test_conv_bn>();
Paul's avatar
Paul committed
3116
    verify_program<test_conv_bn_relu_pooling>();
Paul's avatar
Paul committed
3117
    verify_program<test_conv_bn_relu_pooling2>();
3118
    verify_program<test_slice>();
3119
3120
    verify_program<test_gather>();
    verify_program<test_gather_neg_axis>();
3121
3122
3123
    verify_program<test_gather_scalar_output>();
    verify_program<test_gather_scalar_index>();
    verify_program<test_gather_1d_index>();
3124
    verify_program<test_rnn_forward>();
3125
    verify_program<test_rnn_forward10>();
Shucai Xiao's avatar
Shucai Xiao committed
3126
    verify_program<test_rnn_reverse>();
3127
3128
3129
3130
    verify_program<test_rnn_reverse2>();
    verify_program<test_rnn_3args>();
    verify_program<test_rnn_4args>();
    verify_program<test_rnn_5args>();
Shucai Xiao's avatar
Shucai Xiao committed
3131
    verify_program<test_rnn_bidirectional>();
3132
    verify_program<test_rnn_bidirectional10>();
3133
    verify_program<test_rnn_bi_3args>();
Shucai Xiao's avatar
Shucai Xiao committed
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
    verify_program<test_gru_forward_last>();
    verify_program<test_gru_forward_hs>();
    verify_program<test_gru_forward_3args_und>();
    verify_program<test_gru_forward_3args>();
    verify_program<test_gru_forward_seq1>();
    verify_program<test_gru_forward_default_actv>();
    verify_program<test_gru_forward_default_actv1>();
    verify_program<test_gru_reverse_last>();
    verify_program<test_gru_reverse_3args>();
    verify_program<test_gru_bidirct_last>();
    verify_program<test_gru_bidirct_hs>();
    verify_program<test_gru_bidirct_3args_und>();
    verify_program<test_gru_bidirct_3args>();
    verify_program<test_gru_bidirct_seq1>();
    verify_program<test_gru_bidirct_default_actv>();
    verify_program<test_gru_bidirct_default_actv1>();
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
    verify_program<test_lstm_forward_last>();
    verify_program<test_lstm_forward_hs>();
    verify_program<test_lstm_forward_3args_und>();
    verify_program<test_lstm_forward_3args>();
    verify_program<test_lstm_forward_seq1>();
    verify_program<test_lstm_forward_default_actv>();
    verify_program<test_lstm_forward_default_actv1>();
    verify_program<test_lstm_reverse_last>();
    verify_program<test_lstm_reverse_3args>();
    verify_program<test_lstm_reverse_3args_cell_output>();
    verify_program<test_lstm_bidirct_last>();
    verify_program<test_lstm_bidirct_hs>();
    verify_program<test_lstm_bidirct_3args_und>();
    verify_program<test_lstm_bidirct_3args>();
    verify_program<test_lstm_bidirct_seq1>();
    verify_program<test_lstm_bidirct_default_actv>();
    verify_program<test_lstm_bidirct_default_actv1>();
    verify_program<test_lstm_bidirct_default_actv2>();
3168
3169
3170
3171
3172
3173
3174
    verify_program<test_logsoftmax<0>>();
    verify_program<test_logsoftmax<1>>();
    verify_program<test_logsoftmax<2>>();
    verify_program<test_logsoftmax<3>>();
    verify_program<test_logsoftmax<4>>();
    verify_program<test_logsoftmax_1<0>>();
    verify_program<test_logsoftmax_1<1>>();
Paul's avatar
Paul committed
3175
}