"src/targets/ref/lowering.cpp" did not exist on "613772dde3d97754e9bc6b78a88b772cf4524e8d"
perf.cpp 1.63 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "perf.hpp"

#include <migraphx/cpu/target.hpp>
#include <migraphx/generate.hpp>
#ifdef HAVE_GPU
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/hip.hpp>
#endif

namespace migraphx {
namespace driver {
inline namespace MIGRAPHX_INLINE_NS {

14
15
16
17
18
19
template <class T>
auto get_hash(const T& x)
{
    return std::hash<T>{}(x);
}

Paul's avatar
Paul committed
20
21
22
23
24
program::parameter_map fill_param_map(program::parameter_map& m, const program& p, bool gpu)
{
    for(auto&& x : p.get_parameter_shapes())
    {
        argument& arg = m[x.first];
Paul's avatar
Paul committed
25
        if(arg.empty())
26
            arg = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
27
28
29
30
31
32
33
34
35
36
#ifdef HAVE_GPU
        if(gpu)
            arg = gpu::to_gpu(arg);
#else
        (void)gpu;
#endif
    }
    return m;
}

Paul's avatar
Paul committed
37
38
39
40
41
42
43
program::parameter_map create_param_map(const program& p, bool gpu)
{
    program::parameter_map m;
    for(auto&& x : p.get_parameter_shapes())
    {
#ifdef HAVE_GPU
        if(gpu)
44
            m[x.first] = gpu::to_gpu(generate_argument(x.second, get_hash(x.first)));
Paul's avatar
Paul committed
45
        else
Paul's avatar
Paul committed
46
#else
Paul's avatar
Paul committed
47
        (void)gpu;
Paul's avatar
Paul committed
48
#endif
49
            m[x.first] = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
50
51
52
53
    }
    return m;
}

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
target get_target(bool gpu)
{
    if(gpu)
    {
#ifdef HAVE_GPU
        return gpu::target{};
#else
        MIGRAPHX_THROW("Gpu not supported.");
#endif
    }
    else
    {
        return cpu::target{};
    }
}

Paul's avatar
Paul committed
70
71
void compile_program(program& p, bool gpu)
{
Paul's avatar
Paul committed
72
    if(gpu)
Paul's avatar
Paul committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    {
#ifdef HAVE_GPU
        p.compile(gpu::target{});
#else
        MIGRAPHX_THROW("Gpu not supported.");
#endif
    }
    else
    {
        p.compile(cpu::target{});
    }
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace driver
} // namespace migraphx