/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
torch
/
include
/
c10
/
core
/
/usr/local/lib64/python3.6/site-packages/torch/include/c10/core
mkdir
upload
Name
Size
Mode
Actions
impl/
-
0755
rm
Allocator.h
8725
0644
edit
dl
rm
AutogradState.h
994
0644
edit
dl
rm
Backend.h
8487
0644
edit
dl
rm
CompileTimeFunctionPointer.h
1677
0644
edit
dl
rm
CopyBytes.h
1229
0644
edit
dl
rm
CPUAllocator.h
2267
0644
edit
dl
rm
DefaultDtype.h
394
0644
edit
dl
rm
DefaultTensorOptions.h
1032
0644
edit
dl
rm
Device.h
5396
0644
edit
dl
rm
DeviceGuard.h
7555
0644
edit
dl
rm
DeviceType.h
2994
0644
edit
dl
rm
DispatchKey.h
18069
0644
edit
dl
rm
DispatchKeySet.h
12951
0644
edit
dl
rm
Event.h
4169
0644
edit
dl
rm
GeneratorImpl.h
3713
0644
edit
dl
rm
GradMode.h
1261
0644
edit
dl
rm
InferenceMode.h
3471
0644
edit
dl
rm
Layout.h
1225
0644
edit
dl
rm
MemoryFormat.h
8571
0644
edit
dl
rm
OptionalRef.h
521
0644
edit
dl
rm
QEngine.h
861
0644
edit
dl
rm
QScheme.h
1562
0644
edit
dl
rm
Scalar.h
6019
0644
edit
dl
rm
ScalarType.h
17073
0644
edit
dl
rm
ScalarTypeToTypeMeta.h
1365
0644
edit
dl
rm
Storage.h
4369
0644
edit
dl
rm
StorageImpl.h
5610
0644
edit
dl
rm
Stream.h
7373
0644
edit
dl
rm
StreamGuard.h
6315
0644
edit
dl
rm
TensorImpl.h
96152
0644
edit
dl
rm
TensorOptions.h
27593
0644
edit
dl
rm
thread_pool.h
2992
0644
edit
dl
rm
UndefinedTensorImpl.h
911
0644
edit
dl
rm
WrapDimMinimal.h
805
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/torch/include/c10/core/StreamGuard.h
(6315B)
#pragma once #include <c10/core/impl/InlineStreamGuard.h> namespace c10 { /** * A StreamGuard is an RAII class that changes the current device * to the device corresponding to some stream, and changes the * default stream on that device to be this stream. * * Use of StreamGuard is HIGHLY discouraged in operator definitions. In * a single operator, you probably don't know enough about the global * state of the world to profitably decide how to set streams. Let * the caller handle this appropriately, and just use the current stream * in your operator code. * * This StreamGuard does NOT have an uninitialized state; it is guaranteed * to reset the stream and device on exit. If you are in a situation * where you *might* want to setup a stream guard, see OptionalStreamGuard. */ struct StreamGuard { /// No default constructor, see Note [Omitted default constructor from RAII] explicit StreamGuard() = delete; /// Set the current device to the device associated with the passed stream, /// and set the current stream on that device to the passed stream. explicit StreamGuard(Stream stream) : guard_(stream) {} /// Copy is disallowed StreamGuard(const StreamGuard&) = delete; StreamGuard& operator=(const StreamGuard&) = delete; /// Move is disallowed, as StreamGuard does not have an uninitialized state, /// which is required for moves on types with nontrivial destructors. StreamGuard(StreamGuard&& other) = delete; StreamGuard& operator=(StreamGuard&& other) = delete; /// Resets the currently set stream to the original stream and /// the currently set device to the original device. Then, /// set the current device to the device associated with the passed stream, /// and set the current stream on that device to the passed stream. /// /// NOTE: this implementation may skip some stream/device setting if /// it can prove that it is unnecessary. /// /// WARNING: reset_stream does NOT preserve previously set streams on /// different devices. If you need to set streams on multiple devices /// on , use MultiStreamGuard instead. void reset_stream(Stream stream) { guard_.reset_stream(stream); } /// Returns the stream that was set at the time the guard was constructed. Stream original_stream() const { return guard_.original_stream(); } /// Returns the most recent stream that was set using this device guard, /// either from construction, or via set_stream. Stream current_stream() const { return guard_.current_stream(); } /// Returns the most recent device that was set using this device guard, /// either from construction, or via set_device/reset_device/set_index. Device current_device() const { return guard_.current_device(); } /// Returns the device that was set at the most recent reset_stream(), /// or otherwise the device at construction time. Device original_device() const { return guard_.original_device(); } private: c10::impl::InlineStreamGuard<impl::VirtualGuardImpl> guard_; }; /** * An OptionalStreamGuard is an RAII class that sets a device to some value on * initialization, and resets the device to its original value on destruction. * See OptionalDeviceGuard for more guidance on how to use this class. */ struct OptionalStreamGuard { /// Create an uninitialized guard. explicit OptionalStreamGuard() : guard_() {} /// Set the current device to the device associated with the passed stream, /// and set the current stream on that device to the passed stream. explicit OptionalStreamGuard(Stream stream) : guard_(stream) {} /// Set the current device to the device associated with the passed stream, /// and set the current stream on that device to the passed stream, /// if the passed stream is not nullopt. explicit OptionalStreamGuard(optional<Stream> stream_opt) : guard_(stream_opt) {} /// Copy is disallowed OptionalStreamGuard(const OptionalStreamGuard&) = delete; OptionalStreamGuard& operator=(const OptionalStreamGuard&) = delete; // See Note [Move construction for RAII guards is tricky] OptionalStreamGuard(OptionalStreamGuard&& other) = delete; // See Note [Move assignment for RAII guards is tricky] OptionalStreamGuard& operator=(OptionalStreamGuard&& other) = delete; /// Resets the currently set stream to the original stream and /// the currently set device to the original device. Then, /// set the current device to the device associated with the passed stream, /// and set the current stream on that device to the passed stream. /// Initializes the guard if it was not previously initialized. void reset_stream(Stream stream) { guard_.reset_stream(stream); } /// Returns the stream that was set at the time the guard was most recently /// initialized, or nullopt if the guard is uninitialized. optional<Stream> original_stream() const { return guard_.original_stream(); } /// Returns the most recent stream that was set using this stream guard, /// either from construction, or via reset_stream, if the guard is /// initialized, or nullopt if the guard is uninitialized. optional<Stream> current_stream() const { return guard_.current_stream(); } /// Restore the original device and stream, resetting this guard to /// uninitialized state. void reset() { guard_.reset(); } private: c10::impl::InlineOptionalStreamGuard<impl::VirtualGuardImpl> guard_; }; /** * A MultiStreamGuard is an RAII class that sets the current streams of a set of * devices all at once, and resets them to their original values on destruction. */ struct MultiStreamGuard { /// Set the current streams to the passed streams on each of their respective /// devices. explicit MultiStreamGuard(ArrayRef<Stream> streams) : guard_(streams) {} /// Copy is disallowed MultiStreamGuard(const MultiStreamGuard&) = delete; MultiStreamGuard& operator=(const MultiStreamGuard&) = delete; // See Note [Move construction for RAII guards is tricky] MultiStreamGuard(MultiStreamGuard&& other) = delete; // See Note [Move assignment for RAII guards is tricky] MultiStreamGuard& operator=(MultiStreamGuard&& other) = delete; private: c10::impl::InlineMultiStreamGuard<impl::VirtualGuardImpl> guard_; }; } // namespace c10
Save
cmd:
run