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

Method TryEnqueueMany

tensorflow/core/kernels/priority_queue.cc:130–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void PriorityQueue::TryEnqueueMany(const Tuple& tuple, OpKernelContext* ctx,
131 DoneCallback callback) {
132 const int64 batch_size = tuple[0].dim_size(0);
133 if (batch_size == 0) {
134 callback();
135 return;
136 }
137
138 CancellationManager* cm = ctx->cancellation_manager();
139 CancellationToken token = cm->get_cancellation_token();
140 bool already_cancelled;
141 {
142 mutex_lock l(mu_);
143 already_cancelled = !cm->RegisterCallback(
144 token, [this, cm, token]() { Cancel(kEnqueue, cm, token); });
145 if (!already_cancelled) {
146 enqueue_attempts_.emplace_back(
147 batch_size, callback, ctx, cm, token,
148 [tuple, this, ctx](Attempt* attempt) EXCLUSIVE_LOCKS_REQUIRED(mu_) {
149 if (closed_) {
150 attempt->context->SetStatus(
151 errors::Cancelled("PriorityQueue '", name_, "' is closed."));
152 return kComplete;
153 }
154 RunResult result = kNoProgress;
155 while (queues_[0].size() < static_cast<size_t>(capacity_)) {
156 result = kProgress;
157 const int index =
158 tuple[0].dim_size(0) - attempt->elements_requested;
159
160 PersistentTensor priority_element;
161 attempt->context->SetStatus(GetElementComponentFromBatch(
162 tuple, index, 0, attempt->context, &priority_element));
163 if (!attempt->context->status().ok()) return kComplete;
164 Tensor* priority_tensor = priority_element.AccessTensor(ctx);
165 if (!TensorShapeUtils::IsScalar(priority_tensor->shape())) {
166 attempt->context->SetStatus(errors::InvalidArgument(
167 "Expected the priority element to be a scalar, but "
168 "received shape: ",
169 priority_tensor->shape().DebugString()));
170 return kComplete;
171 }
172 const int64 priority = priority_tensor->scalar<int64>()();
173 for (int i = 0; i < num_components(); ++i) {
174 PersistentTensor element;
175 attempt->context->SetStatus(GetElementComponentFromBatch(
176 tuple, index, i, attempt->context, &element));
177 if (!attempt->context->status().ok()) return kComplete;
178 queues_[i].emplace(priority, element);
179 }
180 --attempt->elements_requested;
181 if (attempt->elements_requested == 0) {
182 return kComplete;
183 }
184 }
185 return result;
186 });
187 }

Callers

nothing calls this directly

Calls 15

callbackFunction · 0.85
CancelledFunction · 0.85
InvalidArgumentFunction · 0.85
num_componentsFunction · 0.85
AccessTensorMethod · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.50
IsScalarFunction · 0.50
dim_sizeMethod · 0.45
cancellation_managerMethod · 0.45
RegisterCallbackMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected