gemm_xdl_fp16.cpp 8.28 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
// SPDX-License-Identifier: MIT
Illia Silin's avatar
Illia Silin committed
2
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
Chao Liu's avatar
Chao Liu committed
3

4
#include "common.hpp"
Chao Liu's avatar
Chao Liu committed
5

6
7
#include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl.hpp"
#include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl_cshuffle.hpp"
8
9
#include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl_waveletmodel_cshuffle.hpp"

Chao Liu's avatar
Chao Liu committed
10

11
12
13
using ADataType        = ck::half_t;
using BDataType        = ck::half_t;
using AccDataType      = float;
14
using CShuffleDataType = ck::half_t;
15
using CDataType        = ck::half_t;
Chao Liu's avatar
Chao Liu committed
16

17
using F16 = ck::half_t;
18
using F32 = float;
19

20
using ALayout = Row;
21
using BLayout = Row;
22
using CLayout = Row;
Chao Liu's avatar
Chao Liu committed
23

24
25
26
using AElementOp = PassThrough;
using BElementOp = PassThrough;
using CElementOp = PassThrough;
Chao Liu's avatar
Chao Liu committed
27

28
static constexpr auto GemmDefault = ck::tensor_operation::device::GemmSpecialization::Default;
Chao Liu's avatar
Chao Liu committed
29

30
// clang-format off
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using DeviceGemmFactory = 
    std::tuple<
#if 0
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 256, 
        32, 8, 8,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 8, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 256, 
        32, 8, 2,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 2, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Col,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 256, 
        32, 8, 8,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>,  
        2, 8, 8, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Col,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        2,   256,
        256, 256, 
        32, 8, 8,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>,  
        2, 8, 8, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 256, 
        32, 8, 8,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 8, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v2>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 256, 
        32, 8, 2,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 2, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v2>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Col,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 256, 
        32, 8, 8,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>,  
        2, 8, 8, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v2>,
#endif
#if 0
    // interwave best:
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 128, 
        32, 8, 2,
        32,   32,
        4,    2, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<8, 32, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 2, 0,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Interwave, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 128, 
        32, 8, 2,
        32,   32,
        4,    2, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<8, 32, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 2, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Interwave, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 128, 
        32, 8, 4,
        32,   32,
        4,    2, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<8, 32, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 4, 0,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Interwave, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 128, 
        32, 8, 4,
        32,   32,
        4,    2, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<8, 32, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 4, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Interwave, ck::PipelineVersion::v1>,
        
    ck::tensor_operation::device::DeviceGemm_Xdl_WaveletModel_CShuffle<
        ALayout, BLayout, CLayout, 
        ADataType, BDataType, AccDataType,              F16, CDataType,  
        AElementOp,  BElementOp,  CElementOp,    GemmDefault,        
        1, 256,  256,   256,   128,    
        32, 8, 2,
        32,   32,
        4,    2, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<8, 32, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 2, 0,
        1, 1, S<1, 32, 1, 8>, 8>,
#endif
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        2,   256,
        256, 256, 
        32, 8, 4,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 4, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v1>,
    ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle<
        Row,   Row,  Row,   
        F16,   F16,  F16,  F32,  F16, 
        PassThrough, PassThrough, PassThrough, GemmDefault, 
        1,   256,
        256, 256, 
        32, 8, 4,
        32,   32,
        4,    4, 
        S<4, 64, 1>,  S<1, 0, 2>,  S<1, 0, 2>, 
        2, 8, 8, 1,
        S<4, 64, 1>,  S<0, 2, 1>,  S<0, 2, 1>, 
        1, 4, 4, 1,
        1, 1, S<1, 32, 1, 8>, 8,
        ck::LoopScheduler::Default, ck::PipelineVersion::v1>
    >;

Po Yen Chen's avatar
Po Yen Chen committed
249

Chao Liu's avatar
Chao Liu committed
250
251
// clang-format on

252
// using DeviceGemmInstance = DeviceGemmFactory;
Po Yen Chen's avatar
Po Yen Chen committed
253

Chao Liu's avatar
Chao Liu committed
254
using ReferenceGemmInstance = ck::tensor_operation::host::
255
    ReferenceGemm<ADataType, BDataType, CDataType, AccDataType, AElementOp, BElementOp, CElementOp>;
256

257
#include "run_gemm_example.inc"
Jianfeng Yan's avatar
Jianfeng Yan committed
258

259
int main(int argc, char* argv[]) { return !run_gemm_example(argc, argv); }