forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader_op_kernel.cc
More file actions
55 lines (46 loc) · 2.01 KB
/
reader_op_kernel.cc
File metadata and controls
55 lines (46 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Copyright 2015 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/core/framework/reader_op_kernel.h"
namespace tensorflow {
ReaderOpKernel::ReaderOpKernel(OpKernelConstruction* context)
: OpKernel(context), have_handle_(false) {
OP_REQUIRES_OK(context, context->allocate_persistent(
tensorflow::DT_STRING,
tensorflow::TensorShape({2}), &handle_, nullptr));
}
ReaderOpKernel::~ReaderOpKernel() {
if (have_handle_ && cinfo_.resource_is_private_to_kernel()) {
TF_CHECK_OK(cinfo_.resource_manager()->Delete<ReaderInterface>(
cinfo_.container(), cinfo_.name()));
}
}
void ReaderOpKernel::Compute(OpKernelContext* ctx) {
mutex_lock l(mu_);
if (!have_handle_) {
OP_REQUIRES_OK(ctx, cinfo_.Init(ctx->resource_manager(), def(), false));
ReaderInterface* reader;
OP_REQUIRES_OK(ctx,
cinfo_.resource_manager()->LookupOrCreate<ReaderInterface>(
cinfo_.container(), cinfo_.name(), &reader,
[this](ReaderInterface** ret) {
*ret = factory_();
return Status::OK();
}));
reader->Unref();
auto h = handle_.AccessTensor(ctx)->flat<string>();
h(0) = cinfo_.container();
h(1) = cinfo_.name();
have_handle_ = true;
}
ctx->set_output_ref(0, &mu_, handle_.AccessTensor(ctx));
}
} // namespace tensorflow