perf.cpp 1.36 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);
}

Paul's avatar
Paul committed
19
20
21
22
23
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
24
        if(arg.empty())
25
            arg = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
26
27
28
29
30
31
32
33
34
35
#ifdef HAVE_GPU
        if(gpu)
            arg = gpu::to_gpu(arg);
#else
        (void)gpu;
#endif
    }
    return m;
}

Paul's avatar
Paul committed
36
37
38
39
40
41
42
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)
43
            m[x.first] = gpu::to_gpu(generate_argument(x.second, get_hash(x.first)));
Paul's avatar
Paul committed
44
        else
Paul's avatar
Paul committed
45
#else
Paul's avatar
Paul committed
46
        (void)gpu;
Paul's avatar
Paul committed
47
#endif
48
            m[x.first] = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
49
50
51
52
    }
    return m;
}

53
54
55
target get_target(bool gpu)
{
    if(gpu)
56
        return make_target("gpu");
57
    else
58
        return make_target("cpu");
59
60
}

61
void compile_program(program& p, bool gpu) { p.compile(get_target(gpu)); }
Paul's avatar
Paul committed
62
63
64
65

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