"src/targets/vscode:/vscode.git/clone" did not exist on "bd910b3940e4fd40be11fbed2936300f5342f569"
write_literals.cpp 1.15 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
4
#include <migraphx/gpu/write_literals.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/hip.hpp>
#include <migraphx/instruction.hpp>
5
#include <migraphx/program.hpp>
Paul's avatar
Paul committed
6
#include <migraphx/env.hpp>
Paul's avatar
Paul committed
7

Paul's avatar
Paul committed
8
namespace migraphx {
Paul's avatar
Paul committed
9
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
10
namespace gpu {
Paul's avatar
Paul committed
11

Paul's avatar
Paul committed
12
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_COPY_LITERALS)
13

14
void write_literals::apply(module& p) const
Paul's avatar
Paul committed
15
{
Paul's avatar
Paul committed
16
    assert(ctx != nullptr);
17
    std::size_t n = 0;
Paul's avatar
Paul committed
18
19
    for(auto ins : iterator_for(p))
    {
Paul's avatar
Paul committed
20
        if(ins->name() == "@literal")
Paul's avatar
Paul committed
21
        {
Paul's avatar
Paul committed
22
            if(enabled(MIGRAPHX_COPY_LITERALS{}))
23
            {
Paul's avatar
Paul committed
24
25
                literal l  = ins->get_literal();
                auto pre   = p.add_literal(l);
26
                auto alloc = p.insert_instruction(std::next(pre), hip_allocate{l.get_shape()});
27
                p.replace_instruction(ins, hip_copy_to_gpu{}, pre, alloc);
Paul's avatar
Paul committed
28
            }
29
30
            else
            {
31
                std::string id = "@literal:" + std::to_string(n);
32
                p.replace_instruction(ins, hip_copy_literal{ins->get_literal(), id});
33
                n++;
34
            }
Paul's avatar
Paul committed
35
36
37
        }
    }
}
38

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