using System; using System.Linq; using NvAPIWrapper.Native.Exceptions; using NvAPIWrapper.Native.General; using NvAPIWrapper.Native.GPU; using NvAPIWrapper.Native.GPU.Structures; using NvAPIWrapper.Native.Helpers; using NvAPIWrapper.Native.Helpers.Structures; using NvAPIWrapper.Native.Interfaces.GPU; namespace NvAPIWrapper.Native { /// /// Contains GPU static functions /// // ReSharper disable once ClassTooBig public static partial class GPUApi { /// /// This function returns an array of logical GPU handles. /// Each handle represents one or more GPUs acting in concert as a single graphics device. /// At least one GPU must be present in the system and running an NVIDIA display driver. /// All logical GPUs handles get invalidated on a GPU topology change, so the calling application is required to /// re-enum /// the logical GPU handles to get latest physical handle mapping after every GPU topology change activated by a call /// to SetGpuTopologies(). /// To detect if SLI rendering is enabled, use Direct3DApi.GetCurrentSLIState(). /// /// Array of logical GPU handles. /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found public static LogicalGPUHandle[] EnumLogicalGPUs() { var gpuList = typeof(LogicalGPUHandle).Instantiate().Repeat(LogicalGPUHandle.MaxLogicalGPUs); var status = DelegateFactory.GetDelegate()(gpuList, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpuList.Take((int) count).ToArray(); } /// /// This function returns an array of physical GPU handles. /// Each handle represents a physical GPU present in the system. /// That GPU may be part of an SLI configuration, or may not be visible to the OS directly. /// At least one GPU must be present in the system and running an NVIDIA display driver. /// Note: In drivers older than 105.00, all physical GPU handles get invalidated on a mode-set. So the calling /// applications need to re-enum the handles after every mode-set. With drivers 105.00 and up, all physical GPU handles /// are constant. Physical GPU handles are constant as long as the GPUs are not physically moved and the SBIOS VGA /// order is unchanged. /// For GPU handles in TCC MODE please use EnumTCCPhysicalGPUs() /// /// /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found public static PhysicalGPUHandle[] EnumPhysicalGPUs() { var gpuList = typeof(PhysicalGPUHandle).Instantiate().Repeat(PhysicalGPUHandle.PhysicalGPUs); var status = DelegateFactory.GetDelegate()(gpuList, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpuList.Take((int) count).ToArray(); } /// /// This function returns an array of physical GPU handles that are in TCC Mode. /// Each handle represents a physical GPU present in the system in TCC Mode. /// That GPU may not be visible to the OS directly. /// NOTE: Handles enumerated by this API are only valid for NvAPIs that are tagged as TCC_SUPPORTED If handle is passed /// to any other API, it will fail with Status.InvalidHandle /// For WDDM GPU handles please use EnumPhysicalGPUs() /// /// An array of physical GPU handles that are in TCC Mode. /// See NVIDIAApiException.Status for the reason of the exception. public static PhysicalGPUHandle[] EnumTCCPhysicalGPUs() { var gpuList = typeof(PhysicalGPUHandle).Instantiate().Repeat(PhysicalGPUHandle.PhysicalGPUs); var status = DelegateFactory.GetDelegate()(gpuList, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpuList.Take((int) count).ToArray(); } /// /// This function returns the AGP aperture in megabytes. /// /// Physical GPU handle to get information about /// AGP aperture in megabytes /// Status.InvalidArgument: display is not valid /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static int GetAGPAperture(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var agpAperture); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) agpAperture; } /// /// [PRIVATE] /// Gets the architect information for the passed physical GPU handle. /// /// The GPU handle to retrieve information for. /// The GPU architect information. public static PrivateArchitectInfoV2 GetArchitectInfo(PhysicalGPUHandle gpuHandle) { var instance = typeof(PrivateArchitectInfoV2).Instantiate(); using (var architectInfoReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, architectInfoReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return architectInfoReference.ToValueType( typeof(PrivateArchitectInfoV2)); } } /// /// This API Retrieves the Board information (a unique GPU Board Serial Number) stored in the InfoROM. /// /// Physical GPU Handle /// Board Information /// Status.Error: Miscellaneous error occurred /// Status.ExpectedPhysicalGPUHandle: Handle passed is not a physical GPU handle /// Status.ApiNotInitialized: NVAPI not initialized public static BoardInfo GetBoardInfo(PhysicalGPUHandle gpuHandle) { var boardInfo = typeof(BoardInfo).Instantiate(); var status = DelegateFactory.GetDelegate()(gpuHandle, ref boardInfo); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return boardInfo; } /// /// Returns the identification of the bus associated with this GPU. /// /// GPU handle to get information about /// Id of the bus /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found. /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static int GetBusId(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var busId); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) busId; } /// /// Returns the identification of the bus slot associated with this GPU. /// /// GPU handle to get information about /// Identification of the bus slot associated with this GPU /// Status.InvalidArgument: gpuHandle is NULL /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle public static int GetBusSlotId(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var busId); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) busId; } /// /// This function returns the type of bus associated with this GPU. /// TCC_SUPPORTED /// /// GPU handle to get information about /// Type of bus associated with this GPU /// Status.InvalidArgument: gpuHandle is NULL public static GPUBusType GetBusType(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var busType); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return busType; } /// /// This function returns the current AGP Rate (0 = AGP not present, 1 = 1x, 2 = 2x, etc.). /// /// Physical GPU handle to get information about /// Current AGP rate /// Status.InvalidArgument: display is not valid /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static int GetCurrentAGPRate(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var agpRate); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) agpRate; } /// /// This function returns the number of PCIE lanes being used for the PCIE interface downstream from the GPU. /// /// Physical GPU handle to get information about /// PCIE lanes being used for the PCIE interface downstream /// Status.InvalidArgument: display is not valid /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static int GetCurrentPCIEDownStreamWidth(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var width); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) width; } /// /// [PRIVATE] /// Gets the driver model for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The driver model of the GPU. public static uint GetDriverModel(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return count; } /// /// This function returns ECC memory configuration information. /// /// /// handle identifying the physical GPU for which ECC configuration information is to be /// retrieved. /// /// An instance of public static ECCConfigurationInfoV1 GetECCConfigurationInfo(PhysicalGPUHandle gpuHandle) { var instance = typeof(ECCConfigurationInfoV1).Instantiate(); using (var configurationInfoReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, configurationInfoReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return configurationInfoReference.ToValueType(typeof(ECCConfigurationInfoV1)); } } /// /// This function returns ECC memory error information. /// /// A handle identifying the physical GPU for which ECC error information is to be retrieved. /// An instance of public static ECCErrorInfoV1 GetECCErrorInfo(PhysicalGPUHandle gpuHandle) { var instance = typeof(ECCErrorInfoV1).Instantiate(); using (var errorInfoReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, errorInfoReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return errorInfoReference.ToValueType(typeof(ECCErrorInfoV1)); } } /// /// This function returns ECC memory status information. /// /// A handle identifying the physical GPU for which ECC status information is to be retrieved. /// An instance of public static ECCStatusInfoV1 GetECCStatusInfo(PhysicalGPUHandle gpuHandle) { var instance = typeof(ECCStatusInfoV1).Instantiate(); using (var statusInfoReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()( gpuHandle, statusInfoReference ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return statusInfoReference.ToValueType(typeof(ECCStatusInfoV1)); } } /// /// [PRIVATE] /// Gets the GPU manufacturing foundry of the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The GPU manufacturing foundry of the GPU. public static GPUFoundry GetFoundry(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var foundry); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return foundry; } /// /// [PRIVATE] /// Gets the current frame buffer width and location for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The frame buffer width. /// The frame buffer location. public static void GetFrameBufferWidthAndLocation( PhysicalGPUHandle gpuHandle, out uint width, out uint location) { var status = DelegateFactory.GetDelegate()(gpuHandle, out width, out location); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } /// /// This function retrieves the full GPU name as an ASCII string - for example, "Quadro FX 1400". /// /// Physical GPU handle to get information about /// Full GPU name as an ASCII string /// See NVIDIAApiException.Status for the reason of the exception. public static string GetFullName(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var name); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return name.Value; } /// /// Retrieves the total number of cores defined for a GPU. /// Returns 0 on architectures that don't define GPU cores. /// /// Physical GPU handle to get information about /// Total number of cores /// Status.InvalidArgument: display is not valid /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. /// Status.NotSupported: API call is not supported on current architecture public static uint GetGPUCoreCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var cores); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return cores; } /// /// [PRIVATE] /// Gets the GPUID of the passed GPU handle. /// /// The GPU handle to get the GPUID for. /// The GPU's GPUID. public static uint GetGPUIDFromPhysicalGPU(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var gpuId); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpuId; } /// /// This function returns the GPU type (integrated or discrete). /// TCC_SUPPORTED /// /// GPU handle to get information about /// GPU type /// Status.InvalidArgument: gpuHandle is NULL /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle public static GPUType GetGPUType(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var type); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return type; } /// /// This function returns the interrupt number associated with this GPU. /// /// GPU handle to get information about /// Interrupt number associated with this GPU /// Status.InvalidArgument: gpuHandle is NULL /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle public static int GetIRQ(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var irq); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) irq; } /// /// [PRIVATE] /// Gets the current frame buffer width and location for the passed logical GPU handle. /// /// The handle of the logical GPU to perform the operation on. /// The frame buffer width. /// The frame buffer location. public static void GetLogicalFrameBufferWidthAndLocation( LogicalGPUHandle gpuHandle, out uint width, out uint location) { var status = DelegateFactory.GetDelegate()(gpuHandle, out width, out location); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } /// /// This function returns the logical GPU handle associated with specified physical GPU handle. /// At least one GPU must be present in the system and running an NVIDIA display driver. /// /// GPU handle to get information about /// Logical GPU handle associated with specified physical GPU handle /// Status.InvalidArgument: gpuHandle is NULL /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found public static LogicalGPUHandle GetLogicalGPUFromPhysicalGPU(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var gpu); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpu; } /// /// This function retrieves the available driver memory footprint for the specified GPU. /// If the GPU is in TCC Mode, only dedicatedVideoMemory will be returned. /// /// Handle of the physical GPU for which the memory information is to be extracted. /// The memory footprint available in the driver. /// This operation is not supported. /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found. /// A delegate callback throws an exception. public static IDisplayDriverMemoryInfo GetMemoryInfo(PhysicalGPUHandle physicalGPUHandle) { var getMemoryInfo = DelegateFactory.GetDelegate(); foreach (var acceptType in getMemoryInfo.Accepts()) { var instance = acceptType.Instantiate(); using (var displayDriverMemoryInfo = ValueTypeReference.FromValueType(instance, acceptType)) { var status = getMemoryInfo(physicalGPUHandle, displayDriverMemoryInfo); if (status == Status.IncompatibleStructureVersion) { continue; } if (status != Status.Ok) { throw new NVIDIAApiException(status); } return displayDriverMemoryInfo.ToValueType(acceptType); } } throw new NVIDIANotSupportedException("This operation is not supported."); } /// /// [PRIVATE] /// Gets the number of GPC (Graphic Processing Clusters) of the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// The number of GPC units for the GPU. public static uint GetPartitionCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return count; } /// /// [PRIVATE] /// Gets additional information about the PCIe interface and configuration for the passed GPU handle. /// /// The handle of the GPU to perform the operation on. /// PCIe information and configurations. public static PrivatePCIeInfoV2 GetPCIEInfo(PhysicalGPUHandle gpuHandle) { var instance = typeof(PrivatePCIeInfoV2).Instantiate(); using (var pcieInfoReference = ValueTypeReference.FromValueType(instance)) { var status = DelegateFactory.GetDelegate()(gpuHandle, pcieInfoReference); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return pcieInfoReference.ToValueType(typeof(PrivatePCIeInfoV2)); } } /// /// This function returns the PCI identifiers associated with this GPU. /// TCC_SUPPORTED /// /// GPU handle to get information about /// The internal PCI device identifier for the GPU. /// The internal PCI subsystem identifier for the GPU. /// The internal PCI device-specific revision identifier for the GPU. /// The external PCI device identifier for the GPU. /// Status.InvalidArgument: gpuHandle or an argument is NULL /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle // ReSharper disable once TooManyArguments public static void GetPCIIdentifiers( PhysicalGPUHandle gpuHandle, out uint deviceId, out uint subSystemId, out uint revisionId, out uint extDeviceId) { var status = DelegateFactory.GetDelegate()(gpuHandle, out deviceId, out subSystemId, out revisionId, out extDeviceId); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } /// /// This function returns the physical size of frame buffer in KB. This does NOT include any system RAM that may be /// dedicated for use by the GPU. /// TCC_SUPPORTED /// /// GPU handle to get information about /// Physical size of frame buffer in KB /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle public static int GetPhysicalFrameBufferSize(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var size); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) size; } /// /// [PRIVATE] /// Gets a physical GPU handle from the passed GPUID /// /// The GPUID to get the physical handle for. /// The retrieved physical GPU handle. public static PhysicalGPUHandle GetPhysicalGPUFromGPUID(uint gpuId) { var status = DelegateFactory.GetDelegate()(gpuId, out var gpuHandle); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpuHandle; } /// /// This function returns the physical GPU handles associated with the specified logical GPU handle. /// At least one GPU must be present in the system and running an NVIDIA display driver. /// /// Logical GPU handle to get information about /// An array of physical GPU handles /// Status.InvalidArgument: gpuHandle is not valid /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedLogicalGPUHandle: gpuHandle was not a logical GPU handle public static PhysicalGPUHandle[] GetPhysicalGPUsFromLogicalGPU(LogicalGPUHandle gpuHandle) { var gpuList = typeof(PhysicalGPUHandle).Instantiate().Repeat(PhysicalGPUHandle.MaxPhysicalGPUs); var status = DelegateFactory.GetDelegate()(gpuHandle, gpuList, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return gpuList.Take((int) count).ToArray(); } /// /// This function retrieves the Quadro status for the GPU (true if Quadro, false if GeForce) /// /// GPU handle to get information about /// true if Quadro, false if GeForce /// Status.Error: Miscellaneous error occurred public static bool GetQuadroStatus(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var isQuadro); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return isQuadro > 0; } /// /// [PRIVATE] /// Gets the number of RAM banks for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The number of RAM memory banks. public static uint GetRAMBankCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var bankCount); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return bankCount; } /// /// [PRIVATE] /// Gets the RAM bus width for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The RAM memory bus width. public static uint GetRAMBusWidth(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var busWidth); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return busWidth; } /// /// [PRIVATE] /// Gets the RAM maker for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The RAM memory maker. public static GPUMemoryMaker GetRAMMaker(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var ramMaker); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return ramMaker; } /// /// [PRIVATE] /// Gets the RAM type for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The RAM memory type. public static GPUMemoryType GetRAMType(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var ramType); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return ramType; } /// /// [PRIVATE] /// Gets the ROP count for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The number of ROP units. public static uint GetROPCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var ropCount); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return ropCount; } /// /// [PRIVATE] /// Gets the number of shader pipe lines for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The number of shader pipelines. public static uint GetShaderPipeCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var spCount); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return spCount; } /// /// This function retrieves the number of Shader SubPipes on the GPU /// On newer architectures, this corresponds to the number of SM units /// /// GPU handle to get information about /// Number of Shader SubPipes on the GPU /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle public static uint GetShaderSubPipeCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var count); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return count; } /// /// [PRIVATE] /// Gets the GPU short name (code name) for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The GPU short name. public static string GetShortName(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var name); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return name.Value; } /// /// This function identifies whether the GPU is a notebook GPU or a desktop GPU. /// /// GPU handle to get information about /// GPU system type /// Status.InvalidArgument: gpuHandle is NULL /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle public static SystemType GetSystemType(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var systemType); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return systemType; } /// /// [PRIVATE] /// Gets the SM count for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The number of SM units. public static uint GetTotalSMCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var smCount); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return smCount; } /// /// [PRIVATE] /// Gets the SP count for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The number of SP units. public static uint GetTotalSPCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var spCount); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return spCount; } /// /// [PRIVATE] /// Gets the TPC count for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The number of TPC units. public static uint GetTotalTPCCount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var tpcCount); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return tpcCount; } /// /// This function returns the OEM revision of the video BIOS associated with this GPU. /// /// GPU handle to get information about /// OEM revision of the video BIOS /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found. /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static uint GetVBIOSOEMRevision(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var revision); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return revision; } /// /// This function returns the revision of the video BIOS associated with this GPU. /// TCC_SUPPORTED /// /// GPU handle to get information about /// Revision of the video BIOS /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found. /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static uint GetVBIOSRevision(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var revision); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return revision; } /// /// This function returns the full video BIOS version string in the form of xx.xx.xx.xx.yy where xx numbers come from /// GetVbiosRevision() and yy comes from GetVbiosOEMRevision(). /// /// Physical GPU handle to get information about /// Full video BIOS version string /// Status.InvalidArgument: display is not valid /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static string GetVBIOSVersionString(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var version); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return version.Value; } /// /// This function returns the virtual size of frame buffer in KB. This includes the physical RAM plus any system RAM /// that has been dedicated for use by the GPU. /// /// Physical GPU handle to get information about /// Virtual size of frame buffer in KB /// Status.InvalidArgument: display is not valid /// Status.NvidiaDeviceNotFound: No NVIDIA GPU driving a display was found /// Status.ExpectedPhysicalGPUHandle: gpuHandle was not a physical GPU handle. public static int GetVirtualFrameBufferSize(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var bufferSize); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return (int) bufferSize; } /// /// [PRIVATE] /// Gets the VPE count for the passed GPU handle. /// /// The handle of the GPU to retrieve this information from. /// The number of VPE units. public static uint GetVPECount(PhysicalGPUHandle gpuHandle) { var status = DelegateFactory.GetDelegate()(gpuHandle, out var vpeCount); if (status != Status.Ok) { throw new NVIDIAApiException(status); } return vpeCount; } /// /// Reads data from I2C bus /// /// The physical GPU to access I2C bus. /// The information required for the operation. Will be filled with data after retrieval. // ReSharper disable once InconsistentNaming public static void I2CRead(PhysicalGPUHandle gpuHandle, ref TI2CInfo i2cInfo) where TI2CInfo : struct, II2CInfo { var c = i2cInfo as II2CInfo; I2CRead(gpuHandle, ref c); i2cInfo = (TI2CInfo) c; } /// /// Reads data from I2C bus /// /// The physical GPU to access I2C bus. /// The information required for the operation. Will be filled with data after retrieval. // ReSharper disable once InconsistentNaming public static void I2CRead(PhysicalGPUHandle gpuHandle, ref II2CInfo i2cInfo) { var type = i2cInfo.GetType(); // ReSharper disable once InconsistentNaming var i2cRead = DelegateFactory.GetDelegate(); if (!i2cRead.Accepts().Contains(type)) { throw new ArgumentOutOfRangeException(nameof(type)); } // ReSharper disable once InconsistentNaming using (var i2cInfoReference = ValueTypeReference.FromValueType(i2cInfo, type)) { var status = i2cRead(gpuHandle, i2cInfoReference); if (status != Status.Ok) { throw new NVIDIAApiException(status); } i2cInfo = i2cInfoReference.ToValueType(type); } } /// /// Writes data to I2C bus /// /// The physical GPU to access I2C bus. /// The information required for the operation. // ReSharper disable once InconsistentNaming public static void I2CWrite(PhysicalGPUHandle gpuHandle, II2CInfo i2cInfo) { var type = i2cInfo.GetType(); // ReSharper disable once InconsistentNaming var i2cWrite = DelegateFactory.GetDelegate(); if (!i2cWrite.Accepts().Contains(type)) { throw new ArgumentOutOfRangeException(nameof(type)); } // ReSharper disable once InconsistentNaming using (var i2cInfoReference = ValueTypeReference.FromValueType(i2cInfo, type)) { var status = i2cWrite(gpuHandle, i2cInfoReference); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } } /// /// This function resets ECC memory error counters. /// /// A handle identifying the physical GPU for which ECC error information is to be cleared. /// Reset the current ECC error counters. /// Reset the aggregate ECC error counters. public static void ResetECCErrorInfo( PhysicalGPUHandle gpuHandle, bool resetCurrent, bool resetAggregated) { var status = DelegateFactory.GetDelegate()( gpuHandle, (byte) (resetCurrent ? 1 : 0), (byte) (resetAggregated ? 1 : 0) ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } /// /// This function updates the ECC memory configuration setting. /// /// A handle identifying the physical GPU for which to update the ECC configuration setting. /// The new ECC configuration setting. /// Request that the new setting take effect immediately. public static void SetECCConfiguration( PhysicalGPUHandle gpuHandle, bool isEnable, bool isEnableImmediately) { var status = DelegateFactory.GetDelegate()( gpuHandle, (byte) (isEnable ? 1 : 0), (byte) (isEnableImmediately ? 1 : 0) ); if (status != Status.Ok) { throw new NVIDIAApiException(status); } } } }