adjust_allocation.cpp 1.2 KB
Newer Older
1
2
3
4
#include <migraphx/gpu/adjust_allocation.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/program.hpp>
#include <migraphx/iterator_for.hpp>
5
6
<<<<<<< HEAD
=======
Shucai Xiao's avatar
Shucai Xiao committed
7
#include <algorithm>
8
>>>>>>> adjust_gpu_allocation
9
10
11
12
13
14
15

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {

void adjust_allocation::apply(program& p) const
{
Shucai Xiao's avatar
Shucai Xiao committed
16
    std::vector<std::string> ins_names = {"gpu::fp_conversion"};
17
18
    for(auto ins : iterator_for(p))
    {
Shucai Xiao's avatar
Shucai Xiao committed
19
        // skip instructions not in the set
Shucai Xiao's avatar
Shucai Xiao committed
20
        if(std::find(ins_names.begin(), ins_names.end(), ins->name()) == ins_names.end())
Shucai Xiao's avatar
Shucai Xiao committed
21
22
23
24
        {
            continue;
        }

25
        auto alias_ins = instruction::get_output_alias(ins, true);
Shucai Xiao's avatar
Shucai Xiao committed
26
        if(alias_ins->name() == "hip::allocate")
27
28
29
        {
            // shape allocated is different from actual shape
            // of the instruction, reallocate and replace the previous one
Shucai Xiao's avatar
Shucai Xiao committed
30
            if(alias_ins->get_shape() != ins->get_shape())
31
32
33
34
35
36
37
38
39
40
41
            {
                auto alloc_ins = p.insert_instruction(ins, hip_allocate{ins->get_shape()});
                p.replace_instruction(alias_ins, alloc_ins);
            }
        }
    }
}

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