1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_FRAMEWORK_CONTROL_FLOW_H_
17#define TENSORFLOW_CORE_FRAMEWORK_CONTROL_FLOW_H_
18
19#include "tensorflow/core/lib/hash/hash.h"
20#include "tensorflow/core/platform/logging.h"
21#include "tensorflow/core/platform/types.h"
22
23namespace tensorflow {
24
25const uint64 kIllegalFrameId = ~0uLL;
26const int64_t kIllegalIterId = -1;
27
28// For the purpose of control flow, every tensor produced by TensorFlow is
29// conceptually tagged by a 'FrameAndIter'. FrameAndIter consists of a
30// 'frame_id' and an 'iter_id'. The tensor value it represents is produced
31// in the frame with frame_id at the iteration of iter_id.
32struct FrameAndIter {
33 uint64 frame_id = kIllegalFrameId;
34 int64_t iter_id = kIllegalIterId;
35
36 FrameAndIter() {}
37
38 FrameAndIter(uint64 frame, int64_t iter) {
39 frame_id = frame;
40 iter_id = iter;
41 }
42
43 bool operator==(const FrameAndIter& other) const {
44 return (frame_id == other.frame_id && iter_id == other.iter_id);
45 }
46};
47
48struct FrameAndIterHash {
49 size_t operator()(const FrameAndIter& key) const {
50 // Make sure there are no padding bytes that we don't want
51 CHECK_EQ(sizeof(uint64) + sizeof(int64_t), sizeof(FrameAndIter));
52 return Hash64(reinterpret_cast<const char*>(&key), sizeof(FrameAndIter));
53 }
54};
55
56} // namespace tensorflow
57
58#endif // TENSORFLOW_CORE_FRAMEWORK_CONTROL_FLOW_H_
59