| 668 | |
| 669 | template <typename T> |
| 670 | Status GetResourceFromContext(OpKernelContext* ctx, const string& input_name, |
| 671 | T** resource) { |
| 672 | DataType dtype; |
| 673 | TF_RETURN_IF_ERROR(ctx->input_dtype(input_name, &dtype)); |
| 674 | if (dtype == DT_RESOURCE) { |
| 675 | const Tensor* handle; |
| 676 | TF_RETURN_IF_ERROR(ctx->input(input_name, &handle)); |
| 677 | return LookupResource(ctx, handle->scalar<ResourceHandle>()(), resource); |
| 678 | } |
| 679 | string container; |
| 680 | string shared_name; |
| 681 | { |
| 682 | mutex* mu; |
| 683 | TF_RETURN_IF_ERROR(ctx->input_ref_mutex(input_name, &mu)); |
| 684 | mutex_lock l(*mu); |
| 685 | Tensor tensor; |
| 686 | TF_RETURN_IF_ERROR(ctx->mutable_input(input_name, &tensor, true)); |
| 687 | if (tensor.NumElements() != 2) { |
| 688 | return errors::InvalidArgument( |
| 689 | "Resource handle must have 2 elements, but had shape: ", |
| 690 | tensor.shape().DebugString()); |
| 691 | } |
| 692 | container = tensor.flat<tstring>()(0); |
| 693 | shared_name = tensor.flat<tstring>()(1); |
| 694 | } |
| 695 | return ctx->resource_manager()->Lookup(container, shared_name, resource); |
| 696 | } |
| 697 | |
| 698 | namespace internal { |
| 699 |
no test coverage detected