1 /* Copyright 2019 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_KERNELS_STATEFUL_RANDOM_OPS_H_ 17 #define TENSORFLOW_CORE_KERNELS_STATEFUL_RANDOM_OPS_H_ 18 19 // #include "tensorflow/core/framework/resource_var.h" 20 #include "tensorflow/core/lib/random/philox_random.h" 21 22 namespace tensorflow { 23 24 // 'Variable' doesn't support uint32 or uint64 yet (due to reasons explained 25 // in b/111604096 and cl/171681867), so I use signed int here. I choose int64 26 // instead of int32 because `VarHandleOp` doesn't support int32 on GPU. 27 using StateElementType = int64; 28 static constexpr DataType STATE_ELEMENT_DTYPE = DT_INT64; 29 30 using Algorithm = StateElementType; 31 static constexpr DataType ALGORITHM_DTYPE = STATE_ELEMENT_DTYPE; 32 static constexpr Algorithm RNG_ALG_PHILOX = 1; 33 static constexpr Algorithm RNG_ALG_THREEFRY = 2; 34 35 using random::PhiloxRandom; 36 37 static constexpr int64 PHILOX_MIN_STATE_SIZE = 38 (PhiloxRandom::ResultType::kElementCount + 39 PhiloxRandom::Key::kElementCount) / 40 2; 41 static constexpr int64 THREEFRY_MIN_STATE_SIZE = 2; 42 43 } // end namespace tensorflow 44 45 #endif // TENSORFLOW_CORE_KERNELS_STATEFUL_RANDOM_OPS_H_ 46