• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 // See docs in ../ops/data_flow_ops.cc.
17 
18 #include <deque>
19 #include <vector>
20 
21 #include "tensorflow/core/framework/op_kernel.h"
22 #include "tensorflow/core/framework/partial_tensor_shape.h"
23 #include "tensorflow/core/framework/resource_mgr.h"
24 #include "tensorflow/core/framework/tensor.h"
25 #include "tensorflow/core/framework/tensor_shape.h"
26 #include "tensorflow/core/framework/types.h"
27 #include "tensorflow/core/kernels/padding_fifo_queue.h"
28 #include "tensorflow/core/kernels/queue_base.h"
29 #include "tensorflow/core/kernels/queue_op.h"
30 #include "tensorflow/core/lib/core/errors.h"
31 #include "tensorflow/core/platform/logging.h"
32 #include "tensorflow/core/platform/macros.h"
33 #include "tensorflow/core/platform/mutex.h"
34 #include "tensorflow/core/platform/thread_annotations.h"
35 #include "tensorflow/core/platform/types.h"
36 
37 namespace tensorflow {
38 
39 // Defines a PaddingFIFOQueueOp, which produces a Queue (specifically, one
40 // backed by PaddingFIFOQueue) that persists across different graph
41 // executions, and sessions. Running this op produces a single-element
42 // tensor of handles to Queues in the corresponding device.
43 class PaddingFIFOQueueOp : public TypedQueueOp {
44  public:
PaddingFIFOQueueOp(OpKernelConstruction * context)45   explicit PaddingFIFOQueueOp(OpKernelConstruction* context)
46       : TypedQueueOp(context) {
47     OP_REQUIRES_OK(context, context->GetAttr("shapes", &component_shapes_));
48     for (const auto& shape : component_shapes_) {
49       OP_REQUIRES(context, shape.dims() >= 0,
50                   errors::InvalidArgument("shape ", shape.DebugString(),
51                                           " must have known rank."));
52     }
53   }
54 
55  private:
CreateResource(QueueInterface ** ret)56   Status CreateResource(QueueInterface** ret) override
57       EXCLUSIVE_LOCKS_REQUIRED(mu_) {
58     PaddingFIFOQueue* queue = new PaddingFIFOQueue(
59         capacity_, component_types_, component_shapes_, cinfo_.name());
60     return CreateTypedQueue(queue, ret);
61   }
62 
63   std::vector<PartialTensorShape> component_shapes_;
64 
65   TF_DISALLOW_COPY_AND_ASSIGN(PaddingFIFOQueueOp);
66 };
67 
68 REGISTER_KERNEL_BUILDER(Name("PaddingFIFOQueue").Device(DEVICE_CPU),
69                         PaddingFIFOQueueOp);
70 REGISTER_KERNEL_BUILDER(Name("PaddingFIFOQueueV2").Device(DEVICE_CPU),
71                         PaddingFIFOQueueOp);
72 
73 }  // namespace tensorflow
74