pub struct InterGpuTransfer { /* private fields */ }Expand description
Inter-GPU data transfer manager.
Maintains a per-device “last submitted buffer” slot so that gather
can perform real GPU→CPU readback. After dispatching work to device i,
call set_device_buffer with the result buffer
and its byte-size; then gather will DMA-read every registered buffer
back to the host and return the raw bytes.
Implementations§
Source§impl InterGpuTransfer
impl InterGpuTransfer
Sourcepub fn new(manager: Arc<MultiGpuManager>) -> Self
pub fn new(manager: Arc<MultiGpuManager>) -> Self
Create a new inter-GPU transfer manager.
Sourcepub fn set_device_buffer(
&self,
device_idx: usize,
buffer: Arc<Buffer>,
size_bytes: u64,
) -> GpuResult<()>
pub fn set_device_buffer( &self, device_idx: usize, buffer: Arc<Buffer>, size_bytes: u64, ) -> GpuResult<()>
Register the GPU buffer produced by a compute pass on device_idx.
The buffer must have at least BufferUsages::COPY_SRC so that
gather can issue a copy-to-staging command.
§Errors
Returns GpuError::InvalidBuffer when device_idx is out of range
or the internal lock is poisoned.
Sourcepub async fn copy_buffer(
&self,
src_device: usize,
dst_device: usize,
data: &[u8],
) -> GpuResult<()>
pub async fn copy_buffer( &self, src_device: usize, dst_device: usize, data: &[u8], ) -> GpuResult<()>
Copy data between GPUs via the host (staging).
§Errors
Returns an error if transfer fails or devices are invalid.
Sourcepub async fn gather(&self, dst_device: usize) -> GpuResult<Vec<Vec<u8>>>
pub async fn gather(&self, dst_device: usize) -> GpuResult<Vec<Vec<u8>>>
Gather data from every source device to dst_device.
For each source device i (where i != dst_device) that has had a
buffer registered via set_device_buffer,
this method performs a real GPU→CPU readback:
- Allocates a CPU-visible staging buffer on device
i. - Encodes a
copy_buffer_to_buffercommand from the registered source buffer into the staging buffer, then submits it to the device queue. - Polls the device until the submission has completed (blocking wait).
- Maps the staging buffer for reading, copies the data, and unmaps it.
The returned Vec<Vec<u8>> contains one entry per source device
(ordered by ascending device index, skipping dst_device). Devices
that have no registered buffer produce an empty Vec<u8>.
§Errors
Returns an error when:
dst_device >= num_devices- the wgpu device poll fails
- the staging buffer cannot be mapped (e.g., the source buffer is missing
COPY_SRCusage) - an internal mutex is poisoned