mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-06-08 00:23:03 +00:00
### 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
36 lines
972 B
C++
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
|