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

Method ComputeAsync

tensorflow/core/kernels/barrier_ops.cc:581–621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

579
580 protected:
581 void ComputeAsync(OpKernelContext* ctx, Barrier* barrier,
582 DoneCallback callback) override {
583 const Tensor* Tnum_elements;
584 OP_REQUIRES_OK_ASYNC(ctx, ctx->input("num_elements", &Tnum_elements),
585 callback);
586 OP_REQUIRES_ASYNC(ctx, TensorShapeUtils::IsScalar(Tnum_elements->shape()),
587 errors::InvalidArgument("num_elements must be a scalar."),
588 callback);
589 const int32 num_elements = Tnum_elements->scalar<int32>()();
590
591 DataTypeVector expected_inputs = {DT_STRING_REF, DT_INT32};
592 // The first output is the insertion index, the second output is the key.
593 DataTypeVector expected_outputs = {DT_INT64, DT_STRING};
594 for (DataType dt : barrier->component_types()) {
595 expected_outputs.push_back(dt);
596 }
597 OP_REQUIRES_OK_ASYNC(
598 ctx, ctx->MatchSignature(expected_inputs, expected_outputs), callback);
599
600 barrier->TryTakeMany(
601 num_elements, allow_small_batch_, timeout_, ctx,
602 [ctx, callback](const Tensor& indices, const Tensor& keys,
603 const Barrier::Tuple& values) {
604 if (!ctx->status().ok()) {
605 callback();
606 return;
607 }
608 // At this point, indices, keys, and values
609 // have all been written to successfully.
610 OP_REQUIRES_OK_ASYNC(ctx, ctx->set_output("indices", indices),
611 callback);
612 OP_REQUIRES_OK_ASYNC(ctx, ctx->set_output("keys", keys), callback);
613 OpOutputList values_output;
614 OP_REQUIRES_OK_ASYNC(ctx, ctx->output_list("values", &values_output),
615 callback);
616 for (size_t i = 0; i < values.size(); ++i) {
617 values_output.set(i, values[i]);
618 }
619 callback();
620 });
621 }
622
623 private:
624 int64 timeout_;

Callers

nothing calls this directly

Calls 15

InvalidArgumentFunction · 0.85
callbackFunction · 0.85
component_typesMethod · 0.80
MatchSignatureMethod · 0.80
TryTakeManyMethod · 0.80
output_listMethod · 0.80
IsScalarFunction · 0.50
inputMethod · 0.45
shapeMethod · 0.45
push_backMethod · 0.45
okMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected