"test/vscode:/vscode.git/clone" did not exist on "1e7457cbbdcb9ded7ff4f95f6dfec3aa2c775695"
test_rnn_sql_1.cpp 3.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
24
25
26
27

#include "verify_program.hpp"
#include <migraphx/program.hpp>
#include <migraphx/generate.hpp>
28
29
30
31
#include <migraphx/serialize.hpp>

#include <migraphx/make_op.hpp>

Paul's avatar
Paul committed
32
#include <migraphx/op/common.hpp>
33

Umang Yadav's avatar
Umang Yadav committed
34
35
template <migraphx::shape::type_t DType>
struct test_rnn_sql_1 : verify_program<test_rnn_sql_1<DType>>
36
37
38
39
40
41
42
43
44
45
46
{
    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;
47
        auto* mm = p.get_main_module();
Umang Yadav's avatar
Umang Yadav committed
48
49
50
51
        migraphx::shape in_shape{DType, {seq_len, batch_size, input_size}};
        migraphx::shape w_shape{DType, {num_dirct, hidden_size, input_size}};
        migraphx::shape r_shape{DType, {num_dirct, hidden_size, hidden_size}};
        migraphx::shape b_shape{DType, {num_dirct, 2 * hidden_size}};
52
        migraphx::shape s_shape{migraphx::shape::int32_type, {batch_size}};
Umang Yadav's avatar
Umang Yadav committed
53
        migraphx::shape ih_shape{DType, {num_dirct, batch_size, hidden_size}};
54

55
56
57
58
        auto seq  = mm->add_parameter("seq", in_shape);
        auto w    = mm->add_parameter("w", w_shape);
        auto r    = mm->add_parameter("r", r_shape);
        auto bias = mm->add_parameter("bias", b_shape);
59
        std::vector<int> sl_data{5, 7};
60
61
        auto sql = mm->add_literal(migraphx::literal{s_shape, sl_data});
        auto ih  = mm->add_parameter("ih", ih_shape);
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
        auto hs = mm->add_instruction(
            migraphx::make_op(
                "rnn",
                {{"hidden_size", hidden_size},
                 {"actv_func",
                  migraphx::to_value(std::vector<migraphx::operation>{migraphx::make_op("tanh"),
                                                                      migraphx::make_op("tanh")})},
                 {"direction", migraphx::to_value(migraphx::op::rnn_direction::forward)},
                 {"clip", clip}}),
            seq,
            w,
            r,
            bias,
            sql,
            ih);
        auto last_hs = mm->add_instruction(migraphx::make_op("rnn_last_hs_output"), hs);
79
        mm->add_return({hs, last_hs});
80
81
82
83
84

        return p;
    }
    std::string section() const { return "rnn"; }
};
Umang Yadav's avatar
Umang Yadav committed
85
86
87
88

template struct test_rnn_sql_1<migraphx::shape::float_type>;
template struct test_rnn_sql_1<migraphx::shape::half_type>;
template struct test_rnn_sql_1<migraphx::shape::fp8e4m3fnuz_type>;