pytorch/c10/core/InferenceMode.cpp
Alban Desmaison 41ffec07ce Add a common autograd TLS state (#63860)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/63860

Test Plan: Imported from OSS

Reviewed By: heitorschueroff

Differential Revision: D30513253

Pulled By: albanD

fbshipit-source-id: 97d76ed54dfbdf4ba3fc7051ce3b9bb636cefb4b
2021-08-24 15:34:06 -07:00

14 lines
450 B
C++

#include <c10/core/InferenceMode.h>
#include <stdexcept>
namespace c10 {
// Invariant:
// is_enabled() ==
// !c10::impl::tls_is_dispatch_key_included(DispatchKey::ADInplaceOrView);
// 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 AutogradState::get_tls_state().get_inference_mode();
}
} // namespace c10