"src/targets/cpu/lowering.cpp" did not exist on "e01c70e659950b69dd093faf204a37077fc441d5"
target.cpp 6.78 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.
 */
24
#include <migraphx/adjust_allocation.hpp>
Paul's avatar
Paul committed
25
#include <migraphx/auto_contiguous.hpp>
26
#include <migraphx/check_context.hpp>
Paul's avatar
Paul committed
27
#include <migraphx/dead_code_elimination.hpp>
28
#include <migraphx/eliminate_allocation.hpp>
Paul's avatar
Paul committed
29
#include <migraphx/eliminate_concat.hpp>
30
#include <migraphx/eliminate_contiguous.hpp>
31
#include <migraphx/eliminate_data_type.hpp>
32
#include <migraphx/eliminate_identity.hpp>
33
#include <migraphx/eliminate_pad.hpp>
34
#include <migraphx/fuse_pointwise.hpp>
Shucai Xiao's avatar
Shucai Xiao committed
35
#include <migraphx/inline_module.hpp>
kahmed10's avatar
kahmed10 committed
36
#include <migraphx/insert_pad.hpp>
37
#include <migraphx/layout_nhwc.hpp>
38
#include <migraphx/memory_coloring.hpp>
Shucai Xiao's avatar
Shucai Xiao committed
39
#include <migraphx/normalize_ops.hpp>
40
#include <migraphx/optimize_module.hpp>
41
#include <migraphx/preallocate_param.hpp>
Charlie Lin's avatar
Charlie Lin committed
42
#include <migraphx/promote_literals.hpp>
43
#include <migraphx/register_target.hpp>
44
#include <migraphx/replace_allocate.hpp>
45
#include <migraphx/rewrite_gelu.hpp>
46
#include <migraphx/rewrite_pooling.hpp>
turneram's avatar
turneram committed
47
#include <migraphx/rewrite_quantization.hpp>
48
#include <migraphx/rewrite_rnn.hpp>
Paul's avatar
Paul committed
49
#include <migraphx/schedule.hpp>
turneram's avatar
turneram committed
50
#include <migraphx/simplify_qdq.hpp>
51
#include <migraphx/simplify_reshapes.hpp>
52
#include <migraphx/split_single_dyn_dim.hpp>
53
#include <migraphx/gpu/allocation_model.hpp>
54
#include <migraphx/gpu/compile_miopen.hpp>
55
#include <migraphx/gpu/compile_ops.hpp>
56
57
#include <migraphx/gpu/concat_gpu_opt.hpp>
#include <migraphx/gpu/context.hpp>
58
#include <migraphx/gpu/device_name.hpp>
Paul Fultz II's avatar
Paul Fultz II committed
59
#include <migraphx/gpu/fuse_mlir.hpp>
60
#include <migraphx/gpu/fuse_ops.hpp>
61
#include <migraphx/gpu/prefuse_ops.hpp>
62
63
64
65
66
67
#include <migraphx/gpu/lowering.hpp>
#include <migraphx/gpu/pack_int8_args.hpp>
#include <migraphx/gpu/schedule_model.hpp>
#include <migraphx/gpu/sync_device.hpp>
#include <migraphx/gpu/target.hpp>
#include <migraphx/gpu/write_literals.hpp>
Paul's avatar
Paul committed
68

Paul's avatar
Paul committed
69
namespace migraphx {
Paul's avatar
Paul committed
70
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
71
namespace gpu {
mei-ye's avatar
mei-ye committed
72

73
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_DISABLE_SCHEDULE_PASS)
74
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_DISABLE_POINTWISE_FUSION)
75
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_ENABLE_NHWC)
76
77
78
79
80
81
82
83
84
85
86
87
struct id_pass
{
    std::string name() const { return "id"; }
    void apple(const module&) const {}
};

pass enable_pass(bool enabled, pass p)
{
    if(enabled)
        return p;
    return id_pass{};
}
Paul's avatar
Paul committed
88

89
std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_options& options) const
Paul's avatar
Paul committed
90
{
Paul's avatar
Paul committed
91
    auto& ctx = any_cast<context>(gctx);
92
    ctx.set_exhaustive_tune_flag(options.exhaustive_tune);
93
94
95
96
97
98
    std::set<shape::type_t> unsupported_types(shape::types().begin(), shape::types().end());
    unsupported_types.erase(shape::type_t::float_type);
    unsupported_types.erase(shape::type_t::half_type);
    unsupported_types.erase(shape::type_t::bool_type);
    unsupported_types.erase(shape::type_t::int8_type);
    unsupported_types.erase(shape::type_t::uint8_type);
Shucai Xiao's avatar
Shucai Xiao committed
99
    unsupported_types.erase(shape::type_t::tuple_type);
Paul's avatar
Paul committed
100
101
102
    // clang-format off
    return
    {
103
104
        enable_pass(options.split_single_dyn_dim, split_single_dyn_dim{}),
        enable_pass(options.split_single_dyn_dim, dead_code_elimination{}),
Shucai Xiao's avatar
Shucai Xiao committed
105
        normalize_ops{},
106
        dead_code_elimination{},
turneram's avatar
turneram committed
107
        simplify_qdq{},
turneram's avatar
turneram committed
108
109
        rewrite_quantization{},
        dead_code_elimination{},
110
        eliminate_data_type{unsupported_types, shape::type_t::float_type},
111
        simplify_reshapes{},
112
        eliminate_identity{},
113
        eliminate_pad{},
114
        dead_code_elimination{},
kahmed10's avatar
kahmed10 committed
115
116
        insert_pad{},
        dead_code_elimination{},
Shucai Xiao's avatar
Shucai Xiao committed
117
        rewrite_rnn{},
Shucai Xiao's avatar
Shucai Xiao committed
118
        dead_code_elimination{},
Shucai Xiao's avatar
Shucai Xiao committed
119
        inline_module{},
120
        rewrite_pooling{},
Shucai Xiao's avatar
Shucai Xiao committed
121
        dead_code_elimination{},
122
        rewrite_gelu{},
123
        optimize_module{},
124
125
        enable_pass(enabled(MIGRAPHX_ENABLE_NHWC{}), layout_nhwc{}),
        dead_code_elimination{},
126
127
        prefuse_ops{},
        dead_code_elimination{},
Paul's avatar
Paul committed
128
        auto_contiguous{},
129
        optimize_module{},
130
        enable_pass(not enabled(MIGRAPHX_DISABLE_POINTWISE_FUSION{}), fuse_pointwise{}),
131
        dead_code_elimination{},
Paul Fultz II's avatar
Paul Fultz II committed
132
133
        fuse_mlir{&ctx},
        dead_code_elimination{},
134
        lowering{&ctx, options.offload_copy},
135
        eliminate_contiguous{"gpu::contiguous"},
Paul's avatar
Paul committed
136
        dead_code_elimination{},
137
138
        eliminate_concat{concat_gpu_optimization{}},
        dead_code_elimination{},
139
140
        compile_miopen{&gctx},
        dead_code_elimination{},
141
142
        pack_int8_args{},
        dead_code_elimination{},
kahmed10's avatar
kahmed10 committed
143
        fuse_ops{&ctx, options.fast_math},
Paul's avatar
Paul committed
144
        dead_code_elimination{},
145
146
        replace_allocate{gpu_allocation_model{}, options.offload_copy},
        dead_code_elimination{},
147
148
        adjust_allocation{gpu_allocation_model{}},
        dead_code_elimination{},
149
150
        compile_ops{&ctx},
        dead_code_elimination{},
Charlie Lin's avatar
Charlie Lin committed
151
152
        promote_literals{},
        dead_code_elimination{},
Paul's avatar
Paul committed
153
        write_literals{&ctx},
154
        schedule{gpu::schedule_model{ctx.get_current_device().nstreams()}, not enabled(MIGRAPHX_DISABLE_SCHEDULE_PASS{})},
Paul's avatar
Paul committed
155
        memory_coloring{"hip::allocate"},
156
        sync_device{},
157
        preallocate_param{"scratch", gpu_allocation_model{}},
Paul's avatar
Paul committed
158
        dead_code_elimination{},
Paul's avatar
Paul committed
159
        eliminate_allocation{"hip::allocate"},
160
        check_context<context>{},
161
        normalize_ops{},
162
163
        dead_code_elimination{},
        eliminate_identity{}
Paul's avatar
Paul committed
164
165
    };
    // clang-format on
Paul's avatar
Paul committed
166
}
Paul's avatar
Paul committed
167

168
std::string target::name() const { return "gpu"; }
Paul's avatar
Paul committed
169

170
migraphx::context target::get_context() const { return context(gpu::get_device_id()); }
171

Shucai Xiao's avatar
Shucai Xiao committed
172
argument target::copy_to(const argument& arg) const { return gpu::to_gpu(arg); }
173

Shucai Xiao's avatar
Shucai Xiao committed
174
argument target::copy_from(const argument& arg) const { return gpu::from_gpu(arg); }
175

Shucai Xiao's avatar
Shucai Xiao committed
176
argument target::allocate(const shape& s) const { return gpu::allocate_gpu(s); }
177

178
179
MIGRAPHX_REGISTER_TARGET(target);

Paul's avatar
Paul committed
180
} // namespace gpu
Paul's avatar
Paul committed
181
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
182
} // namespace migraphx