MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / RunAsyncParts

Method RunAsyncParts

tensorflow/core/common_runtime/ring_gatherer.cc:125–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125bool RingGatherer::RunAsyncParts() {
126 // This function orchestrates RingGatherer actions on behalf of a
127 // single device. It is entered by a blockable thread that
128 // loops within it until all actions assigned to that device
129 // complete. Hence function local variables are accessible only by that
130 // one thread and do not require an explicit mutex.
131 rfv_.clear();
132 rfv_.resize(group_size_ * num_subdivs_);
133 PCQueue ready_queue;
134 for (int chunk_idx = 0; chunk_idx < group_size_; ++chunk_idx) {
135 for (int subdiv_idx = 0; subdiv_idx < num_subdivs_; ++subdiv_idx) {
136 int rf_index = (chunk_idx * num_subdivs_) + subdiv_idx;
137 InitRingField(&rfv_[rf_index], chunk_idx, subdiv_idx, rf_index);
138 ready_queue.Enqueue(&rfv_[rf_index]);
139 }
140 }
141 const DeviceBase::GpuDeviceInfo* gpu_info =
142 col_ctx_->device->tensorflow_gpu_device_info();
143 if (gpu_info) {
144 // Wait for all currently queued events on the CPU compute stream to
145 // complete before proceeding. The previous InitRingField calls allocated
146 // temp memory buffers that are not guaranteed to be valid (e.g. for RDMA
147 // write) unless we do.
148 profiler::TraceMe activity("WaitForQueuedEvents",
149 profiler::TraceMeLevel::kInfo);
150 Notification note;
151 Status s = gpu_info->default_context->ThenExecute(
152 col_ctx_->device, gpu_info->stream, [&note]() { note.Notify(); });
153 if (s.ok()) {
154 note.WaitForNotification();
155 } else {
156 mutex_lock l(status_mu_);
157 status_ =
158 errors::Internal("Failed to dispatch ThenExecute in RingGatherer");
159 return false;
160 }
161 }
162
163 int field_done_count = 0;
164 int send_pending_count = 0;
165 int recv_pending_count = 0;
166 std::atomic<bool> aborted(false);
167
168 // Loop until all RingFields have advanced to completion.
169 {
170 profiler::TraceMe activity("Loop", profiler::TraceMeLevel::kInfo);
171 while (field_done_count < rfv_.size()) {
172 VLOG(4) << FieldState();
173 // Wait for a RingField to appear in the ready_queue.
174 RingField* rf = ready_queue.Dequeue();
175 // Advance the RingField to its next action and execute, repeating
176 // until either an async action has been started or the RingField
177 // is done.
178 bool dispatched = false; // true if async action was initiated
179 do {
180 if (aborted) {
181 // Requeue this RingField to be counted off below.
182 ready_queue.Enqueue(rf);

Callers

nothing calls this directly

Calls 12

InternalFunction · 0.85
DequeueMethod · 0.80
clearMethod · 0.45
resizeMethod · 0.45
EnqueueMethod · 0.45
ThenExecuteMethod · 0.45
NotifyMethod · 0.45
okMethod · 0.45
WaitForNotificationMethod · 0.45
sizeMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected