target.cpp 4.25 KB
Newer Older
1
#include <migraphx/adjust_allocation.hpp>
Paul's avatar
Paul committed
2
#include <migraphx/auto_contiguous.hpp>
3
#include <migraphx/check_context.hpp>
Paul's avatar
Paul committed
4
#include <migraphx/dead_code_elimination.hpp>
5
6
#include <migraphx/decompose.hpp>
#include <migraphx/eliminate_allocation.hpp>
Paul's avatar
Paul committed
7
#include <migraphx/eliminate_common_subexpression.hpp>
Paul's avatar
Paul committed
8
#include <migraphx/eliminate_concat.hpp>
9
#include <migraphx/eliminate_contiguous.hpp>
10
#include <migraphx/eliminate_data_type.hpp>
11
#include <migraphx/eliminate_identity.hpp>
12
#include <migraphx/eliminate_pad.hpp>
13
#include <migraphx/memory_coloring.hpp>
Shucai Xiao's avatar
Shucai Xiao committed
14
#include <migraphx/normalize_ops.hpp>
15
16
#include <migraphx/propagate_constant.hpp>
#include <migraphx/register_target.hpp>
17
#include <migraphx/remap.hpp>
18
19
20
#include <migraphx/rewrite_batchnorm.hpp>
#include <migraphx/rewrite_pooling.hpp>
#include <migraphx/rewrite_rnn.hpp>
Paul's avatar
Paul committed
21
#include <migraphx/schedule.hpp>
22
23
#include <migraphx/simplify_algebra.hpp>
#include <migraphx/simplify_reshapes.hpp>
24
#include <migraphx/gpu/allocation_model.hpp>
25
26
27
28
29
#include <migraphx/gpu/concat_gpu_opt.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/eliminate_workspace.hpp>
#include <migraphx/gpu/fuse_ops.hpp>
#include <migraphx/gpu/lowering.hpp>
30
#include <migraphx/gpu/mlir_conv.hpp>
31
32
33
34
35
36
#include <migraphx/gpu/pack_int8_args.hpp>
#include <migraphx/gpu/preallocate_param.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
37

Paul's avatar
Paul committed
38
namespace migraphx {
Paul's avatar
Paul committed
39
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
40
namespace gpu {
mei-ye's avatar
mei-ye committed
41

42
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_DISABLE_SCHEDULE_PASS)
Paul's avatar
Paul committed
43

44
std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_options& options) const
Paul's avatar
Paul committed
45
{
Paul's avatar
Paul committed
46
    auto& ctx = any_cast<context>(gctx);
47
48
49
50
51
52
    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);
Paul's avatar
Paul committed
53
54
55
    // clang-format off
    return
    {
Shucai Xiao's avatar
Shucai Xiao committed
56
        normalize_ops{},
57
        decompose{},
58
        dead_code_elimination{},
59
        eliminate_data_type{unsupported_types, shape::type_t::float_type},
60
        simplify_reshapes{},
61
        eliminate_identity{},
62
        eliminate_pad{},
63
        dead_code_elimination{},
Paul's avatar
Paul committed
64
        rewrite_batchnorm{},
Paul's avatar
Paul committed
65
        dead_code_elimination{},
Shucai Xiao's avatar
Shucai Xiao committed
66
        rewrite_rnn{},
Shucai Xiao's avatar
Shucai Xiao committed
67
        dead_code_elimination{},
68
        rewrite_pooling{},
Shucai Xiao's avatar
Shucai Xiao committed
69
        dead_code_elimination{},
Paul's avatar
Paul committed
70
71
        eliminate_common_subexpression{},
        dead_code_elimination{},
Paul's avatar
Paul committed
72
        simplify_algebra{},
73
74
        simplify_reshapes{},
        simplify_algebra{},
Paul's avatar
Paul committed
75
        auto_contiguous{},
76
        simplify_reshapes{},
77
78
        propagate_constant{},
        dead_code_elimination{},
79
        mlir_conv{&ctx},
80
        lowering{&ctx, options.offload_copy},
81
        eliminate_contiguous{"gpu::contiguous"},
Paul's avatar
Paul committed
82
        dead_code_elimination{},
83
84
        eliminate_concat{concat_gpu_optimization{}},
        dead_code_elimination{},
85
        adjust_allocation{gpu_allocation_model{}},
86
        dead_code_elimination{},
87
88
        pack_int8_args{},
        dead_code_elimination{},
kahmed10's avatar
kahmed10 committed
89
        fuse_ops{&ctx, options.fast_math},
Paul's avatar
Paul committed
90
        dead_code_elimination{},
Paul's avatar
Paul committed
91
        write_literals{&ctx},
92
        schedule{gpu::schedule_model{ctx.get_current_device().nstreams()}, not enabled(MIGRAPHX_DISABLE_SCHEDULE_PASS{})},
Paul's avatar
Paul committed
93
        memory_coloring{"hip::allocate"},
94
        sync_device{},
95
        preallocate_param{"scratch", &ctx},
Paul's avatar
Paul committed
96
        dead_code_elimination{},
Paul's avatar
Paul committed
97
98
        eliminate_workspace{},
        eliminate_allocation{"hip::allocate"},
99
        check_context<context>{},
100
        normalize_ops{},
101
102
        dead_code_elimination{},
        eliminate_identity{}
Paul's avatar
Paul committed
103
104
    };
    // clang-format on
Paul's avatar
Paul committed
105
}
Paul's avatar
Paul committed
106

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

Paul's avatar
Paul committed
109
migraphx::context target::get_context() const { return context{}; }
110

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

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

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

117
118
MIGRAPHX_REGISTER_TARGET(target);

Paul's avatar
Paul committed
119
} // namespace gpu
Paul's avatar
Paul committed
120
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
121
} // namespace migraphx