• 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 #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 
23 namespace tensorflow {
24 
25 const uint64 kIllegalFrameId = ~0uLL;
26 const int64 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.
32 struct FrameAndIter {
33   uint64 frame_id = kIllegalFrameId;
34   int64 iter_id = kIllegalIterId;
35 
FrameAndIterFrameAndIter36   FrameAndIter() {}
37 
FrameAndIterFrameAndIter38   FrameAndIter(uint64 frame, int64 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 
48 struct FrameAndIterHash {
operatorFrameAndIterHash49   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), 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