compile_scatternd.cpp 1.59 KB
Newer Older
turneram's avatar
turneram 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <migraphx/gpu/compile_scatternd.hpp>
#include <migraphx/gpu/compile_hip_code_object.hpp>
#include <migraphx/gpu/compile_hip.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/reduce_dims.hpp>
#include <migraphx/stringutils.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {

// NOLINTNEXTLINE
static const char* const scatternd_kernel = R"__migraphx__(
#include <migraphx/kernels/scatternd.hpp>
#include <migraphx/kernels/basic_ops.hpp>
#include <migraphx/kernels/integral_constant.hpp>
#include <migraphx/kernels/generic_constant.hpp>
#include <args.hpp>

namespace migraphx {

extern "C" {

__global__ void scatternd_kernel(void* in_indices, void* in_updates, void* output) 
{
    make_tensors()(in_indices, in_updates, output)([](auto&&... xs) { 
        scatternd(xs..., REDUCTION); 
    });
}

}

} // namespace migraphx

int main() {}

)__migraphx__";

operation
compile_scatternd(context&, const std::vector<shape>& io_shapes, const std::string& reduction)
{
    hip_compile_options options;
    auto out_s             = io_shapes.back();
    options.local          = 1024;
    options.global         = compute_global(io_shapes.at(1).elements(), options.local);
    options.inputs         = io_shapes;
    options.output         = out_s;
    options.kernel_name    = "scatternd_kernel";
    options.virtual_inputs = io_shapes;

    options.params += " -DREDUCTION=assign_" + reduction + "{}";

    return compile_hip_code_object(scatternd_kernel, options);
}

} // namespace gpu

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx