auto_contiguous.cpp 582 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
7
#include <migraph/auto_contiguous.hpp>
#include <migraph/program.hpp>
#include <migraph/instruction.hpp>
#include <migraph/operators.hpp>
#include <migraph/iterator_for.hpp>

namespace migraph {
8
inline namespace version_1 {
Paul's avatar
Paul committed
9

Paul's avatar
Paul committed
10
void auto_contiguous::apply(program& p) const
Paul's avatar
Paul committed
11
12
13
{
    for(auto ins : iterator_for(p))
    {
Paul's avatar
Paul committed
14
        shape s = ins->get_shape();
Paul's avatar
Paul committed
15
        if(not s.standard())
Paul's avatar
Paul committed
16
        {
17
            auto c = p.insert_instruction(std::next(ins), op::contiguous{}, ins);
Paul's avatar
Paul committed
18
            p.replace_instruction(ins, c);
Paul's avatar
Paul committed
19
20
21
22
        }
    }
}

Shucai Xiao's avatar
Shucai Xiao committed
23
} // namespace version_1
Paul's avatar
Paul committed
24
} // namespace migraph