add.cpp 1.6 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
#include <migraphx/gpu/add.hpp>
#include <migraphx/operators.hpp>
#include <migraphx/manage_ptr.hpp>
#include <migraphx/config.hpp>
#include <migraphx/gpu/miopen.hpp>
6
7
#include <utility>

Paul's avatar
Paul committed
8
namespace migraphx {
9
inline namespace MIGRAPH_INLINE_NS {
10
11
12
13
14
15
16
17
18
namespace gpu {

shape hip_add::compute_shape(const std::vector<shape>& inputs) const
{
    // check_shapes{inputs, *this}.has(3).standard();
    check_shapes{inputs, *this}.has(3);
    return inputs.at(0);
}

Paul's avatar
Paul committed
19
argument hip_add::compute(context& ctx, const shape&, const std::vector<argument>& args) const
20
{
Paul's avatar
Paul committed
21
    device::add(ctx.get_stream().get(), args[2], args[0], args[1]);
22
23
24
25
26
27
28
29
30
    return args[2];
}

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

wsttiger's avatar
wsttiger committed
31
32
33
argument miopen_add::compute(context& ctx,
                             const shape& output_shape,
                             const std::vector<argument>& args) const
34
35
36
37
38
{
    float alpha = 1, beta = 0;
    auto a_desc = make_tensor(args[0].get_shape());
    auto b_desc = make_tensor(args[1].get_shape());
    auto c_desc = make_tensor(output_shape);
Paul's avatar
Paul committed
39
    miopenOpTensor(ctx.get_stream().get_miopen(),
40
41
42
43
44
45
46
47
48
49
50
51
52
53
                   miopenTensorOpAdd,
                   &alpha,
                   a_desc.get(),
                   args[0].implicit(),
                   &alpha,
                   b_desc.get(),
                   args[1].implicit(),
                   &beta,
                   c_desc.get(),
                   args[2].implicit());
    return args[2];
}

} // namespace gpu
54
} // namespace MIGRAPH_INLINE_NS
Paul's avatar
Paul committed
55
} // namespace migraphx