| 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. |
nothing calls this directly
no test coverage detected