Home | History | Annotate | Download | only in kernels
      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/resource_mgr.h"
     23 #include "tensorflow/core/framework/tensor.h"
     24 #include "tensorflow/core/framework/tensor_shape.h"
     25 #include "tensorflow/core/framework/types.h"
     26 #include "tensorflow/core/kernels/fifo_queue.h"
     27 #include "tensorflow/core/kernels/queue_base.h"
     28 #include "tensorflow/core/kernels/queue_op.h"
     29 #include "tensorflow/core/lib/core/errors.h"
     30 #include "tensorflow/core/platform/logging.h"
     31 #include "tensorflow/core/platform/macros.h"
     32 #include "tensorflow/core/platform/mutex.h"
     33 #include "tensorflow/core/platform/thread_annotations.h"
     34 #include "tensorflow/core/platform/types.h"
     35 
     36 namespace tensorflow {
     37 
     38 // Defines a FIFOQueueOp, which produces a Queue (specifically, one
     39 // backed by FIFOQueue) that persists across different graph
     40 // executions, and sessions. Running this op produces a single-element
     41 // tensor of handles to Queues in the corresponding device.
     42 class FIFOQueueOp : public TypedQueueOp {
     43  public:
     44   explicit FIFOQueueOp(OpKernelConstruction* context) : TypedQueueOp(context) {
     45     OP_REQUIRES_OK(context, context->GetAttr("shapes", &component_shapes_));
     46   }
     47 
     48  private:
     49   Status CreateResource(QueueInterface** ret) override
     50       EXCLUSIVE_LOCKS_REQUIRED(mu_) {
     51     FIFOQueue* queue = new FIFOQueue(capacity_, component_types_,
     52                                      component_shapes_, cinfo_.name());
     53     return CreateTypedQueue(queue, ret);
     54   }
     55 
     56   std::vector<TensorShape> component_shapes_;
     57   TF_DISALLOW_COPY_AND_ASSIGN(FIFOQueueOp);
     58 };
     59 
     60 REGISTER_KERNEL_BUILDER(Name("FIFOQueue").Device(DEVICE_CPU), FIFOQueueOp);
     61 REGISTER_KERNEL_BUILDER(Name("FIFOQueueV2").Device(DEVICE_CPU), FIFOQueueOp);
     62 
     63 }  // namespace tensorflow
     64