auto_contiguous.cpp 691 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
#include <migraphx/auto_contiguous.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
4
5
#include <migraphx/make_op.hpp>

Paul's avatar
Paul committed
6
#include <migraphx/iterator_for.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

11
void auto_contiguous::apply(module& p) const
Paul's avatar
Paul committed
12
13
14
{
    for(auto ins : iterator_for(p))
    {
15
16
        if (ins->name() == "layout")
            continue;
Paul's avatar
Paul committed
17
        shape s = ins->get_shape();
18
        if(not s.standard() and s.elements() != 0)
Paul's avatar
Paul committed
19
        {
20
            auto c = p.insert_instruction(std::next(ins), make_op("contiguous"), ins);
Paul's avatar
Paul committed
21
            p.replace_instruction(ins, c);
Paul's avatar
Paul committed
22
23
24
25
        }
    }
}

Paul's avatar
Paul committed
26
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
27
} // namespace migraphx