Class NumaAffinityManager
- Namespace
- DotCompute.Backends.CPU.Threading.NUMA
- Assembly
- DotCompute.Backends.CPU.dll
Manages thread and process affinity for NUMA optimization.
public sealed class NumaAffinityManager : IDisposable
- Inheritance
-
NumaAffinityManager
- Implements
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the NumaAffinityManager class.
Constructors
NumaAffinityManager(NumaTopology)
Manages thread and process affinity for NUMA optimization.
public NumaAffinityManager(NumaTopology topology)
Parameters
topologyNumaTopologyNUMA topology information.
Remarks
Initializes a new instance of the NumaAffinityManager class.
Methods
ClearThreadAffinity(int)
Clears thread affinity, allowing the thread to run on any processor.
public bool ClearThreadAffinity(int threadId)
Parameters
threadIdintThread ID (0 for current thread).
Returns
- bool
True if affinity was cleared successfully.
CreateAffinityScope(int)
Creates an affinity scope that automatically restores original affinity.
public IDisposable CreateAffinityScope(int nodeId)
Parameters
nodeIdintNode ID to set affinity to.
Returns
- IDisposable
Disposable affinity scope.
Dispose()
Disposes of the affinity manager and clears all managed affinities.
public void Dispose()
GetAffinityStatistics()
Gets affinity statistics for monitoring.
public AffinityStatistics GetAffinityStatistics()
Returns
- AffinityStatistics
Affinity statistics.
GetOptimalNodeForMask(ulong)
Gets the optimal NUMA node for a processor mask.
public int GetOptimalNodeForMask(ulong processorMask)
Parameters
processorMaskulongProcessor mask.
Returns
- int
Optimal node ID.
GetOptimalNodeForProcessors(IEnumerable<int>)
Gets the optimal NUMA node for a set of processors.
public int GetOptimalNodeForProcessors(IEnumerable<int> processorIds)
Parameters
processorIdsIEnumerable<int>Processor IDs.
Returns
- int
Optimal node ID.
GetProcessAffinity(int)
Gets the current process affinity information.
public AffinityInfo? GetProcessAffinity(int processId)
Parameters
processIdintProcess ID (0 for current process).
Returns
- AffinityInfo
Affinity information or null if not set.
GetThreadAffinity(int)
Gets the current thread affinity information.
public AffinityInfo? GetThreadAffinity(int threadId)
Parameters
threadIdintThread ID (0 for current thread).
Returns
- AffinityInfo
Affinity information or null if not set.
RunCurrentThreadOnNode(int)
Runs the current thread on a specific NUMA node.
public bool RunCurrentThreadOnNode(int nodeId)
Parameters
nodeIdintNUMA node ID.
Returns
- bool
True if the operation succeeded.
SetProcessAffinity(int, int)
Sets process affinity to a specific NUMA node.
public bool SetProcessAffinity(int processId, int nodeId)
Parameters
Returns
- bool
True if affinity was set successfully.
SetThreadAffinity(int, int)
Sets thread affinity to a specific NUMA node.
public bool SetThreadAffinity(int threadId, int nodeId)
Parameters
Returns
- bool
True if affinity was set successfully.
SetThreadAffinityMask(int, ulong)
Sets thread affinity to specific processors.
public bool SetThreadAffinityMask(int threadId, ulong processorMask)
Parameters
Returns
- bool
True if affinity was set successfully.