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#include "tensorflow/stream_executor/rng.h"
17
18#include "tensorflow/stream_executor/platform/logging.h"
19
20namespace perftools {
21namespace gputools {
22namespace rng {
23
24bool RngSupport::CheckSeed(const uint8 *seed, uint64 seed_bytes) {
25  CHECK(seed != nullptr);
26
27  if (seed_bytes < kMinSeedBytes) {
28    LOG(INFO) << "Insufficient RNG seed data specified: " << seed_bytes
29              << ". At least " << RngSupport::kMinSeedBytes
30              << " bytes are required.";
31    return false;
32  }
33
34  if (seed_bytes > kMaxSeedBytes) {
35    LOG(INFO) << "Too much RNG seed data specified: " << seed_bytes
36              << ". At most " << RngSupport::kMaxSeedBytes
37              << " bytes may be provided.";
38    return false;
39  }
40
41  return true;
42}
43
44#if defined(__APPLE__) || defined(__FreeBSD__)
45const int RngSupport::kMinSeedBytes;
46const int RngSupport::kMaxSeedBytes;
47#endif
48
49}  // namespace rng
50}  // namespace gputools
51}  // namespace perftools
52