3 #include <c10/core/Device.h> 62 enum Unsafe { UNSAFE };
63 enum Default { DEFAULT };
83 bool operator==(
const Stream& other)
const noexcept {
84 return this->device_ == other.device_ && this->id_ == other.id_;
86 bool operator!=(
const Stream& other)
const noexcept {
87 return !(*
this == other);
90 Device device()
const noexcept {
return device_; }
91 DeviceType device_type()
const noexcept {
return device_.
type(); }
93 StreamId id()
const noexcept {
return id_; }
102 uint64_t pack()
const noexcept {
105 static_assert(
sizeof(DeviceType) == 2,
"DeviceType is not 16-bit");
106 static_assert(
sizeof(
DeviceIndex) == 2,
"DeviceIndex is not 16-bit");
107 static_assert(
sizeof(
StreamId) == 4,
"DeviceIndex is not 32-bit");
111 static_cast<uint64_t
>(
static_cast<uint16_t
>(device_type())) << 48
112 |
static_cast<uint64_t
>(
static_cast<uint16_t
>(device_index())) << 32
113 |
static_cast<uint64_t
>(
static_cast<uint32_t
>(id()));
117 static Stream unpack(uint64_t bits) {
118 auto stream_id =
static_cast<StreamId>(bits) & 0xFFFFFFFFull;
120 auto device_index =
static_cast<DeviceIndex>(bits) & 0xFFFFull;
122 auto device_type =
static_cast<DeviceType
>(bits);
123 AT_CHECK(isValidDeviceType(device_type));
126 return Stream(UNSAFE,
Device(device_type, device_index), stream_id);
134 C10_API std::ostream& operator<<(std::ostream& stream,
const Stream& s);
142 return std::hash<uint64_t>{}(s.pack());
A stream is a software mechanism used to synchronize launched kernels without requiring explicit sync...
Represents a a compute device on which a tensor is located.
int16_t DeviceIndex
An index representing a specific device; e.g., the 1 in GPU 1.
Stream(Unsafe, Device device, StreamId id)
Unsafely construct a stream from a Device and a StreamId.
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
int32_t StreamId
An index representing a specific stream.
Flush-To-Zero and Denormals-Are-Zero mode.
DeviceIndex index() const noexcept
Returns the optional index.
DeviceType type() const noexcept
Returns the type of device this is.
Stream(Default, Device device)
Construct the default stream of a Device.