forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_interface.h
More file actions
92 lines (71 loc) · 3.58 KB
/
queue_interface.h
File metadata and controls
92 lines (71 loc) · 3.58 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* 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.
==============================================================================*/
#ifndef TENSORFLOW_FRAMEWORK_QUEUE_INTERFACE_H_
#define TENSORFLOW_FRAMEWORK_QUEUE_INTERFACE_H_
#include <string>
#include <vector>
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/resource_mgr.h"
#include "tensorflow/core/framework/types.h"
#include "tensorflow/core/platform/port.h"
#include "tensorflow/core/public/tensor.h"
namespace tensorflow {
// All implementations must be thread-safe.
class QueueInterface : public ResourceBase {
public:
typedef std::vector<Tensor> Tuple;
typedef AsyncOpKernel::DoneCallback DoneCallback;
typedef std::function<void(const Tuple&)> CallbackWithTuple;
virtual Status ValidateTuple(const Tuple& tuple) = 0;
virtual Status ValidateManyTuple(const Tuple& tuple) = 0;
// Stashes a function object for future execution, that will eventually
// enqueue the tuple of tensors into the queue, and returns immediately. The
// function object is guaranteed to call 'callback'.
virtual void TryEnqueue(const Tuple& tuple, OpKernelContext* ctx,
DoneCallback callback) = 0;
// Same as above, but the component tensors are sliced along the 0th dimension
// to make multiple queue-element components.
virtual void TryEnqueueMany(const Tuple& tuple, OpKernelContext* ctx,
DoneCallback callback) = 0;
// Stashes a function object for future execution, that will eventually
// dequeue an element from the queue and call 'callback' with that tuple
// element as argument.
virtual void TryDequeue(OpKernelContext* ctx, CallbackWithTuple callback) = 0;
// Same as above, but the stashed function object will attempt to dequeue
// num_elements items.
virtual void TryDequeueMany(int num_elements, OpKernelContext* ctx,
CallbackWithTuple callback) = 0;
// Signals that no more elements will be enqueued, and optionally
// cancels pending Enqueue(Many) operations.
//
// After calling this function, subsequent calls to Enqueue(Many)
// will fail. If `cancel_pending_enqueues` is true, all pending
// calls to Enqueue(Many) will fail as well.
//
// After calling this function, all current and subsequent calls to
// Dequeue(Many) will fail instead of blocking (though they may
// succeed if they can be satisfied by the elements in the queue at
// the time it was closed).
virtual void Close(OpKernelContext* ctx, bool cancel_pending_enqueues,
DoneCallback callback) = 0;
// Assuming *this represents a shared queue, verify that it matches
// another instantiation indicated by node_def.
virtual Status MatchesNodeDef(const NodeDef& node_def) = 0;
// Returns the number of elements in the queue.
virtual int32 size() = 0;
virtual const DataTypeVector& component_dtypes() const = 0;
string DebugString() override { return "A queue"; }
protected:
virtual ~QueueInterface() {}
};
} // namespace tensorflow
#endif // TENSORFLOW_FRAMEWORK_QUEUE_INTERFACE_H_