Make ResourceHandle private to tensorflow library (#9994)
tensorflow::ResourceHandle is a protobuf object. The official protobuf document suggests: "If your project is itself a DLL intended for use by third-party software, we recommend that you do NOT expose protocol buffer objects in your library's public interface, and that you statically link protocol buffers into your library" Without this change, it is not able to implement a ResourceOpKernel in DLL on Windows.
This commit is contained in:
parent
fabd225532
commit
f2a46993e3
@ -24,6 +24,34 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/platform/demangle.h"
|
#include "tensorflow/core/platform/demangle.h"
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
|
ResourceHandle MakeResourceHandle(OpKernelContext* ctx, const string& container,
|
||||||
|
const string& name,
|
||||||
|
const TypeIndex& type_index) {
|
||||||
|
ResourceHandle result;
|
||||||
|
result.set_device(ctx->device()->attributes().name());
|
||||||
|
string actual_container;
|
||||||
|
if (!container.empty()) {
|
||||||
|
actual_container = container;
|
||||||
|
} else {
|
||||||
|
actual_container = ctx->resource_manager()->default_container();
|
||||||
|
}
|
||||||
|
result.set_container(actual_container);
|
||||||
|
result.set_name(name);
|
||||||
|
result.set_hash_code(type_index.hash_code());
|
||||||
|
result.set_maybe_type_name(type_index.name());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status MakeResourceHandleToOutput(OpKernelContext* context, int output_index,
|
||||||
|
const string& container, const string& name,
|
||||||
|
const TypeIndex& type_index) {
|
||||||
|
Tensor* handle;
|
||||||
|
TF_RETURN_IF_ERROR(
|
||||||
|
context->allocate_output(output_index, TensorShape({}), &handle));
|
||||||
|
handle->scalar<ResourceHandle>()() =
|
||||||
|
MakeResourceHandle(context, container, name, type_index);
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
@ -202,9 +202,20 @@ class ResourceMgr {
|
|||||||
|
|
||||||
// Makes a resource handle with the specified type for a given container /
|
// Makes a resource handle with the specified type for a given container /
|
||||||
// name.
|
// name.
|
||||||
|
ResourceHandle MakeResourceHandle(OpKernelContext* ctx, const string& container,
|
||||||
|
const string& name,
|
||||||
|
const TypeIndex& type_index);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
ResourceHandle MakeResourceHandle(OpKernelContext* ctx, const string& container,
|
ResourceHandle MakeResourceHandle(OpKernelContext* ctx, const string& container,
|
||||||
const string& name);
|
const string& name) {
|
||||||
|
return MakeResourceHandle(ctx, container, name, MakeTypeIndex<T>());
|
||||||
|
}
|
||||||
|
|
||||||
|
Status MakeResourceHandleToOutput(OpKernelContext* context, int output_index,
|
||||||
|
const string& container, const string& name,
|
||||||
|
const TypeIndex& type_index);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
ResourceHandle MakePerStepResourceHandle(OpKernelContext* ctx,
|
ResourceHandle MakePerStepResourceHandle(OpKernelContext* ctx,
|
||||||
const string& name);
|
const string& name);
|
||||||
@ -423,25 +434,6 @@ Status GetResourceFromContext(OpKernelContext* ctx, const string& input_name,
|
|||||||
return ctx->resource_manager()->Lookup(container, shared_name, resource);
|
return ctx->resource_manager()->Lookup(container, shared_name, resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
ResourceHandle MakeResourceHandle(OpKernelContext* ctx, const string& container,
|
|
||||||
const string& name) {
|
|
||||||
ResourceHandle result;
|
|
||||||
result.set_device(ctx->device()->attributes().name());
|
|
||||||
string actual_container;
|
|
||||||
if (!container.empty()) {
|
|
||||||
actual_container = container;
|
|
||||||
} else {
|
|
||||||
actual_container = ctx->resource_manager()->default_container();
|
|
||||||
}
|
|
||||||
result.set_container(actual_container);
|
|
||||||
result.set_name(name);
|
|
||||||
auto type_index = MakeTypeIndex<T>();
|
|
||||||
result.set_hash_code(type_index.hash_code());
|
|
||||||
result.set_maybe_type_name(type_index.name());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
ResourceHandle MakePerStepResourceHandle(OpKernelContext* ctx,
|
ResourceHandle MakePerStepResourceHandle(OpKernelContext* ctx,
|
||||||
const string& name) {
|
const string& name) {
|
||||||
|
@ -95,11 +95,9 @@ class ResourceOpKernel : public OpKernel {
|
|||||||
resource_ = resource;
|
resource_ = resource;
|
||||||
}
|
}
|
||||||
if (context->expected_output_dtype(0) == DT_RESOURCE) {
|
if (context->expected_output_dtype(0) == DT_RESOURCE) {
|
||||||
Tensor* handle;
|
OP_REQUIRES_OK(context, MakeResourceHandleToOutput(
|
||||||
OP_REQUIRES_OK(context,
|
context, 0, cinfo_.container(), cinfo_.name(),
|
||||||
context->allocate_output(0, TensorShape({}), &handle));
|
MakeTypeIndex<T>()));
|
||||||
handle->scalar<ResourceHandle>()() =
|
|
||||||
MakeResourceHandle<T>(context, cinfo_.container(), cinfo_.name());
|
|
||||||
} else {
|
} else {
|
||||||
context->set_output_ref(0, &mu_, handle_.AccessTensor(context));
|
context->set_output_ref(0, &mu_, handle_.AccessTensor(context));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user