softmax.cpp 1.46 KB
Newer Older
Paul's avatar
Paul committed
1
#include <migraphx/gpu/softmax.hpp>
Khalique's avatar
Khalique committed
2
#include <migraphx/gpu/device/softmax.hpp>
Khalique's avatar
Khalique committed
3
#include <migraphx/gpu/context.hpp>
4

Paul's avatar
Paul committed
5
namespace migraphx {
Paul's avatar
Paul committed
6
inline namespace MIGRAPHX_INLINE_NS {
7
8
namespace gpu {

Khalique's avatar
Khalique committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
shape miopen_softmax::compute_shape(const std::vector<shape>& inputs) const
{
    check_shapes{inputs, *this}.has(2).standard();
    return op.compute_shape({inputs.at(0)});
}

argument miopen_softmax::compute(context& ctx,
                                 const shape& output_shape,
                                 const std::vector<argument>& args) const
{
    float alpha = 1;
    float beta  = 0;
    auto x_desc = make_tensor(args[0].get_shape());
    auto y_desc = make_tensor(output_shape);
    miopenSoftmaxForward(ctx.get_stream().get_miopen(),
                         &alpha,
                         x_desc.get(),
                         args[0].implicit(),
                         &beta,
                         y_desc.get(),
                         args[1].implicit());

    return args[1];
}

Khalique's avatar
Khalique committed
34
shape hip_softmax::compute_shape(const std::vector<shape>& inputs) const
35
36
37
38
39
{
    check_shapes{inputs, *this}.has(2).standard();
    return op.compute_shape({inputs.at(0)});
}

Khalique's avatar
Khalique committed
40
argument hip_softmax::compute(context& ctx,
Paul's avatar
Paul committed
41
                              const shape&,
Khalique's avatar
Khalique committed
42
                              const std::vector<argument>& args) const
43
{
Paul's avatar
Paul committed
44
    return device::softmax(ctx.get_stream().get(), args[1], args[0], op.axis);
45
46
47
}

} // namespace gpu
Paul's avatar
Paul committed
48
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
49
} // namespace migraphx