MCPcopy Create free account
hub / github.com/KnowingNothing/MatmulTutorial / ClusterBarrier

Class ClusterBarrier

include/barrier.h:26–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26struct ClusterBarrier {
27 using ValueType = uint64_t;
28
29 protected:
30 // Can never be initialized - can only be aliased to smem
31 ValueType barrier_;
32
33 public:
34 DEVICE ClusterBarrier() = delete;
35
36 DEVICE void init(uint32_t arrive_count) const {
37 ClusterBarrier::init(&this->barrier_, arrive_count);
38 }
39
40 DEVICE uint32_t test_wait(uint32_t phase, uint32_t pred = true) const {
41 return ClusterBarrier::test_wait(&this->barrier_, phase, pred);
42 }
43
44 DEVICE uint32_t try_wait(uint32_t phase) const {
45 return ClusterBarrier::try_wait(&this->barrier_, phase);
46 }
47
48 DEVICE void wait(uint32_t phase) const {
49 ClusterBarrier::wait(&this->barrier_, phase);
50 }
51
52 // Barrier arrive on local smem
53 DEVICE void arrive() const { ClusterBarrier::arrive(&this->barrier_); }
54
55 // Remote SMEM arrive with a perdicate (usually done to pick the thread doing
56 // the arrive)
57 DEVICE void arrive(uint32_t cta_id, uint32_t pred = true) const {
58 ClusterBarrier::arrive(&this->barrier_, cta_id, pred);
59 }
60
61 //
62 // Static Versions
63 //
64 DEVICE static void init(ValueType const *smem_ptr, uint32_t arrive_count) {
65 uint32_t smem_addr = cast_smem_ptr_to_uint(smem_ptr);
66 asm volatile(
67 "{\n\t"
68 "mbarrier.init.shared.b64 [%1], %0; \n"
69 "}"
70 :
71 : "r"(arrive_count), "r"(smem_addr));
72 }
73
74 // Static version of wait - in case we don't want to burn a register
75 DEVICE static void wait(ValueType const *smem_ptr, uint32_t phase) {
76 uint32_t smem_addr = cast_smem_ptr_to_uint(smem_ptr);
77 // Arbitrarily large timer value after which try-wait expires and re-tries.
78 uint32_t ticks = 0x989680;
79 asm volatile(
80 "{\n\t"
81 ".reg .pred P1; \n\t"
82 "LAB_WAIT: \n\t"
83 "mbarrier.try_wait.parity.shared.b64 P1, [%0], %1, %2; \n\t"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected