1 /* Copyright 2020 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 #include "tensorflow/core/tpu/graph_rewrite/distributed_tpu_rewrite_pass_internal.h" 17 18 #include <limits> 19 20 #include "absl/random/random.h" 21 22 namespace tensorflow { 23 namespace { 24 25 static int64 overridden_node_id = -1; 26 27 } // namespace 28 29 namespace internal { 30 OverrideNodeIdForTesting(const int64 node_id)31void OverrideNodeIdForTesting(const int64 node_id) { 32 overridden_node_id = node_id; 33 } 34 GetNodeId()35uint64 GetNodeId() { 36 static absl::BitGen bitgen; 37 if (overridden_node_id > -1) { 38 return overridden_node_id; 39 } else { 40 return absl::Uniform(bitgen, uint64{0}, std::numeric_limits<uint64>::max()); 41 } 42 } 43 44 } // namespace internal 45 } // namespace tensorflow 46