"scripts/vscode:/vscode.git/clone" did not exist on "b7fdde4bb499feff41dd03c429fb5f1ab7cd36e1"
perf.cpp 3.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
Paul's avatar
Paul committed
24
25
26
#include "perf.hpp"

#include <migraphx/generate.hpp>
27
#include <migraphx/register_target.hpp>
Paul's avatar
Paul committed
28
29
30
31
32
33
34
35
#ifdef HAVE_GPU
#include <migraphx/gpu/hip.hpp>
#endif

namespace migraphx {
namespace driver {
inline namespace MIGRAPHX_INLINE_NS {

36
37
38
39
40
41
template <class T>
auto get_hash(const T& x)
{
    return std::hash<T>{}(x);
}

42
parameter_map fill_param_map(parameter_map& m, const program& p, const target& t, bool offload)
43
44
45
46
47
48
49
50
51
52
53
54
{
    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;
}

55
parameter_map fill_param_map(parameter_map& m, const program& p, bool gpu)
Paul's avatar
Paul committed
56
57
58
59
{
    for(auto&& x : p.get_parameter_shapes())
    {
        argument& arg = m[x.first];
Paul's avatar
Paul committed
60
        if(arg.empty())
61
            arg = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
62
63
64
65
66
67
68
69
70
71
#ifdef HAVE_GPU
        if(gpu)
            arg = gpu::to_gpu(arg);
#else
        (void)gpu;
#endif
    }
    return m;
}

72
parameter_map create_param_map(const program& p, const target& t, bool offload)
73
{
74
    parameter_map m;
75
76
77
78
79
80
81
82
83
84
85
    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;
}

86
parameter_map create_param_map(const program& p, bool gpu)
Paul's avatar
Paul committed
87
{
88
    parameter_map m;
Paul's avatar
Paul committed
89
90
91
92
    for(auto&& x : p.get_parameter_shapes())
    {
#ifdef HAVE_GPU
        if(gpu)
93
            m[x.first] = gpu::to_gpu(generate_argument(x.second, get_hash(x.first)));
Paul's avatar
Paul committed
94
        else
Paul's avatar
Paul committed
95
#else
Paul's avatar
Paul committed
96
        (void)gpu;
Paul's avatar
Paul committed
97
#endif
98
            m[x.first] = generate_argument(x.second, get_hash(x.first));
Paul's avatar
Paul committed
99
100
101
102
    }
    return m;
}

103
104
105
target get_target(bool gpu)
{
    if(gpu)
106
        return make_target("gpu");
107
    else
108
        return make_target("cpu");
109
110
}

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

113
} // namespace  MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
114
115
} // namespace driver
} // namespace migraphx