Table of Contents

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 : IDisposable

Inheritance

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

deviceIds int[]?

Device ordinals to manage. If null, uses all available devices.

Properties

DeviceCount

Number of GPUs in this context.

public int DeviceCount { get; }

Property Value

int

DeviceIds

The device IDs managed by this context.

public IReadOnlyList<int> DeviceIds { get; }

Property Value

IReadOnlyList<int>

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

fromIndex int
toIndex int

Returns

bool

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

dst DeviceBuffer<T>
dstDeviceIndex int
src DeviceBuffer<T>
srcDeviceIndex int
stream CudaStream?

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

action Action<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

action Func<int, int, CudaStream, Task>
ct CancellationToken

Returns

Task

GetDeviceId(int)

Returns the CUDA device ID for the given index (0-based within this context).

public int GetDeviceId(int index)

Parameters

index int

Returns

int

GetDeviceName(int)

Returns the device name for the given device index.

public string GetDeviceName(int index)

Parameters

index int

Returns

string

GetStream(int)

Returns the stream associated with the given device index (0-based within this context).

public CudaStream GetStream(int index)

Parameters

index int

Returns

CudaStream

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

index int

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)

Parameters

ct CancellationToken

Returns

Task