Device Transfer
torchlinops.linops.ToDevice
Bases: NamedLinop
Transfer tensors between devices as a named linear operator.
The forward operation moves a tensor from idevice to odevice.
The adjoint reverses the direction. The normal \(T^H T\) is the identity
(device round-trip is lossless).
For CUDA-to-CUDA transfers, streams and events are used for asynchronous pipelined execution.
| ATTRIBUTE | DESCRIPTION |
|---|---|
ispec |
Source (input) device specification containing device and stream info.
TYPE:
|
ospec |
Target (output) device specification containing device and stream info.
TYPE:
|
is_gpu2gpu |
True if both source and target devices are CUDA devices.
TYPE:
|
Source code in src/torchlinops/linops/device.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
__init__
__init__(
idevice: DeviceSpec | device | None,
odevice: DeviceSpec | device | None,
ioshape: Optional[Shape] = None,
)
| PARAMETER | DESCRIPTION |
|---|---|
idevice
|
Source (input) device specification.
TYPE:
|
odevice
|
Target (output) device specification.
TYPE:
|
ioshape
|
Named dimensions (same for input and output since this is diagonal).
TYPE:
|
Source code in src/torchlinops/linops/device.py
torchlinops.linops.DeviceSpec
dataclass
Lightweight data structure for holding useful CUDA-related objects for multi-GPU computation.
| ATTRIBUTE | DESCRIPTION |
|---|---|
device |
The device for computation and transfers.
TYPE:
|
compute_stream |
Stream used for computation on this device. Set automatically by
TYPE:
|
transfer_stream |
Stream used for data transfers to/from this device. Obtained from a registry to enable stream reuse across transfers.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
p2p_setup |
Configure compute and transfer streams for peer-to-peer transfers. |
get_transfer_stream |
Get or create a transfer stream for a source/target device pair. |
Source code in src/torchlinops/linops/device.py
__init__
__init__(
device: Any = (lambda: torch.device("cpu"))(),
compute_stream: Optional[Stream] = None,
transfer_stream: Optional[Stream] = None,
) -> None
p2p_setup
Sets up compute and transfer streams for peer2peer transfers, if not set yet.
| PARAMETER | DESCRIPTION |
|---|---|
other_device
|
The other device involved in the peer-to-peer transfer.
TYPE:
|
Source code in src/torchlinops/linops/device.py
get_transfer_stream
staticmethod
Return the stream used for device transfers associated with this device.
Streams are cached in a registry to enable reuse. Each source/target device pair gets a dedicated transfer stream.
| PARAMETER | DESCRIPTION |
|---|---|
source_device
|
The source device for transfers.
TYPE:
|
target_device
|
The target device for transfers.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Stream
|
A CUDA stream for performing transfers. |