| 57 | // "leader" Currently, it is optional to elect a leader for the Consumers |
| 58 | template <int Stages_, int ClusterX_, int ClusterY_, int ClusterZ_> |
| 59 | class PipelineTmaAsync { |
| 60 | public: |
| 61 | using FullBarrier = ClusterTransactionBarrier; |
| 62 | using EmptyBarrier = ClusterBarrier; |
| 63 | using ProducerBarrierType = FullBarrier::ValueType; |
| 64 | using ConsumerBarrierType = EmptyBarrier::ValueType; |
| 65 | static constexpr uint32_t Stages = Stages_; |
| 66 | using PipelineState = PipelineState<Stages>; |
| 67 | |
| 68 | struct SharedStorage { |
| 69 | FullBarrier full_barrier_[Stages]; |
| 70 | EmptyBarrier empty_barrier_[Stages]; |
| 71 | }; |
| 72 | |
| 73 | enum class ThreadCategory { |
| 74 | NonParticipant, |
| 75 | Producer, |
| 76 | Consumer, |
| 77 | ProducerConsumer |
| 78 | }; |
| 79 | |
| 80 | struct Params { |
| 81 | uint32_t transaction_bytes = 0; |
| 82 | ThreadCategory role = ThreadCategory::NonParticipant; |
| 83 | uint32_t is_leader = 0; |
| 84 | uint32_t num_consumers = 0; |
| 85 | int active_warps = 0; |
| 86 | }; |
| 87 | |
| 88 | // Constructor |
| 89 | DEVICE PipelineTmaAsync(SharedStorage& storage, Params params) |
| 90 | : params_(params), |
| 91 | full_barrier_ptr_(&storage.full_barrier_[0]), |
| 92 | empty_barrier_ptr_(&storage.empty_barrier_[0]) { |
| 93 | int warp_idx = canonical_warp_idx(); |
| 94 | int lane_predicate = elect_one_sync(); |
| 95 | if (warp_idx == params.active_warps && lane_predicate == 1) { |
| 96 | // Barrier FULL init |
| 97 | for (int i = 0; i < Stages; ++i) { |
| 98 | full_barrier_ptr_[i].init(1); |
| 99 | } |
| 100 | uint32_t const num_consumer_warpgroups_per_cluster = |
| 101 | params_.num_consumers / WARP_GROUP_SIZE; |
| 102 | uint32_t const multicast_consumer_arrival_count = |
| 103 | (ClusterX_ + ClusterY_ - 1) * num_consumer_warpgroups_per_cluster; |
| 104 | // Barrier EMPTY init |
| 105 | for (int i = 0; i < Stages; ++i) { |
| 106 | empty_barrier_ptr_[i].init(multicast_consumer_arrival_count); |
| 107 | } |
| 108 | } |
| 109 | // Logic to optimally schedule Empty Arrives |
| 110 | // Goal : To divide SYNCS Empty Arrival duty equally amongst the Warp-Group |
| 111 | // (128 threads) |
| 112 | dim3 block_id = block_id_in_cluster(); |
| 113 | static constexpr int cluster_size = ClusterX_ * ClusterY_ * ClusterZ_; |
| 114 | static_assert(cluster_size <= MAX_CLUSTER_SIZE, |
| 115 | "ERROR : Cluster size too large !"); |
| 116 |
nothing calls this directly
no test coverage detected