Class MultiGpuContext
- Namespace
- NVMathNet
- Assembly
- NVMath.Net.dll
Manages a set of CUDA devices for single-process multi-GPU execution. Enables peer-to-peer access between GPUs and provides helpers to run work concurrently across devices using one thread per GPU.
public sealed class MultiGpuContext : IDisposableInheritance
Implements
Inherited Members
Constructors
MultiGpuContext(int[]?)
Creates a multi-GPU context managing the specified devices. Enables peer-to-peer access where supported.
public MultiGpuContext(int[]? deviceIds = null)Parameters
deviceIdsint[]?-
Device ordinals to manage. If null, uses all available devices.
Properties
DeviceCount
Number of GPUs in this context.
public int DeviceCount { get; }Property Value
DeviceIds
The device IDs managed by this context.
public IReadOnlyList<int> DeviceIds { get; }Property Value
Methods
CanAccessPeer(int, int)
Returns whether peer access is possible between two device indices in this context.
public bool CanAccessPeer(int fromIndex, int toIndex)Parameters
Returns
CopyPeerAsync<T>(DeviceBuffer<T>, int, DeviceBuffer<T>, int, CudaStream?)
Copies data from a device buffer on one GPU to a device buffer on another GPU using peer-to-peer transfer.
public void CopyPeerAsync<T>(DeviceBuffer<T> dst, int dstDeviceIndex, DeviceBuffer<T> src, int srcDeviceIndex, CudaStream? stream = null) where T : unmanaged, INumberBase<T>Parameters
dstDeviceBuffer<T>dstDeviceIndexintsrcDeviceBuffer<T>srcDeviceIndexintstreamCudaStream?
Type Parameters
T
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()ForEachDevice(Action<int, int, CudaStream>)
Runs an action on each device in parallel, one thread per GPU. Each thread has its device set as current before the action is invoked.
public void ForEachDevice(Action<int, int, CudaStream> action)Parameters
actionAction<int, int, CudaStream>-
Action receiving (deviceIndex, deviceId, stream) where deviceIndex is 0-based within this context.
ForEachDeviceAsync(Func<int, int, CudaStream, Task>, CancellationToken)
Runs an async action on each device concurrently, one task per GPU.
public Task ForEachDeviceAsync(Func<int, int, CudaStream, Task> action, CancellationToken ct = default)Parameters
actionFunc<int, int, CudaStream, Task>ctCancellationToken
Returns
GetDeviceId(int)
Returns the CUDA device ID for the given index (0-based within this context).
public int GetDeviceId(int index)Parameters
indexint
Returns
GetDeviceName(int)
Returns the device name for the given device index.
public string GetDeviceName(int index)Parameters
indexint
Returns
GetStream(int)
Returns the stream associated with the given device index (0-based within this context).
public CudaStream GetStream(int index)Parameters
indexint
Returns
SetDevice(int)
Sets the active CUDA device for the calling thread to the device at index
(0-based within this context).
public void SetDevice(int index)Parameters
indexint
SynchronizeAll()
Synchronises all streams in this context, blocking until all GPU work completes.
public void SynchronizeAll()SynchronizeAllAsync(CancellationToken)
Synchronises all streams asynchronously.
public Task SynchronizeAllAsync(CancellationToken ct = default)