leaky_relu.cpp 1.23 KB
Newer Older
Paul's avatar
Paul committed
1
#include <migraphx/gpu/leaky_relu.hpp>
Paul's avatar
Paul committed
2
#include <migraphx/gpu/context.hpp>
Shucai Xiao's avatar
Shucai Xiao committed
3
#include <migraphx/gpu/miopen.hpp>
Khalique's avatar
Khalique committed
4

Paul's avatar
Paul committed
5
namespace migraphx {
Paul's avatar
Paul committed
6
inline namespace MIGRAPHX_INLINE_NS {
Khalique's avatar
Khalique committed
7
8
9
10
11
12
13
14
15
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,
16
17
                                    const shape& output_shape,
                                    const std::vector<argument>& args) const
Khalique's avatar
Khalique committed
18
{
Paul's avatar
Paul committed
19
    float alpha = 1;
Paul's avatar
Paul committed
20
    float beta  = 0;
Khalique's avatar
Khalique committed
21
22
    auto x_desc = make_tensor(args[0].get_shape());
    auto y_desc = make_tensor(output_shape);
Paul's avatar
Paul committed
23
    miopenActivationForward(ctx.get_stream().get_miopen(),
Khalique's avatar
Khalique committed
24
25
26
27
28
29
30
31
32
33
34
                            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
35
36
37
38
39
void miopen_leaky_relu::finalize(context&, const shape&, const std::vector<shape>&)
{
    ad = make_leaky_relu(op.alpha);
}

Khalique's avatar
Khalique committed
40
} // namespace gpu
Paul's avatar
Paul committed
41
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
42
} // namespace migraphx