Ingests data from one invocation of the batch op. The data is enqueued to be combined with others into a batch, asynchronously.
| 242 | // Ingests data from one invocation of the batch op. The data is enqueued to |
| 243 | // be combined with others into a batch, asynchronously. |
| 244 | Status RegisterInput(int64 guid, OpKernelContext* context, |
| 245 | const string& batcher_queue_name, |
| 246 | AsyncOpKernel::DoneCallback done_callback) { |
| 247 | std::unique_ptr<BatchTask> batch_components(new BatchTask); |
| 248 | batch_components->guid = guid; |
| 249 | batch_components->propagated_context = Context(ContextKind::kThread); |
| 250 | OpInputList tensors; |
| 251 | TF_RETURN_IF_ERROR(context->input_list("in_tensors", &tensors)); |
| 252 | for (int i = 0; i < tensors.size(); ++i) { |
| 253 | const Tensor& tensor = tensors[i]; |
| 254 | if (tensor.shape().dims() == 0) { |
| 255 | return errors::InvalidArgument( |
| 256 | "Batching input tensors must have at least one dimension"); |
| 257 | } |
| 258 | if (tensors.size() >= 2 && |
| 259 | tensor.shape().dim_size(0) != tensors[0].shape().dim_size(0)) { |
| 260 | return errors::InvalidArgument( |
| 261 | "Batching input tensors supplied in a given op invocation must " |
| 262 | "have equal 0th-dimension size"); |
| 263 | } |
| 264 | batch_components->inputs.push_back(tensor); |
| 265 | } |
| 266 | OpInputList captured_tensors; |
| 267 | const auto captured_status = |
| 268 | context->input_list("captured_tensors", &captured_tensors); |
| 269 | if (captured_status.ok()) { |
| 270 | for (const Tensor& captured_tensor : captured_tensors) { |
| 271 | batch_components->captured_inputs.push_back(captured_tensor); |
| 272 | } |
| 273 | } |
| 274 | batch_components->context = context; |
| 275 | batch_components->done_callback = std::move(done_callback); |
| 276 | |
| 277 | BatcherQueue* batcher_queue; |
| 278 | TF_RETURN_IF_ERROR( |
| 279 | LookupOrCreateBatcherQueue(batcher_queue_name, &batcher_queue)); |
| 280 | return batcher_queue->Schedule(&batch_components); |
| 281 | } |
| 282 | |
| 283 | private: |
| 284 | BatchResource() = default; |
no test coverage detected