Class CudaMemoryPrefetcher
- Namespace
- DotCompute.Backends.CUDA.Memory
- Assembly
- DotCompute.Backends.CUDA.dll
Manages memory prefetching for unified memory to optimize data movement. Uses cudaMemPrefetchAsync to proactively move data between host and device.
public sealed class CudaMemoryPrefetcher : IDisposable
- Inheritance
-
CudaMemoryPrefetcher
- Implements
- Inherited Members
- Extension Methods
Constructors
CudaMemoryPrefetcher(CudaContext, CudaDevice, ILogger)
Initializes a new instance of the CudaMemoryPrefetcher class.
public CudaMemoryPrefetcher(CudaContext context, CudaDevice device, ILogger logger)
Parameters
contextCudaContextThe context.
deviceCudaDeviceThe device.
loggerILoggerThe logger.
Properties
PrefetchCount
Gets the total number of prefetch operations.
public long PrefetchCount { get; }
Property Value
PrefetchHitRate
Gets the prefetch hit rate.
public double PrefetchHitRate { get; }
Property Value
Statistics
Gets prefetch statistics.
public PrefetchStatistics Statistics { get; }
Property Value
SupportsPrefetch
Gets whether the device supports memory prefetching.
public bool SupportsPrefetch { get; }
Property Value
TotalPrefetchedBytes
Gets the total number of bytes prefetched.
public long TotalPrefetchedBytes { get; }
Property Value
Methods
AdviseMemoryAsync(nint, long, CudaMemoryAdvise, int, CancellationToken)
Advises CUDA about the expected access pattern for memory.
public Task<bool> AdviseMemoryAsync(nint devicePointer, long sizeInBytes, CudaMemoryAdvise advice, int deviceId = -1, CancellationToken cancellationToken = default)
Parameters
devicePointernintsizeInByteslongadviceCudaMemoryAdvisedeviceIdintcancellationTokenCancellationToken
Returns
BatchPrefetchAsync(PrefetchRequest[], CancellationToken)
Prefetches multiple memory regions in batch.
public Task<int> BatchPrefetchAsync(PrefetchRequest[] requests, CancellationToken cancellationToken = default)
Parameters
requestsPrefetchRequest[]cancellationTokenCancellationToken
Returns
Dispose()
Performs dispose.
public void Dispose()
PrefetchToDeviceAsync(nint, long, int, nint, CancellationToken)
Prefetches memory to the specified device asynchronously.
public Task<bool> PrefetchToDeviceAsync(nint ptr, long sizeInBytes, int deviceId = -1, nint stream = 0, CancellationToken cancellationToken = default)
Parameters
ptrnintsizeInByteslongdeviceIdintstreamnintcancellationTokenCancellationToken
Returns
PrefetchToHostAsync(nint, long, nint, CancellationToken)
Prefetches memory to the host CPU asynchronously.
public Task<bool> PrefetchToHostAsync(nint ptr, long sizeInBytes, nint stream = 0, CancellationToken cancellationToken = default)
Parameters
ptrnintsizeInByteslongstreamnintcancellationTokenCancellationToken
Returns
RecordPrefetchHit(nint)
Records a prefetch hit (data was used as expected).
public void RecordPrefetchHit(nint devicePointer)
Parameters
devicePointernint
RecordPrefetchMiss(nint)
Records a prefetch miss (data was not where expected).
public void RecordPrefetchMiss(nint devicePointer)
Parameters
devicePointernint
WaitForPrefetchesAsync(CancellationToken)
Waits for all pending prefetch operations to complete.
public Task WaitForPrefetchesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken