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

Method Compute

tensorflow/compiler/xrt/kernels/xrt_state_ops.h:363–401  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361 XRTSubTupleOp& operator=(const XRTSubTupleOp&) = delete;
362
363 void Compute(OpKernelContext* ctx) override {
364 VLOG(1) << "XRTSubTupleOp::Compute";
365
366 const Tensor& handle_tensor = ctx->input(0);
367 OP_REQUIRES(
368 ctx, TensorShapeUtils::IsScalar(handle_tensor.shape()),
369 errors::Internal("computation input should be an int64 scalar"));
370 int64 allocation_handle = handle_tensor.scalar<int64>()();
371
372 const Tensor& subtuple_info = ctx->input(1);
373 OP_REQUIRES(
374 ctx, TensorShapeUtils::IsVector(subtuple_info.shape()),
375 errors::Internal("tuple index input should be an int32 vector"));
376 xla::ShapeIndex shape_index;
377 for (int i = 0; i < subtuple_info.dim_size(0); ++i) {
378 shape_index.push_back(subtuple_info.vec<int32>()(i));
379 }
380
381 ResourceMgr* rm;
382 OP_REQUIRES_OK(ctx, DeviceAccessor::GetResourceManager(ctx, &rm));
383
384 RefPtr<XRTMemoryManager> memory_manager = XRTMemoryManager::Get(rm);
385 RefPtr<XRTTupleAllocation> allocation;
386 OP_REQUIRES_OK(ctx, memory_manager->Lookup(allocation_handle, &allocation));
387
388 if (discard_) {
389 VLOG(2) << "Releasing handle " << allocation_handle;
390 OP_REQUIRES_OK(ctx, memory_manager->Release(allocation_handle));
391 }
392
393 XRTTupleAllocation* suballocation;
394 OP_REQUIRES_OK(
395 ctx, XRTTupleAllocation::MakeSubBuffer(allocation.get(), shape_index,
396 &suballocation, !discard_));
397
398 Tensor output(DT_INT64, TensorShape({}));
399 output.scalar<int64>()() = memory_manager->Register(suballocation);
400 ctx->set_output(0, output);
401 }
402};
403
404// Op that allocates memory for a literal and transfers it to the device.

Callers

nothing calls this directly

Calls 13

InternalFunction · 0.85
GetFunction · 0.85
IsScalarFunction · 0.50
TensorShapeClass · 0.50
inputMethod · 0.45
shapeMethod · 0.45
dim_sizeMethod · 0.45
push_backMethod · 0.45
LookupMethod · 0.45
ReleaseMethod · 0.45
getMethod · 0.45
RegisterMethod · 0.45

Tested by

no test coverage detected