perf.cpp 2.01 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
#include "perf.hpp"

#include <migraphx/generate.hpp>
4
#include <migraphx/register_target.hpp>
Paul's avatar
Paul committed
5
6
7
8
9
10
11
12
#ifdef HAVE_GPU
#include <migraphx/gpu/hip.hpp>
#endif

namespace migraphx {
namespace driver {
inline namespace MIGRAPHX_INLINE_NS {

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

19
parameter_map fill_param_map(parameter_map& m, const program& p, const target& t, bool offload)
20
21
22
23
24
25
26
27
28
29
30
31
{
    for(auto&& x : p.get_parameter_shapes())
    {
        argument& arg = m[x.first];
        if(arg.empty())
            arg = generate_argument(x.second, get_hash(x.first));
        if(not offload)
            arg = t.copy_to(arg);
    }
    return m;
}

32
parameter_map fill_param_map(parameter_map& m, const program& p, bool gpu)
Paul's avatar
Paul committed
33
34
35
36
{
    for(auto&& x : p.get_parameter_shapes())
    {
        argument& arg = m[x.first];
Paul's avatar
Paul committed
37
        if(arg.empty())
38
            arg = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
39
40
41
42
43
44
45
46
47
48
#ifdef HAVE_GPU
        if(gpu)
            arg = gpu::to_gpu(arg);
#else
        (void)gpu;
#endif
    }
    return m;
}

49
parameter_map create_param_map(const program& p, const target& t, bool offload)
50
{
51
    parameter_map m;
52
53
54
55
56
57
58
59
60
61
62
    for(auto&& x : p.get_parameter_shapes())
    {
        auto arg = generate_argument(x.second, get_hash(x.first));
        if(offload)
            m[x.first] = arg;
        else
            m[x.first] = t.copy_to(arg);
    }
    return m;
}

63
parameter_map create_param_map(const program& p, bool gpu)
Paul's avatar
Paul committed
64
{
65
    parameter_map m;
Paul's avatar
Paul committed
66
67
68
69
    for(auto&& x : p.get_parameter_shapes())
    {
#ifdef HAVE_GPU
        if(gpu)
70
            m[x.first] = gpu::to_gpu(generate_argument(x.second, get_hash(x.first)));
Paul's avatar
Paul committed
71
        else
Paul's avatar
Paul committed
72
#else
Paul's avatar
Paul committed
73
        (void)gpu;
Paul's avatar
Paul committed
74
#endif
75
            m[x.first] = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
76
77
78
79
    }
    return m;
}

80
81
82
target get_target(bool gpu)
{
    if(gpu)
83
        return make_target("gpu");
84
    else
85
        return make_target("cpu");
86
87
}

88
void compile_program(program& p, bool gpu) { p.compile(get_target(gpu)); }
Paul's avatar
Paul committed
89

90
} // namespace  MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
91
92
} // namespace driver
} // namespace migraphx