copy_sm90.h 19 KB
Newer Older
1
2
#pragma once

3
#ifndef __CUDACC_RTC__
4
#include <cuda.h>
5
#endif
6
7
8
9

#include "common.h"

namespace tl {
10
11
12
13
14
enum class CacheHintSm90 : uint64_t {
  EVICT_NORMAL = 0x1000000000000000,
  EVICT_FIRST = 0x12F0000000000000,
  EVICT_LAST = 0x14F0000000000000,
};
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
TL_DEVICE void tma_load(void *smem_ptr, void *gmem_ptr, uint64_t &smem_mbar,
                        uint32_t size) {
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
  asm volatile("cp.async.bulk.shared::cluster.global.mbarrier::complete_tx::"
               "bytes [%0], [%1], %2, [%3]; \n" ::"r"(smem_int_ptr),
               "l"(gmem_ptr), "r"(size), "r"(smem_int_mbar)
               :);
}

TL_DEVICE void tma_load_multicast(void *smem_ptr, void *gmem_ptr,
                                  uint64_t &smem_mbar, uint32_t size,
                                  uint16_t mask) {
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
  asm volatile(
      "cp.async.bulk.shared::cluster.global.mbarrier::complete_tx::bytes."
      "multicast::cluster [%0], [%1], %2, [%3], %4; \n" ::"r"(smem_int_ptr),
      "l"(gmem_ptr), "r"(size), "r"(smem_int_mbar), "h"(mask)
      :);
}

38
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
39
40
TL_DEVICE void tma_load(const CUtensorMap &descriptor, uint64_t &smem_mbar,
                        void const *const smem_ptr, int32_t const &crd0) {
41
42
43
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.1d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes"
                 " [%0], [%1, {%3}], [%2];"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.1d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes.L2::cache_hint"
                 " [%0], [%1, {%3}], [%2], %4;"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "l"(cache_hint)
                 : "memory");
  }
61
62
}

63
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
64
65
66
TL_DEVICE void tma_load(const CUtensorMap &descriptor, uint64_t &smem_mbar,
                        void const *const smem_ptr, int32_t const &crd0,
                        int32_t const &crd1) {
67
68
69
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.2d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes"
                 " [%0], [%1, {%3, %4}], [%2];"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.2d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes.L2::cache_hint"
                 " [%0], [%1, {%3, %4}], [%2], %5;"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1), "l"(cache_hint)
                 : "memory");
  }
87
88
}

89
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
90
91
92
TL_DEVICE void tma_load(const CUtensorMap &descriptor, uint64_t &smem_mbar,
                        void const *const smem_ptr, int32_t const &crd0,
                        int32_t const &crd1, int32_t const &crd2) {
93
94
95
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.3d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes"
                 " [%0], [%1, {%3, %4, %5}], [%2];"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1), "r"(crd2)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.3d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes.L2::cache_hint"
                 " [%0], [%1, {%3, %4, %5}], [%2], %6;"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1), "r"(crd2), "l"(cache_hint)
                 : "memory");
  }
113
}
114
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
115
116
117
118
TL_DEVICE void tma_load(const CUtensorMap &descriptor, uint64_t &smem_mbar,
                        void const *const smem_ptr, int32_t const &crd0,
                        int32_t const &crd1, int32_t const &crd2,
                        int32_t const &crd3) {
119
120
121
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.4d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes"
                 " [%0], [%1, {%3, %4, %5, %6}], [%2];"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.4d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes.L2::cache_hint"
                 " [%0], [%1, {%3, %4, %5, %6}], [%2], %7;"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "l"(cache_hint)
                 : "memory");
  }
139
140
}

141
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
142
143
144
145
TL_DEVICE void tma_load(const CUtensorMap &descriptor, uint64_t &smem_mbar,
                        void const *const smem_ptr, int32_t const &crd0,
                        int32_t const &crd1, int32_t const &crd2,
                        int32_t const &crd3, int32_t const &crd4) {
146
147
148
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.5d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes"
                 " [%0], [%1, {%3, %4, %5, %6, %7}], [%2];"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.5d.shared::cluster.global.mbarrier::"
                 "complete_tx::bytes.L2::cache_hint"
                 " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], %8;"
                 :
                 : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
                   "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4),
                   "l"(cache_hint)
                 : "memory");
  }
167
168
}

169
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
170
171
172
173
174
175
TL_DEVICE void tma_load_im2col(const CUtensorMap &descriptor,
                               uint64_t &smem_mbar, void const *const smem_ptr,
                               int32_t const &coord_c, int32_t const &coord_w,
                               int32_t const &coord_h, int32_t const &coord_n,
                               uint16_t const &offset_w,
                               uint16_t const &offset_h) {
176
177
178
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_mbar = smem_ptr_to_uint(&smem_mbar);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile(
        "cp.async.bulk.tensor.4d.shared::cluster.global.im2col.mbarrier:"
        ":complete_tx::bytes"
        " [%0], [%1, {%3, %4, %5, %6}], [%2], {%7, %8};"
        :
        : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
          "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n), "h"(offset_w),
          "h"(offset_h)
        : "memory");
  } else {
    asm volatile(
        "cp.async.bulk.tensor.4d.shared::cluster.global.im2col.mbarrier:"
        ":complete_tx::bytes.L2::cache_hint"
        " [%0], [%1, {%3, %4, %5, %6}], [%2], {%7, %8}, %9;"
        :
        : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar),
          "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n), "h"(offset_w),
          "h"(offset_h), "l"(cache_hint)
        : "memory");
  }
200
201
}

202
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
203
204
TL_DEVICE void tma_store(const CUtensorMap &descriptor,
                         void const *const smem_ptr, int32_t const &crd0) {
205
206
207
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);

208
209
210
211
212
213
214
215
216
217
218
219
220
221
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.1d.global.shared::cta.bulk_group [%0, "
                 "{%2}], [%1];"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.1d.global.shared::cta.bulk_group "
                 "::cache_hint [%0, {%2}], [%1], %3;"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0),
                   "l"(cache_hint)
                 : "memory");
  }
222
223
}

224
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
225
226
227
TL_DEVICE void tma_store(const CUtensorMap &descriptor,
                         void const *const smem_ptr, int32_t const &crd0,
                         int32_t const &crd1) {
228
229
230
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);

231
232
233
234
235
236
237
238
239
240
241
242
243
244
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.2d.global.shared::cta.bulk_group [%0, "
                 "{%2, %3}], [%1];"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.2d.global.shared::cta.bulk_group "
                 "::cache_hint [%0, {%2, %3}], [%1], %4;"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1),
                   "l"(cache_hint)
                 : "memory");
  }
245
246
}

247
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
248
249
250
TL_DEVICE void tma_store(const CUtensorMap &descriptor,
                         void const *const smem_ptr, int32_t const &crd0,
                         int32_t const &crd1, int32_t const &crd2) {
251
252
253
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.3d.global.shared::cta.bulk_group [%0, "
                 "{%2, %3, %4}], [%1];"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1),
                   "r"(crd2)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.3d.global.shared::cta.bulk_group "
                 "::cache_hint [%0, {%2, %3, %4}], [%1], %5;"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1),
                   "r"(crd2), "l"(cache_hint)
                 : "memory");
  }
269
270
}

271
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
272
273
274
275
TL_DEVICE void tma_store(const CUtensorMap &descriptor,
                         void const *const smem_ptr, int32_t const &crd0,
                         int32_t const &crd1, int32_t const &crd2,
                         int32_t const &crd3) {
276
277
278
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.4d.global.shared::cta.bulk_group [%0, "
                 "{%2, %3, %4, %5}], [%1];"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1),
                   "r"(crd2), "r"(crd3)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.4d.global.shared::cta.bulk_group "
                 "::cache_hint [%0, {%2, %3, %4, %5}], [%1], %6;"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1),
                   "r"(crd2), "r"(crd3), "l"(cache_hint)
                 : "memory");
  }
294
295
}

296
template <CacheHintSm90 cache_hint = CacheHintSm90::EVICT_NORMAL>
297
298
299
300
TL_DEVICE void tma_store(const CUtensorMap &descriptor,
                         void const *const smem_ptr, int32_t const &crd0,
                         int32_t const &crd1, int32_t const &crd2,
                         int32_t const &crd3, int32_t const &crd4) {
301
302
303
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  uint32_t smem_int_ptr = smem_ptr_to_uint(smem_ptr);

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  if constexpr (cache_hint == CacheHintSm90::EVICT_NORMAL) {
    asm volatile("cp.async.bulk.tensor.5d.global.shared::cta.bulk_group [%0, "
                 "{%2, %3, %4, %5, %6}], [%1];"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1),
                   "r"(crd2), "r"(crd3), "r"(crd4)
                 : "memory");
  } else {
    asm volatile("cp.async.bulk.tensor.5d.global.shared::cta.bulk_group "
                 "::cache_hint [%0, {%2, %3, %4, %5, %6}], [%1], %7;"
                 :
                 : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1),
                   "r"(crd2), "r"(crd3), "r"(crd4), "l"(cache_hint)
                 : "memory");
  }
319
320
}

321
TL_DEVICE void prefetch_tma_descriptor(const CUtensorMap &descriptor) {
322
323
324
325
  uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(&descriptor);
  asm volatile("prefetch.tensormap [%0];" : : "l"(gmem_int_desc) : "memory");
}

326
TL_DEVICE void mbarrier_init(uint64_t &smem_barrier, uint32_t arrive_count) {
327
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
328
329
330
  asm volatile("mbarrier.init.shared.b64 [%1], %0;"
               :
               : "r"(arrive_count), "r"(smem_int_ptr));
331
332
}

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
TL_DEVICE uint32_t mbarrier_try_wait(uint64_t &smem_barrier, int phase_bit) {

  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
  uint32_t waitComplete;

  asm volatile("{\n\t"
               ".reg .pred P1; \n\t"
               "mbarrier.try_wait.parity.shared.b64 P1, [%1], %2; \n\t"
               "selp.b32 %0, 1, 0, P1; \n\t"
               "}"
               : "=r"(waitComplete)
               : "r"(smem_int_ptr), "r"(phase_bit));

  return waitComplete;
}

349
TL_DEVICE void mbarrier_wait(uint64_t &smem_barrier, int phase_bit) {
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
  if (mbarrier_try_wait(smem_barrier, phase_bit) == 0) {
    uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
    // Arbitrarily large timer value after which try-wait expires and re-tries.
    uint32_t ticks = 0x989680;
    asm volatile("{\n\t"
                 ".reg .pred       P1; \n\t"
                 "LAB_WAIT: \n\t"
                 "mbarrier.try_wait.parity.shared.b64 P1, [%0], %1, %2; \n\t"
                 "@P1 bra DONE; \n\t"
                 "bra     LAB_WAIT; \n\t"
                 "DONE: \n\t"
                 "}"
                 :
                 : "r"(smem_int_ptr), "r"(phase_bit), "r"(ticks));
  }
}

TL_DEVICE void mbarrier_test_wait(uint64_t &smem_barrier, int phase_bit) {
368
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
369
370
371
372
373
374
375
376
377
378
379
380
  asm volatile(
      "{\n"
      ".reg .pred                P1;\n"
      "LAB_WAIT:\n"
      "mbarrier.test_wait.parity.shared::cta.b64 P1, [%0], %1;\n"
      "@P1                       bra.uni DONE;\n"
      "nanosleep.u32 5;\n" // wait a few nanoseconds on pre-Hopper architectures
                           // to save instruction issue slots
      "bra.uni                   LAB_WAIT;\n"
      "DONE:\n"
      "}\n" ::"r"(smem_int_ptr),
      "r"(phase_bit));
381
382
}

383
TL_DEVICE void mbarrier_arrive(uint64_t &smem_barrier) {
384
385
386
387
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
  asm volatile("mbarrier.arrive.shared.b64 _, [%0];" : : "r"(smem_int_ptr));
}

388
389
390
391
392
393
394
395
396
397
398
399
400
401
TL_DEVICE void mbarrier_arrive(uint64_t &smem_barrier, int cta_id,
                               uint32_t pred) {
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
  if (pred) {
    asm volatile("{\n\t"
                 ".reg .b32 remAddr32;\n\t"
                 "mapa.shared::cluster.u32  remAddr32, %0, %1;\n\t"
                 "mbarrier.arrive.shared::cluster.b64  _, [remAddr32];\n\t"
                 "}"
                 :
                 : "r"(smem_int_ptr), "r"(cta_id));
  }
}

402
403
TL_DEVICE void mbarrier_expect_tx(uint64_t &smem_barrier,
                                  uint32_t transaction_bytes) {
404
405
406
407
408
409
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
  asm volatile("mbarrier.expect_tx.shared.b64 [%1], %0;"
               :
               : "r"(transaction_bytes), "r"(smem_int_ptr));
}

410
411
TL_DEVICE void mbarrier_arrive_expect_tx(uint64_t &smem_barrier,
                                         uint32_t transaction_bytes) {
412
413
414
415
416
417
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
  asm volatile("mbarrier.arrive.expect_tx.shared.b64 _, [%1], %0;"
               :
               : "r"(transaction_bytes), "r"(smem_int_ptr));
}

418
TL_DEVICE void mbarrier_cp_async_arrive(uint64_t &smem_barrier) {
419
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
420
421
422
  asm volatile("cp.async.mbarrier.arrive.shared.b64 [%0];"
               :
               : "r"(smem_int_ptr));
423
424
}

425
426
427
TL_DEVICE void fence_proxy_async() {
  asm volatile("fence.proxy.async.shared::cta;" : :);
}
428

429
430
431
432
433
434
435
436
437
// Indicate arrival of warp issuing TMA_STORE
TL_DEVICE void tma_store_arrive() {
  asm volatile("cp.async.bulk.commit_group;");
}

template <int Count> TL_DEVICE void tma_store_wait() {
  asm volatile("cp.async.bulk.wait_group.read %0;" : : "n"(Count) : "memory");
}

438
TL_DEVICE void syncthreads_partial(uint64_t &smem_barrier) {
439
  uint32_t smem_int_ptr = smem_ptr_to_uint(&smem_barrier);
440
  uint64_t state = 0;
441
442
443
444
445
446
447
448
449
  asm volatile("{\n"
               ".reg .pred                P1;\n"
               "mbarrier.arrive.shared.b64 %1, [%0];\n"
               "LAB_WAIT:\n"
               "mbarrier.try_wait.shared.b64 P1, [%0], %1;\n"
               "@!P1                      bra.uni LAB_WAIT;\n"
               "}\n"
               :
               : "r"(smem_int_ptr), "l"(state));
450
451
}

452
453
template <uint32_t RegCount> TL_DEVICE void warpgroup_reg_alloc() {
  asm volatile("setmaxnreg.inc.sync.aligned.u32 %0;\n" : : "n"(RegCount));
454
455
}

456
457
template <uint32_t RegCount> TL_DEVICE void warpgroup_reg_dealloc() {
  asm volatile("setmaxnreg.dec.sync.aligned.u32 %0;\n" : : "n"(RegCount));
458
459
}

460
} // namespace tl