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

Function GetResourceFromContext

tensorflow/core/framework/resource_mgr.h:670–696  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

668
669template <typename T>
670Status 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
698namespace internal {
699

Callers 14

ComputeAsyncMethod · 0.85
ComputeAsyncMethod · 0.85
ComputeMethod · 0.85
ComputeAsyncMethod · 0.85
ComputeMethod · 0.85
ComputeAsyncMethod · 0.85
ComputeWithReaderMethod · 0.85
ComputeWithReaderMethod · 0.85
ComputeMethod · 0.85
ComputeMethod · 0.85
ComputeMethod · 0.85
ComputeMethod · 0.85

Calls 11

LookupResourceFunction · 0.85
InvalidArgumentFunction · 0.85
input_ref_mutexMethod · 0.60
input_dtypeMethod · 0.45
inputMethod · 0.45
mutable_inputMethod · 0.45
NumElementsMethod · 0.45
DebugStringMethod · 0.45
shapeMethod · 0.45
LookupMethod · 0.45
resource_managerMethod · 0.45

Tested by

no test coverage detected