forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrad_mode.cpp
More file actions
35 lines (24 loc) · 764 Bytes
/
grad_mode.cpp
File metadata and controls
35 lines (24 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <ATen/core/grad_mode.h>
#include <stdexcept>
namespace at {
/// thread_local is a feature that is not enabled by Caffe2 mobile
/// build (e.g. iOS). Therefore, we only provide `at::GradMode`
/// when we are not in mobile build or when FEATURE_TORCH_MOBILE
/// is on.
#if !defined(C10_MOBILE) || defined(FEATURE_TORCH_MOBILE)
thread_local bool GradMode_enabled = true;
bool GradMode::is_enabled() {
return GradMode_enabled;
}
void GradMode::set_enabled(bool enabled) {
GradMode_enabled = enabled;
}
#else
bool GradMode::is_enabled() {
throw std::runtime_error("GradMode is not supported on mobile");
}
void GradMode::set_enabled(bool enabled) {
throw std::runtime_error("GradMode is not supported on mobile");
}
#endif
} // namespace at