using System; using System.Linq; using NvAPIWrapper.Native; using NvAPIWrapper.Native.GPU.Structures; namespace NvAPIWrapper.GPU { /// /// Represents a logical NVIDIA GPU /// public class LogicalGPU : IEquatable { /// /// Creates a new LogicalGPU /// /// Logical GPU handle public LogicalGPU(LogicalGPUHandle handle) { Handle = handle; } /// /// Gets a list of all corresponding physical GPUs /// public PhysicalGPU[] CorrespondingPhysicalGPUs { get { return GPUApi.GetPhysicalGPUsFromLogicalGPU(Handle).Select(handle => new PhysicalGPU(handle)).ToArray(); } } /// /// Gets the logical GPU handle /// public LogicalGPUHandle Handle { get; } /// public bool Equals(LogicalGPU other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return Handle.Equals(other.Handle); } /// /// Gets all logical GPUs /// /// An array of logical GPUs public static LogicalGPU[] GetLogicalGPUs() { return GPUApi.EnumLogicalGPUs().Select(handle => new LogicalGPU(handle)).ToArray(); } /// /// Checks for equality between two objects of same type /// /// The first object /// The second object /// true, if both objects are equal, otherwise false public static bool operator ==(LogicalGPU left, LogicalGPU right) { return right?.Equals(left) ?? ReferenceEquals(left, null); } /// /// Checks for inequality between two objects of same type /// /// The first object /// The second object /// true, if both objects are not equal, otherwise false public static bool operator !=(LogicalGPU left, LogicalGPU right) { return !(left == right); } /// public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((LogicalGPU) obj); } /// public override int GetHashCode() { return Handle.GetHashCode(); } /// public override string ToString() { return $"Logical GPU [{CorrespondingPhysicalGPUs.Length}] {{{string.Join(", ", CorrespondingPhysicalGPUs.Select(gpu => gpu.FullName).ToArray())}}}"; } } }