예제 #1
0
        public static bool Initialize()
        {
            if (_nvApiInitialize != null)
            {
                return(true);
            }

            var attribute = new DllImportAttribute(DllName)
            {
                CallingConvention = CallingConvention.Cdecl,
                PreserveSig       = true,
                EntryPoint        = "nvapi_QueryInterface"
            };

            Native.CreatePInvokeDelegate(attribute, out _nvApiQueryInterface);

            try {
                GetDelegate((uint)FunctionId.NvAPI_Initialize, out _nvApiInitialize);

                _initStatus = _nvApiInitialize();
                if (_initStatus == NvStatus.Ok)
                {
                    SetupDelegates();
                }
                return(true);
            } catch (DllNotFoundException e) {
                ModuleGpuNvidia.Logger.Error($"Could not found nvapi dll '{DllName}'", e);
            } catch (EntryPointNotFoundException e) {
                ModuleGpuNvidia.Logger.Error($"Could not found entry point in '{DllName}'", e);
            } catch (ArgumentNullException e) {
                ModuleGpuNvidia.Logger.Error($"Could not query pointer to NvAPI_Initialize in '{DllName}'", e);
            }

            return(false);
        }
예제 #2
0
        // GetStatus() -> (unknown<0x20>, u32 error_code)
        public ResultCode GetStatus(ServiceCtx context)
        {
            // TODO: When transfer memory will be implemented, check if it's mapped instead.
            if (_transferMemInitialized)
            {
                // TODO: Populate values when more RE will be done.
                NvStatus nvStatus = new NvStatus
                {
                    MemoryValue1 = 0, // GetMemStats(transfer_memory + 0x60, 3)
                    MemoryValue2 = 0, // GetMemStats(transfer_memory + 0x60, 5)
                    MemoryValue3 = 0, // transfer_memory + 0x78
                    MemoryValue4 = 0  // transfer_memory + 0x80
                };

                context.ResponseData.WriteStruct(nvStatus);
                context.ResponseData.Write((uint)NvResult.Success);

                Logger.Stub?.PrintStub(LogClass.ServiceNv);
            }
            else
            {
                context.ResponseData.Write((uint)NvResult.NotInitialized);
            }

            return(ResultCode.Success);
        }
예제 #3
0
        public static NvStatus NvAPI_GetInterfaceVersionString(out string version)
        {
            StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);
            NvStatus      status  = _nvAPI_GetInterfaceVersionString?.Invoke(builder) ?? NvStatus.FUNCTION_NOT_FOUND;

            version = builder.ToString();
            return(status);
        }
예제 #4
0
        public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle, out string name)
        {
            StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);
            NvStatus      status  = _nvAPI_GPU_GetFullName?.Invoke(gpuHandle, builder) ?? NvStatus.FUNCTION_NOT_FOUND;

            name = builder.ToString();
            return(status);
        }
예제 #5
0
        public static NvStatus NvAPI_GetInterfaceVersionString(out string version)
        {
            StringBuilder builder = new(SHORT_STRING_MAX);
            NvStatus      status  = _nvAPI_GetInterfaceVersionString?.Invoke(builder) ?? NvStatus.FunctionNotFound;

            version = builder.ToString();
            return(status);
        }
예제 #6
0
        public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle, out string name)
        {
            StringBuilder builder = new(SHORT_STRING_MAX);
            NvStatus      status  = _nvAPI_GPU_GetFullName?.Invoke(gpuHandle, builder) ?? NvStatus.FunctionNotFound;

            name = builder.ToString();
            return(status);
        }
예제 #7
0
파일: NVAPI.cs 프로젝트: KratosFu/TempServe
        public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle,
                                                     out string name)
        {
            StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);
            NvStatus      status  = _NvAPI_GPU_GetFullName(gpuHandle, builder);

            name = builder.ToString();
            return(status);
        }
예제 #8
0
        //Init Nvidia GPU param
        public GPUParam(NvPhysicalGpuHandle hdl, NvDisplayHandle displ, int num)
        {
            handle        = hdl;
            displayHandle = displ;

            type = GPUType.nvi;
            //GPU name
            string tmp;

            if (NVAPI.NvAPI_GPU_GetFullName(handle, out tmp) == NvStatus.OK)
            {
                GPUName = "NVIDIA " + tmp.Trim();
            }
            else
            {
                GPUName = "NVIDIA GPU name not found";
            }
            //Slot
            if (NVAPI.NvAPI_GPU_GetBusId != null)
            {
                uint busId = 0;
                if (NVAPI.NvAPI_GPU_GetBusId(handle, out busId) == NvStatus.OK)
                {
                    Slot = (int)busId;
                }
                else
                {
                    Slot = -1;
                }
            }
            //Subsys
            if (NVAPI.NvAPI_GPU_GetPCIIdentifiers != null)
            {
                uint     deviceId, subSystemId, revisionId, extDeviceId;
                NvStatus status = NVAPI.NvAPI_GPU_GetPCIIdentifiers(handle, out deviceId, out subSystemId, out revisionId, out extDeviceId);
                if (status == NvStatus.OK)
                {
                    Subsys = subSystemId.ToString("X", CultureInfo.InvariantCulture);
                    if (Subsys.Length < 8)
                    {
                        Subsys = "0" + Subsys;
                    }
                }
            }
            //Param GPU
            GPUParams = new List <OneParam>();
            for (int i = 0; i != num; i++)
            {
                GPUParams.Insert(i, new OneParam());
            }
        }
        public NvidiaModelAccessor()
        {
            //This constructor itterates through each of GPU's and generates a NvidiaGpuModel Object for each of them appending.
            int count;
            IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles = new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>();

            NvPhysicalGpuHandle[] handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];

            NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count);

            for (int i = 0; i < count; i++)
            {
                NvDisplayHandle displayHandle;
                displayHandles.TryGetValue(handles[i], out displayHandle);
                _gpuList.Add(new NvidiaGpuModel(i, handles[i], displayHandle));
            }
        }
예제 #10
0
        public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handl, NvDisplayHandle displayHandle)
        {
            this.adapterIndex  = adapterIndex;
            this.handle        = handl;
            this.displayHandle = displayHandle;

            gpustat         = new NviGPUStat();
            gpucurr         = new NviGPUInfoNum();
            gpuinfo         = new NviGPUInfo();
            gpuinfo.GPUName = GetName();

            if (NVAPI.NvAPI_GPU_GetBusId != null)
            {
                uint     busId  = 0;
                NvStatus status = NVAPI.NvAPI_GPU_GetBusId(handle, out busId);
                if (status == NvStatus.OK)
                {
                    gpuinfo.Slot = (int)busId;
                }
            }
            if (NVAPI.NvAPI_GPU_GetPCIIdentifiers != null)
            {
                uint     deviceId, subSystemId, revisionId, extDeviceId;
                NvStatus status = NVAPI.NvAPI_GPU_GetPCIIdentifiers(handle, out deviceId, out subSystemId, out revisionId, out extDeviceId);
                if (status == NvStatus.OK)
                {
                    gpuinfo.Subsys = subSystemId.ToString("X", CultureInfo.InvariantCulture);
                    if (gpuinfo.Subsys.Length < 8)
                    {
                        gpuinfo.Subsys = "0" + gpuinfo.Subsys;
                    }
                }
            }
            //Переменная задает время сбора статистики, при цикле 1 сек статистика будет формироваться за последние 5 минут.
            statcount = 60;
            Update();
        }
예제 #11
0
        public GpuSensor()
        {
            if (!NVAPI.IsAvailable)
            {
                throw new Exception("Unable to obtain primary GPU; NVAPI is not available");
            }

            NvPhysicalGpuHandle[] handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];

            int numGpus;

            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
            {
                throw new Exception("Unable to obtain primary GPU; NvAPI_EnumPhysicalGPUs not available");
            }
            else
            {
                NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out numGpus);
                if (status != NvStatus.OK)
                {
                    throw new Exception("Unable to obtain primary GPU");
                }
            }

            if (numGpus < 1)
            {
                throw new Exception("Unable to obtain primary GPU");
            }

            gpuHandle = handles[0];

            IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles = new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>();

            if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null && NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null)
            {
                int      i      = 0;
                NvStatus status = NvStatus.OK;
                while (status == NvStatus.OK)
                {
                    NvDisplayHandle displayHandle = new NvDisplayHandle();
                    status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle);
                    i++;

                    if (status == NvStatus.OK)
                    {
                        NvPhysicalGpuHandle[] handlesFromDisplay = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
                        if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle, handlesFromDisplay, out uint countFromDisplay) == NvStatus.OK)
                        {
                            for (int j = 0; j < countFromDisplay; j++)
                            {
                                if (!displayHandles.ContainsKey(handlesFromDisplay[j]))
                                {
                                    displayHandles.Add(handlesFromDisplay[j], displayHandle);
                                }
                            }
                        }
                    }
                }
            }

            displayHandles.TryGetValue(handles[0], out displayHandle);
        }
예제 #12
0
        public override string GetReport()
        {
            StringBuilder r = new StringBuilder();

            r.AppendLine("Nvidia GPU");
            r.AppendLine();

            r.AppendFormat("Name: {0}{1}", name, Environment.NewLine);
            r.AppendFormat("Index: {0}{1}", adapterIndex, Environment.NewLine);

            if (displayHandle.HasValue && NVAPI.NvAPI_GetDisplayDriverVersion != null)
            {
                NvDisplayDriverVersion driverVersion = new NvDisplayDriverVersion();
                driverVersion.Version = NVAPI.DISPLAY_DRIVER_VERSION_VER;
                if (NVAPI.NvAPI_GetDisplayDriverVersion(displayHandle.Value,
                                                        ref driverVersion) == NvStatus.OK)
                {
                    r.Append("Driver Version: ");
                    r.Append(driverVersion.DriverVersion / 100);
                    r.Append(".");
                    r.Append((driverVersion.DriverVersion % 100).ToString("00",
                                                                          CultureInfo.InvariantCulture));
                    r.AppendLine();
                    r.Append("Driver Branch: ");
                    r.AppendLine(driverVersion.BuildBranch);
                }
            }
            r.AppendLine();

            if (NVAPI.NvAPI_GPU_GetThermalSettings != null)
            {
                NvGPUThermalSettings settings = new NvGPUThermalSettings();
                settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
                settings.Count   = NVAPI.MAX_THERMAL_SENSORS_PER_GPU;
                settings.Sensor  = new NvSensor[NVAPI.MAX_THERMAL_SENSORS_PER_GPU];

                NvStatus status = NVAPI.NvAPI_GPU_GetThermalSettings(handle,
                                                                     (int)NvThermalTarget.ALL, ref settings);

                r.AppendLine("Thermal Settings");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < settings.Count; i++)
                    {
                        r.AppendFormat(" Sensor[{0}].Controller: {1}{2}", i,
                                       settings.Sensor[i].Controller, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].DefaultMinTemp: {1}{2}", i,
                                       settings.Sensor[i].DefaultMinTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].DefaultMaxTemp: {1}{2}", i,
                                       settings.Sensor[i].DefaultMaxTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].CurrentTemp: {1}{2}", i,
                                       settings.Sensor[i].CurrentTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].Target: {1}{2}", i,
                                       settings.Sensor[i].Target, Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetAllClocks != null)
            {
                NvClocks allClocks = new NvClocks();
                allClocks.Version = NVAPI.GPU_CLOCKS_VER;
                allClocks.Clock   = new uint[NVAPI.MAX_CLOCKS_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetAllClocks(handle, ref allClocks);

                r.AppendLine("Clocks");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < allClocks.Clock.Length; i++)
                    {
                        if (allClocks.Clock[i] > 0)
                        {
                            r.AppendFormat(" Clock[{0}]: {1}{2}", i, allClocks.Clock[i],
                                           Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetTachReading != null)
            {
                int      tachValue;
                NvStatus status = NVAPI.NvAPI_GPU_GetTachReading(handle, out tachValue);

                r.AppendLine("Tachometer");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    r.AppendFormat(" Value: {0}{1}", tachValue, Environment.NewLine);
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetPStates != null)
            {
                NvPStates states = new NvPStates();
                states.Version = NVAPI.GPU_PSTATES_VER;
                states.PStates = new NvPState[NVAPI.MAX_PSTATES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetPStates(handle, ref states);

                r.AppendLine("P-States");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < states.PStates.Length; i++)
                    {
                        if (states.PStates[i].Present)
                        {
                            r.AppendFormat(" Percentage[{0}]: {1}{2}", i,
                                           states.PStates[i].Percentage, Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetUsages != null)
            {
                NvUsages usages = new NvUsages();
                usages.Version = NVAPI.GPU_USAGES_VER;
                usages.Usage   = new uint[NVAPI.MAX_USAGES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetUsages(handle, ref usages);

                r.AppendLine("Usages");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < usages.Usage.Length; i++)
                    {
                        if (usages.Usage[i] > 0)
                        {
                            r.AppendFormat(" Usage[{0}]: {1}{2}", i,
                                           usages.Usage[i], Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetCoolerSettings != null)
            {
                NvGPUCoolerSettings settings = new NvGPUCoolerSettings();
                settings.Version = NVAPI.GPU_COOLER_SETTINGS_VER;
                settings.Cooler  = new NvCooler[NVAPI.MAX_COOLER_PER_GPU];
                NvStatus status =
                    NVAPI.NvAPI_GPU_GetCoolerSettings(handle, 0, ref settings);

                r.AppendLine("Cooler Settings");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < settings.Count; i++)
                    {
                        r.AppendFormat(" Cooler[{0}].Type: {1}{2}", i,
                                       settings.Cooler[i].Type, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Controller: {1}{2}", i,
                                       settings.Cooler[i].Controller, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultMin: {1}{2}", i,
                                       settings.Cooler[i].DefaultMin, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultMax: {1}{2}", i,
                                       settings.Cooler[i].DefaultMax, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentMin: {1}{2}", i,
                                       settings.Cooler[i].CurrentMin, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentMax: {1}{2}", i,
                                       settings.Cooler[i].CurrentMax, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentLevel: {1}{2}", i,
                                       settings.Cooler[i].CurrentLevel, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultPolicy: {1}{2}", i,
                                       settings.Cooler[i].DefaultPolicy, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentPolicy: {1}{2}", i,
                                       settings.Cooler[i].CurrentPolicy, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Target: {1}{2}", i,
                                       settings.Cooler[i].Target, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].ControlType: {1}{2}", i,
                                       settings.Cooler[i].ControlType, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Active: {1}{2}", i,
                                       settings.Cooler[i].Active, Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetMemoryInfo != null && displayHandle.HasValue)
            {
                NvMemoryInfo memoryInfo = new NvMemoryInfo();
                memoryInfo.Version = NVAPI.GPU_MEMORY_INFO_VER;
                memoryInfo.Values  = new uint[NVAPI.MAX_MEMORY_VALUES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetMemoryInfo(displayHandle.Value,
                                                                ref memoryInfo);

                r.AppendLine("Memory Info");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < memoryInfo.Values.Length; i++)
                    {
                        r.AppendFormat(" Value[{0}]: {1}{2}", i,
                                       memoryInfo.Values[i], Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            return(r.ToString());
        }
예제 #13
0
        public NvidiaGroup(ref List <GPUParam> gpupar, int numpar)
        {
            if (!NVAPI.IsAvailable)
            {
                return;
            }
            report.AppendLine("NVAPI");
            report.AppendLine();
            string version;

            if (NVAPI.NvAPI_GetInterfaceVersionString(out version) == NvStatus.OK)
            {
                report.Append("Version: ");
                report.AppendLine(version);
            }
            NvPhysicalGpuHandle[] handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
            int count;

            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
            {
                report.AppendLine("Error: NvAPI_EnumPhysicalGPUs not available");
                report.AppendLine();
                return;
            }
            else
            {
                NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count);
                if (status != NvStatus.OK)
                {
                    report.AppendLine("Status: " + status);
                    report.AppendLine();
                    return;
                }
            }
            IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles = new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>();

            if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null && NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null)
            {
                NvStatus status = NvStatus.OK;
                int      i      = 0;
                while (status == NvStatus.OK)
                {
                    NvDisplayHandle displayHandle = new NvDisplayHandle();
                    status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle);
                    i++;
                    if (status == NvStatus.OK)
                    {
                        NvPhysicalGpuHandle[] handlesFromDisplay = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
                        uint countFromDisplay;
                        if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle, handlesFromDisplay, out countFromDisplay) == NvStatus.OK)
                        {
                            for (int j = 0; j < countFromDisplay; j++)
                            {
                                if (!displayHandles.ContainsKey(handlesFromDisplay[j]))
                                {
                                    displayHandles.Add(handlesFromDisplay[j], displayHandle);
                                }
                            }
                        }
                    }
                }
            }
            report.Append("Number of GPUs: ");
            report.AppendLine(count.ToString(CultureInfo.InvariantCulture));
            for (int i = 0; i < count; i++)
            {
                NvDisplayHandle displayHandle;
                displayHandles.TryGetValue(handles[i], out displayHandle);
                //ДОбавляем карту в коллекцию
                gpupar.Add(new GPUParam(handles[i], displayHandle, numpar));
                //Добавляем информацию о карте в отчет
                report.AppendLine(GetReportCard(i, handles[i], displayHandle));
            }
            report.AppendLine();
        }
예제 #14
0
 public NvapiException(string message, NvStatus returnCode)
 {
     _messagePart = message;
     ReturnCode   = returnCode;
 }
예제 #15
0
        public NvidiaGroup(ISettings settings)
        {
            if (!NVAPI.IsAvailable)
            {
                return;
            }

            report.AppendLine("NVAPI");
            report.AppendLine();

            string version;

            if (NVAPI.NvAPI_GetInterfaceVersionString(out version) == NvStatus.OK)
            {
                report.Append("Version: ");
                report.AppendLine(version);
            }

            NvPhysicalGpuHandle[] handles =
                new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
            int count;

            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
            {
                report.AppendLine("Error: NvAPI_EnumPhysicalGPUs not available");
                report.AppendLine();
                return;
            }
            else
            {
                NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count);
                if (status != NvStatus.OK)
                {
                    report.AppendLine("Status: " + status);
                    report.AppendLine();
                    return;
                }
            }

            IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles =
                new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>();

            if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null &&
                NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null)
            {
                NvStatus status = NvStatus.OK;
                int      i      = 0;
                while (status == NvStatus.OK)
                {
                    NvDisplayHandle displayHandle = new NvDisplayHandle();
                    status = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle);
                    i++;

                    if (status == NvStatus.OK)
                    {
                        NvPhysicalGpuHandle[] handlesFromDisplay =
                            new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
                        uint countFromDisplay;
                        if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle,
                                                                   handlesFromDisplay, out countFromDisplay) == NvStatus.OK)
                        {
                            for (int j = 0; j < countFromDisplay; j++)
                            {
                                if (!displayHandles.ContainsKey(handlesFromDisplay[j]))
                                {
                                    displayHandles.Add(handlesFromDisplay[j], displayHandle);
                                }
                            }
                        }
                    }
                }
            }

            report.Append("Number of GPUs: ");
            report.AppendLine(count.ToString(CultureInfo.InvariantCulture));

            for (int i = 0; i < count; i++)
            {
                NvDisplayHandle displayHandle;
                displayHandles.TryGetValue(handles[i], out displayHandle);
                hardware.Add(new NvidiaGPU(i, handles[i], displayHandle, settings));
            }

            report.AppendLine();
        }
예제 #16
0
        public override string GetReport()
        {
            NVidiaGpu nVidiaGpu = new NVidiaGpu();

            nVidiaGpu.Name = name;

            if (displayHandle.HasValue && NVAPI.NvAPI_GetDisplayDriverVersion != null)
            {
                NvDisplayDriverVersion driverVersion = new NvDisplayDriverVersion();
                driverVersion.Version = NVAPI.DISPLAY_DRIVER_VERSION_VER;
                if (NVAPI.NvAPI_GetDisplayDriverVersion(displayHandle.Value,
                                                        ref driverVersion) == NvStatus.OK)
                {
                    nVidiaGpu.DriverVersion = (driverVersion.DriverVersion / 100).ToString() + "." + (driverVersion.DriverVersion % 100).ToString("00", CultureInfo.InvariantCulture);
                    nVidiaGpu.DriverBranch  = driverVersion.BuildBranch;
                }
            }
            if (NVAPI.NvAPI_GPU_GetPCIIdentifiers != null)
            {
                uint deviceId, subSystemId, revisionId, extDeviceId;

                NvStatus status = NVAPI.NvAPI_GPU_GetPCIIdentifiers(handle,
                                                                    out deviceId, out subSystemId, out revisionId, out extDeviceId);

                if (status == NvStatus.OK)
                {
                    nVidiaGpu.DeviceID   = deviceId.ToString("X", CultureInfo.InvariantCulture);
                    nVidiaGpu.RevisionID = revisionId.ToString("X", CultureInfo.InvariantCulture);
                }
            }

            if (NVAPI.NvAPI_GPU_GetThermalSettings != null)
            {
                NvGPUThermalSettings settings = new NvGPUThermalSettings();
                settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
                settings.Count   = NVAPI.MAX_THERMAL_SENSORS_PER_GPU;
                settings.Sensor  = new NvSensor[NVAPI.MAX_THERMAL_SENSORS_PER_GPU];

                NvStatus status = NVAPI.NvAPI_GPU_GetThermalSettings(handle,
                                                                     (int)NvThermalTarget.ALL, ref settings);


                if (status == NvStatus.OK)
                {
                    nVidiaGpu.CurrentTemp = (long)settings.Sensor[0].CurrentTemp;
                }
            }
            else
            {
                nVidiaGpu.CurrentTemp = 0;
            }

            if (NVAPI.NvAPI_GetDisplayDriverMemoryInfo != null &&
                displayHandle.HasValue)
            {
                NvDisplayDriverMemoryInfo memoryInfo = new NvDisplayDriverMemoryInfo();
                memoryInfo.Version = NVAPI.DISPLAY_DRIVER_MEMORY_INFO_VER;
                memoryInfo.Values  = new uint[NVAPI.MAX_MEMORY_VALUES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GetDisplayDriverMemoryInfo(
                    displayHandle.Value, ref memoryInfo);


                if (status == NvStatus.OK)
                {
                    nVidiaGpu.TotalMemory     = memoryInfo.Values[0];
                    nVidiaGpu.AvailableMemory = memoryInfo.Values[1];
                }
                else
                {
                    nVidiaGpu.TotalMemory     = 21;
                    nVidiaGpu.AvailableMemory = 37;
                }
            }
            return(JsonSerializer.Serialize(nVidiaGpu));
        }
예제 #17
0
        public override string GetReport()
        {
            StringBuilder r = new StringBuilder();

            r.AppendLine("Nvidia GPU");
            r.AppendLine();

            r.AppendFormat("Name: {0}{1}", name, Environment.NewLine);
            r.AppendFormat("Index: {0}{1}", adapterIndex, Environment.NewLine);

            if (displayHandle.HasValue && NVAPI.NvAPI_GetDisplayDriverVersion != null)
            {
                NvDisplayDriverVersion driverVersion = new NvDisplayDriverVersion();
                driverVersion.Version = NVAPI.DISPLAY_DRIVER_VERSION_VER;
                if (NVAPI.NvAPI_GetDisplayDriverVersion(displayHandle.Value,
                                                        ref driverVersion) == NvStatus.OK)
                {
                    r.Append("Driver Version: ");
                    r.Append(driverVersion.DriverVersion / 100);
                    r.Append(".");
                    r.Append((driverVersion.DriverVersion % 100).ToString("00",
                                                                          CultureInfo.InvariantCulture));
                    r.AppendLine();
                    r.Append("Driver Branch: ");
                    r.AppendLine(driverVersion.BuildBranch);
                }
            }
            r.AppendLine();

            if (NVAPI.NvAPI_GPU_GetPCIIdentifiers != null)
            {
                uint deviceId, subSystemId, revisionId, extDeviceId;

                NvStatus status = NVAPI.NvAPI_GPU_GetPCIIdentifiers(handle,
                                                                    out deviceId, out subSystemId, out revisionId, out extDeviceId);

                if (status == NvStatus.OK)
                {
                    r.Append("DeviceID: 0x");
                    r.AppendLine(deviceId.ToString("X", CultureInfo.InvariantCulture));
                    r.Append("SubSystemID: 0x");
                    r.AppendLine(subSystemId.ToString("X", CultureInfo.InvariantCulture));
                    r.Append("RevisionID: 0x");
                    r.AppendLine(revisionId.ToString("X", CultureInfo.InvariantCulture));
                    r.Append("ExtDeviceID: 0x");
                    r.AppendLine(extDeviceId.ToString("X", CultureInfo.InvariantCulture));
                    r.AppendLine();
                }
            }

            if (NVAPI.NvAPI_GPU_GetThermalSettings != null)
            {
                NvGPUThermalSettings settings = new NvGPUThermalSettings();
                settings.Version = NVAPI.GPU_THERMAL_SETTINGS_VER;
                settings.Count   = NVAPI.MAX_THERMAL_SENSORS_PER_GPU;
                settings.Sensor  = new NvSensor[NVAPI.MAX_THERMAL_SENSORS_PER_GPU];

                NvStatus status = NVAPI.NvAPI_GPU_GetThermalSettings(handle,
                                                                     (int)NvThermalTarget.ALL, ref settings);

                r.AppendLine("Thermal Settings");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < settings.Count; i++)
                    {
                        r.AppendFormat(" Sensor[{0}].Controller: {1}{2}", i,
                                       settings.Sensor[i].Controller, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].DefaultMinTemp: {1}{2}", i,
                                       settings.Sensor[i].DefaultMinTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].DefaultMaxTemp: {1}{2}", i,
                                       settings.Sensor[i].DefaultMaxTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].CurrentTemp: {1}{2}", i,
                                       settings.Sensor[i].CurrentTemp, Environment.NewLine);
                        r.AppendFormat(" Sensor[{0}].Target: {1}{2}", i,
                                       settings.Sensor[i].Target, Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetAllClocks != null)
            {
                NvClocks allClocks = new NvClocks();
                allClocks.Version = NVAPI.GPU_CLOCKS_VER;
                allClocks.Clock   = new uint[NVAPI.MAX_CLOCKS_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GPU_GetAllClocks(handle, ref allClocks);

                r.AppendLine("Clocks");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < allClocks.Clock.Length; i++)
                    {
                        if (allClocks.Clock[i] > 0)
                        {
                            r.AppendFormat(" Clock[{0}]: {1}{2}", i, allClocks.Clock[i],
                                           Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetTachReading != null)
            {
                int      tachValue;
                NvStatus status = NVAPI.NvAPI_GPU_GetTachReading(handle, out tachValue);

                r.AppendLine("Tachometer");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    r.AppendFormat(" Value: {0}{1}", tachValue, Environment.NewLine);
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetDynamicPstatesInfoEx != null)
            {
                var info = new NvDynamicPstatesInfoEx();
                info.Version            = NVAPI.GPU_DYNAMIC_PSTATES_INFO_EX_VER;
                info.UtilizationDomains =
                    new NvUtilizationDomainEx[NVAPI.NVAPI_MAX_GPU_UTILIZATIONS];
                var status = NVAPI.NvAPI_GPU_GetDynamicPstatesInfoEx(handle, ref info);

                r.AppendLine("Utilization Domains Ex");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < info.UtilizationDomains.Length; i++)
                    {
                        if (info.UtilizationDomains[i].Present)
                        {
                            r.AppendFormat(" Percentage[{0}]: {1}{2}", i,
                                           info.UtilizationDomains[i].Percentage, Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetDynamicPstatesInfo != null)
            {
                var info = new NvDynamicPstatesInfo();
                info.Version            = NVAPI.GPU_DYNAMIC_PSTATES_INFO_VER;
                info.UtilizationDomains =
                    new NvUtilizationDomain[NVAPI.NVAPI_MAX_GPU_UTILIZATIONS];
                var status = NVAPI.NvAPI_GPU_GetDynamicPstatesInfo(handle, ref info);

                r.AppendLine("Utilization Domains");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < info.UtilizationDomains.Length; i++)
                    {
                        if (info.UtilizationDomains[i].Present)
                        {
                            r.AppendFormat(" Percentage[{0}]: {1}{2}", i,
                                           info.UtilizationDomains[i].Percentage, Environment.NewLine);
                        }
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_GetCoolerSettings != null)
            {
                NvGPUCoolerSettings settings = new NvGPUCoolerSettings();
                settings.Version = NVAPI.GPU_COOLER_SETTINGS_VER;
                settings.Cooler  = new NvCooler[NVAPI.MAX_COOLER_PER_GPU];
                NvStatus status =
                    NVAPI.NvAPI_GPU_GetCoolerSettings(handle, 0, ref settings);

                r.AppendLine("Cooler Settings");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < settings.Count; i++)
                    {
                        r.AppendFormat(" Cooler[{0}].Type: {1}{2}", i,
                                       settings.Cooler[i].Type, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Controller: {1}{2}", i,
                                       settings.Cooler[i].Controller, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultMin: {1}{2}", i,
                                       settings.Cooler[i].DefaultMin, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultMax: {1}{2}", i,
                                       settings.Cooler[i].DefaultMax, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentMin: {1}{2}", i,
                                       settings.Cooler[i].CurrentMin, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentMax: {1}{2}", i,
                                       settings.Cooler[i].CurrentMax, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentLevel: {1}{2}", i,
                                       settings.Cooler[i].CurrentLevel, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].DefaultPolicy: {1}{2}", i,
                                       settings.Cooler[i].DefaultPolicy, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].CurrentPolicy: {1}{2}", i,
                                       settings.Cooler[i].CurrentPolicy, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Target: {1}{2}", i,
                                       settings.Cooler[i].Target, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].ControlType: {1}{2}", i,
                                       settings.Cooler[i].ControlType, Environment.NewLine);
                        r.AppendFormat(" Cooler[{0}].Active: {1}{2}", i,
                                       settings.Cooler[i].Active, Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GetDisplayDriverMemoryInfo != null &&
                displayHandle.HasValue)
            {
                NvDisplayDriverMemoryInfo memoryInfo = new NvDisplayDriverMemoryInfo();
                memoryInfo.Version = NVAPI.DISPLAY_DRIVER_MEMORY_INFO_VER;
                memoryInfo.Values  = new uint[NVAPI.MAX_MEMORY_VALUES_PER_GPU];
                NvStatus status = NVAPI.NvAPI_GetDisplayDriverMemoryInfo(
                    displayHandle.Value, ref memoryInfo);

                r.AppendLine("Memory Info");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < memoryInfo.Values.Length; i++)
                    {
                        r.AppendFormat(" Value[{0}]: {1}{2}", i,
                                       memoryInfo.Values[i], Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            if (NVAPI.NvAPI_GPU_ClientFanCoolersGetStatus != null)
            {
                var coolers = new NvFanCoolersStatus();
                coolers.Version = NVAPI.GPU_FAN_COOLERS_STATUS_VER;
                coolers.Items   =
                    new NvFanCoolersStatusItem[NVAPI.MAX_FAN_COOLERS_STATUS_ITEMS];

                var status = NVAPI.NvAPI_GPU_ClientFanCoolersGetStatus(handle, ref coolers);

                r.AppendLine("Fan Coolers Status");
                r.AppendLine();
                if (status == NvStatus.OK)
                {
                    for (int i = 0; i < coolers.Count; i++)
                    {
                        r.AppendFormat(" Items[{0}].Type: {1}{2}", i,
                                       coolers.Items[i].Type, Environment.NewLine);
                        r.AppendFormat(" Items[{0}].CurrentRpm: {1}{2}", i,
                                       coolers.Items[i].CurrentRpm, Environment.NewLine);
                        r.AppendFormat(" Items[{0}].CurrentMinLevel: {1}{2}", i,
                                       coolers.Items[i].CurrentMinLevel, Environment.NewLine);
                        r.AppendFormat(" Items[{0}].CurrentMaxLevel: {1}{2}", i,
                                       coolers.Items[i].CurrentMaxLevel, Environment.NewLine);
                        r.AppendFormat(" Items[{0}].CurrentLevel: {1}{2}", i,
                                       coolers.Items[i].CurrentLevel, Environment.NewLine);
                    }
                }
                else
                {
                    r.Append(" Status: ");
                    r.AppendLine(status.ToString());
                }
                r.AppendLine();
            }

            return(r.ToString());
        }
예제 #18
0
파일: Nvidia.cs 프로젝트: curi1119/monitor
        public Nvidia()
        {
            bool available = NVAPI.IsAvailable;

            NvPhysicalGpuHandle[] handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
            int count;

            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
            {
                //Console.WriteLine("Error: NvAPI_EnumPhysicalGPUs not available");
                return;
            }
            else
            {
                NvStatus status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out count);
                if (status != NvStatus.OK)
                {
                    //Console.WriteLine("Error: NvAPI_EnumPhysicalGPUs not available");
                    //Console.WriteLine("Status: " + status);
                    return;
                }
            }
            IDictionary <NvPhysicalGpuHandle, NvDisplayHandle> displayHandles = new Dictionary <NvPhysicalGpuHandle, NvDisplayHandle>();
            NvDisplayHandle displayHandle;

            if (NVAPI.NvAPI_EnumNvidiaDisplayHandle != null && NVAPI.NvAPI_GetPhysicalGPUsFromDisplay != null)
            {
                NvStatus status = NvStatus.OK;
                int      i      = 0;
                while (status == NvStatus.OK)
                {
                    displayHandle = new NvDisplayHandle();
                    status        = NVAPI.NvAPI_EnumNvidiaDisplayHandle(i, ref displayHandle);
                    i++;

                    if (status == NvStatus.OK)
                    {
                        NvPhysicalGpuHandle[] handlesFromDisplay = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
                        uint countFromDisplay;
                        if (NVAPI.NvAPI_GetPhysicalGPUsFromDisplay(displayHandle, handlesFromDisplay, out countFromDisplay) == NvStatus.OK)
                        {
                            for (int j = 0; j < countFromDisplay; j++)
                            {
                                if (!displayHandles.ContainsKey(handlesFromDisplay[j]))
                                {
                                    displayHandles.Add(handlesFromDisplay[j], displayHandle);
                                }
                            }
                        }
                    }
                }
            }
            if (count > 1)
            {
                Console.WriteLine("only suppoert 1 GUP");
            }

            displayHandles.TryGetValue(handles[0], out displayHandle);
            this._handle        = handles[0];
            this._displayHandle = displayHandle;
            this.Name           = GetName(this._handle);
        }