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

Method EmitIndexTensor

tensorflow/core/kernels/batch_kernels.cc:644–660  ·  view source on GitHub ↗

Emits an index tensor, which the Unbatch op will use to un-concatenate the tensor and attribute the pieces to the right batch keys. The index tensor contains, for each input: [batch_key, start_offset, end_offset] where start_offset and end_offset represent the range of entries in the concatenated tensors that belong to that input. Emits the result to the output at 'output_index' using 'context'.

Source from the content-addressed store, hash-verified

642 //
643 // Emits the result to the output at 'output_index' using 'context'.
644 static Status EmitIndexTensor(OpKernelContext* context, const Batch& batch,
645 int output_index) {
646 const TensorShape index_shape({batch.num_tasks(), 3});
647 Tensor* index = nullptr;
648 TF_RETURN_IF_ERROR(
649 context->allocate_output(output_index, index_shape, &index));
650 auto index_flat = index->shaped<int64, 2>({batch.num_tasks(), 3});
651 size_t offset = 0;
652 for (int task_idx = 0; task_idx < batch.num_tasks(); ++task_idx) {
653 const BatchTask& task = batch.task(task_idx);
654 index_flat(task_idx, 0) = task.guid;
655 index_flat(task_idx, 1) = offset;
656 index_flat(task_idx, 2) = offset + task.size();
657 offset += task.size();
658 }
659 return Status::OK();
660 }
661
662 // Looks up the batcher queue for 'queue_name'. If it did't previously exist,
663 // creates it.

Callers

nothing calls this directly

Calls 4

allocate_outputMethod · 0.80
num_tasksMethod · 0.45
taskMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected