onnxruntime/onnxruntime/core/framework/random_seed.cc
Justin Chu cf19c3697d
Run clang-format in CI (#15524)
### Description

Run clang-format in CI. Formatted all c/c++, objective-c/c++ files.

Excluded

```
    'onnxruntime/core/mlas/**',
    'onnxruntime/contrib_ops/cuda/bert/tensorrt_fused_multihead_attention/**',
```

because they contain assembly or is data heavy


### Motivation and Context

Coding style consistency
2023-04-18 09:26:58 -07:00

36 lines
972 B
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "random_seed.h"
#include "random_generator.h"
#include <atomic>
#include <chrono>
namespace onnxruntime {
namespace utils {
// "Global initializer calls a non-constexpr function."
// TODO: Fix the warning. The variable should be put in the environment class.
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
#pragma warning(disable : 26426)
#endif
static std::atomic<int64_t> g_random_seed(std::chrono::system_clock::now().time_since_epoch().count());
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif
int64_t GetRandomSeed() {
return g_random_seed.load();
}
void SetRandomSeed(int64_t seed) {
g_random_seed.store(seed);
// Reset default generators.
RandomGenerator::Default().SetSeed(seed);
PhiloxGenerator::Default().SetSeed(static_cast<uint64_t>(seed));
}
} // namespace utils
} // namespace onnxruntime