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 #ifndef TENSORFLOW_CORE_FRAMEWORK_RNG_ALG_H_
17 #define TENSORFLOW_CORE_FRAMEWORK_RNG_ALG_H_
18
19 namespace tensorflow {
20
21 enum Algorithm {
22 // The Philox algorithm, as described in paper
23 // ['Parallel Random Numbers: As Easy as 1, 2, 3']
24 // (https://www.thesalmons.org/john/random123/papers/random123sc11.pdf)
25 RNG_ALG_PHILOX = 1,
26 // The ThreeFry algorithm, as described in paper
27 // ['Parallel Random Numbers: As Easy as 1, 2, 3']
28 // (https://www.thesalmons.org/john/random123/papers/random123sc11.pdf)
29 RNG_ALG_THREEFRY = 2,
30 // An algorithm suitable for TPU. Only available on XLA devices.
31 RNG_ALG_XLA_DEFAULT = 3
32 };
33
34 static constexpr int RNG_KEY_SIZE = 1;
35 static constexpr int RNG_MAX_COUNTER_SIZE = 2;
GetCounterSize(Algorithm alg)36 inline int GetCounterSize(Algorithm alg) {
37 if (alg == RNG_ALG_PHILOX) {
38 return 2;
39 } else if (alg == RNG_ALG_THREEFRY) {
40 return 1;
41 } else if (alg == RNG_ALG_XLA_DEFAULT) {
42 return 1;
43 }
44 return 2;
45 }
46
47 } // end namespace tensorflow
48
49 #endif // TENSORFLOW_CORE_FRAMEWORK_RNG_ALG_H_
50