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

Paul's avatar
Paul committed
28
namespace migraphx {
Paul's avatar
Paul committed
29
inline namespace MIGRAPHX_INLINE_NS {
Khalique's avatar
Khalique committed
30
31
32
33
34
35
36
37
38
namespace gpu {

shape miopen_leaky_relu::compute_shape(const std::vector<shape>& inputs) const
{
    check_shapes{inputs, *this}.has(2).not_broadcasted();
    return inputs.at(1);
}

argument miopen_leaky_relu::compute(context& ctx,
39
40
                                    const shape& output_shape,
                                    const std::vector<argument>& args) const
Khalique's avatar
Khalique committed
41
{
Paul's avatar
Paul committed
42
    float alpha = 1;
Paul's avatar
Paul committed
43
    float beta  = 0;
Khalique's avatar
Khalique committed
44
45
    auto x_desc = make_tensor(args[0].get_shape());
    auto y_desc = make_tensor(output_shape);
Paul's avatar
Paul committed
46
    miopenActivationForward(ctx.get_stream().get_miopen(),
Khalique's avatar
Khalique committed
47
48
49
50
51
52
53
54
55
56
57
                            ad.get(),
                            &alpha,
                            x_desc.get(),
                            args[0].implicit(),
                            &beta,
                            y_desc.get(),
                            args[1].implicit());

    return args[1];
}

Shucai Xiao's avatar
Shucai Xiao committed
58
59
60
61
62
void miopen_leaky_relu::finalize(context&, const shape&, const std::vector<shape>&)
{
    ad = make_leaky_relu(op.alpha);
}

Khalique's avatar
Khalique committed
63
} // namespace gpu
Paul's avatar
Paul committed
64
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
65
} // namespace migraphx