1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the LICENSE file.
*
*/
#pragma once
//
// TODO:
//
// Add Key-Val sorting support -- easy.
//
#include <stdio.h>
#include <stdint.h>
//
// All code generation is driven by the specified architectural
// details and host platform API.
//
// In general, the warps-per-block and keys-per-thread are the
// critical knobs for tuning performance.
//
struct hsg_config
{
struct {
struct {
uint32_t lo;
uint32_t hi;
} flip;
struct {
uint32_t lo;
uint32_t hi;
} half;
uint32_t max_log2;
} merge;
struct {
uint32_t warps_min;
uint32_t warps_max;
uint32_t warps_mod;
uint32_t smem_min;
uint32_t smem_quantum;
uint32_t smem_bs;
uint32_t smem_bc;
} block;
struct {
uint32_t lanes;
uint32_t lanes_log2;
uint32_t skpw_bs;
} warp;
struct {
uint32_t regs;
uint32_t xtra;
} thread;
struct {
uint32_t words;
} type;
};
//
// HotSort can merge non-power-of-two blocks of warps
//
struct hsg_level
{
uint32_t count; // networks >= 2
uint32_t diffs [2];
uint32_t diff_masks [2];
uint32_t evenodds [2];
uint32_t evenodd_masks[2];
uint32_t networks [2];
union {
uint64_t b64;
uint32_t b32a2[2];
} active;
};
//
//
//
#define MERGE_LEVELS_MAX_LOG2 7 // merge up to 128 warps
#define MERGE_LEVELS_MAX_SIZE (1 << MERGE_LEVELS_MAX_LOG2)
//
// This is computed
//
struct hsg_merge
{
uint32_t offsets [MERGE_LEVELS_MAX_SIZE];
uint32_t networks[MERGE_LEVELS_MAX_SIZE];
struct hsg_level levels[MERGE_LEVELS_MAX_LOG2];
uint32_t index;
uint32_t warps;
uint32_t rows_bs;
uint32_t rows_bc;
uint32_t skpw_bc;
};
//
//
//
#if 0
#define HSG_FILE_NAME_SIZE 80
struct hsg_file
{
FILE * file;
char const * prefix;
char name[HSG_FILE_NAME_SIZE];
};
//
//
//
typedef enum hsg_file_type {
HSG_FILE_TYPE_HEADER,
HSG_FILE_TYPE_SOURCE,
HSG_FILE_TYPE_COUNT
} hsg_file_type;
#endif
//
//
//
#define HSG_OP_EXPAND_ALL() \
HSG_OP_EXPAND_X(HSG_OP_TYPE_EXIT) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_END) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_BEGIN) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_ELSE) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_TARGET_BEGIN) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_TARGET_END) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_TRANSPOSE_KERNEL_PROTO) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_TRANSPOSE_KERNEL_PREAMBLE) \
HSG_OP_EXPAND_X(HSG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E_CMP_XCHG) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_REG_SHARED_STORE_V) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_REG_SHARED_LOAD_V) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_BC_REG_SHARED_LOAD_V) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BX_REG_SHARED_STORE_LEFT) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_REG_SHARED_STORE_RIGHT) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_REG_SHARED_LOAD_LEFT) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_REG_SHARED_LOAD_RIGHT) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BC_REG_GLOBAL_LOAD_LEFT) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BLOCK_SYNC) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_FRAC_PRED) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_MERGE_H_PREAMBLE) \
HSG_OP_EXPAND_X(HSG_OP_TYPE_BC_MERGE_H_PREAMBLE) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BX_MERGE_H_PRED) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_BS_ACTIVE_PRED) \
\
HSG_OP_EXPAND_X(HSG_OP_TYPE_COUNT)
//
//
//
#undef HSG_OP_EXPAND_X
#define HSG_OP_EXPAND_X(t) t ,
typedef enum hsg_op_type {
HSG_OP_EXPAND_ALL()
} hsg_op_type;
//
//
//
struct hsg_op
{
hsg_op_type type;
union {
struct {
int32_t a;
int32_t b;
int32_t c;
};
struct {
int32_t n;
int32_t v;
};
struct {
int32_t m;
int32_t w;
};
};
};
//
//
//
extern char const * const hsg_op_type_string[];
//
//
//
struct hsg_target
{
struct hsg_target_state * state;
};
//
// All targets share this prototype
//
typedef
void
(*hsg_target_pfn)(struct hsg_target * const target,
struct hsg_config const * const config,
struct hsg_merge const * const merge,
struct hsg_op const * const ops,
uint32_t const depth);
//
//
//
extern
void
hsg_target_debug(struct hsg_target * const target,
struct hsg_config const * const config,
struct hsg_merge const * const merge,
struct hsg_op const * const ops,
uint32_t const depth);
extern
void
hsg_target_cuda(struct hsg_target * const target,
struct hsg_config const * const config,
struct hsg_merge const * const merge,
struct hsg_op const * const ops,
uint32_t const depth);
extern
void
hsg_target_opencl(struct hsg_target * const target,
struct hsg_config const * const config,
struct hsg_merge const * const merge,
struct hsg_op const * const ops,
uint32_t const depth);
extern
void
hsg_target_glsl(struct hsg_target * const target,
struct hsg_config const * const config,
struct hsg_merge const * const merge,
struct hsg_op const * const ops,
uint32_t const depth);
//
//
//
|