示例#1
0
        public void Update()
        {
            NvPStates states = new NvPStates();

            states.Version = NVAPI.GPU_PSTATES_VER;
            states.PStates = new NvPState[NVAPI.MAX_PSTATES_PER_GPU];

            // Update GPU processor load
            if (NVAPI.NvAPI_GPU_GetPStates != null && NVAPI.NvAPI_GPU_GetPStates(handle, ref states) == NvStatus.OK)
            {
                for (int i = 0; i < loads.Length; i++)
                {
                    if (states.PStates[i].Present)
                    {
                        loads[i].Value = states.PStates[i].Percentage;
                    }
                }
            }
            else
            {
                NvUsages usages = new NvUsages();
                usages.Version = NVAPI.GPU_USAGES_VER;
                usages.Usage   = new uint[NVAPI.MAX_USAGES_PER_GPU];
                if (NVAPI.NvAPI_GPU_GetUsages != null && NVAPI.NvAPI_GPU_GetUsages(handle, ref usages) == NvStatus.OK)
                {
                    loads[0].Value = usages.Usage[2];
                    loads[1].Value = usages.Usage[6];
                    loads[2].Value = usages.Usage[10];
                }
            }

            // Update GPU memory load
            NvMemoryInfo memoryInfo = new NvMemoryInfo();

            memoryInfo.Version = NVAPI.GPU_MEMORY_INFO_VER;
            memoryInfo.Values  = new uint[NVAPI.MAX_MEMORY_VALUES_PER_GPU];
            if (NVAPI.NvAPI_GPU_GetMemoryInfo != null && displayHandle.HasValue && NVAPI.NvAPI_GPU_GetMemoryInfo(displayHandle.Value, ref memoryInfo) == NvStatus.OK)
            {
                uint  totalMemory = memoryInfo.Values[0];
                uint  freeMemory  = memoryInfo.Values[4];
                float usedMemory  = Math.Max(totalMemory - freeMemory, 0);

                memoryLoad.Value = 100f * usedMemory / totalMemory;
            }
        }
示例#2
0
 private static string GetName(NvPhysicalGpuHandle handle)
 {
     return("NVIDIA" + ((NVAPI.NvAPI_GPU_GetFullName(handle, out string gpuName) == NvStatus.OK) ? gpuName.Trim() : ""));
 }