topk.cpp 1.22 KB
Newer Older
Shucai Xiao's avatar
Shucai Xiao committed
1
2
3
4
5
6
7
8
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
#include <migraphx/gpu/topk.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/device/topk.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {

shape hip_topk::compute_shape(std::vector<shape> inputs) const
{
    return op.normalize_compute_shape({inputs.front()});
}

argument hip_topk::compute(context& ctx, const shape&, const std::vector<argument>& args) const
{
    auto outputs = args.back().get_sub_objects();
    return op.largest ? device::topk_largest(ctx.get_stream().get(),
                                             outputs.front(),
                                             outputs.back(),
                                             args[0],
                                             op.k,
                                             op.axis)
                      : device::topk_smallest(ctx.get_stream().get(),
                                              outputs.front(),
                                              outputs.back(),
                                              args[0],
                                              op.k,
                                              op.axis);
}

} // namespace gpu
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx