sync_device.cpp 876 Bytes
Newer Older
1
2
3
#include <migraphx/gpu/sync_device.hpp>
#include <migraphx/program.hpp>
#include <migraphx/instruction.hpp>
4
#include <migraphx/make_op.hpp>
5
6
7
8
9
10
#include <migraphx/iterator_for.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {

11
void sync_device::apply(module& m) const
12
{
13
    auto last = std::prev(m.end());
14
15
16
17
18
19
20
    if(last->name() == "@return")
    {
        auto inputs = last->inputs();
        if(std::any_of(inputs.begin(), inputs.end(), [](auto i) {
               return (i->name() == "hip::copy_from_gpu");
           }))
        {
21
            auto sync_in = m.insert_instruction(last, make_op("hip::sync_stream"), inputs);
Shucai Xiao's avatar
Shucai Xiao committed
22
23
            if(not inputs.empty())
            {
24
                m.replace_instruction(inputs.front(), sync_in);
Shucai Xiao's avatar
Shucai Xiao committed
25
            }
26
27
28
29
30
31
32
        }
    }
}

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