forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PythonFallbackKernel.h
35 lines (27 loc) · 1.07 KB
/
PythonFallbackKernel.h
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
#pragma once
#include <ATen/core/TorchDispatchUtils.h>
namespace at::impl {
struct TORCH_API RestorePythonTLSSnapshot {
RestorePythonTLSSnapshot();
RestorePythonTLSSnapshot(RestorePythonTLSSnapshot&& other) = delete;
RestorePythonTLSSnapshot(const RestorePythonTLSSnapshot&) = delete;
RestorePythonTLSSnapshot& operator=(const RestorePythonTLSSnapshot&) = delete;
RestorePythonTLSSnapshot& operator=(RestorePythonTLSSnapshot&&) = delete;
~RestorePythonTLSSnapshot();
private:
c10::impl::LocalDispatchKeySet saved_;
c10::impl::ForceDispatchKeyGuard guard_;
};
// RAII guard to make working with the above TLS safer.
struct TORCH_API MaybeSetTLSOnEntryGuard {
public:
MaybeSetTLSOnEntryGuard();
MaybeSetTLSOnEntryGuard(MaybeSetTLSOnEntryGuard&& other) = delete;
MaybeSetTLSOnEntryGuard(const MaybeSetTLSOnEntryGuard&) = delete;
MaybeSetTLSOnEntryGuard& operator=(const MaybeSetTLSOnEntryGuard&) = delete;
MaybeSetTLSOnEntryGuard& operator=(MaybeSetTLSOnEntryGuard&&) = delete;
~MaybeSetTLSOnEntryGuard();
private:
bool value_set_;
};
} // namespace at::impl