mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/56830 Opt into formatting on GitHub and format everything. This is a trial run before turning on formatting for more and eventually all of the codebase. Test Plan: CI Reviewed By: zertosh Differential Revision: D27979080 fbshipit-source-id: a80f0c48691c08ae8ca0af06377b87e6a2351151
21 lines
624 B
C++
21 lines
624 B
C++
#include <c10/core/InferenceMode.h>
|
|
#include <stdexcept>
|
|
|
|
namespace c10 {
|
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
thread_local bool InferenceMode_enabled = false;
|
|
|
|
// Invariant:
|
|
// is_enabled() ==
|
|
// !c10::impl::tls_is_dispatch_key_included(DispatchKey::InplaceOrView);
|
|
// InferenceMode::is_enabled() is in perf critical path (TensorImpl constructor)
|
|
// so it worths a separate TLS to skip the DispatchKeySet check.
|
|
bool InferenceMode::is_enabled() {
|
|
return InferenceMode_enabled;
|
|
}
|
|
|
|
void InferenceMode::set_enabled(bool enabled) {
|
|
InferenceMode_enabled = enabled;
|
|
}
|
|
} // namespace c10
|