コード例 #1
0
        public static List <NvidiaGPU> EnumGPUs()
        {
            NvStatus status;
            var      gpus = new List <NvidiaGPU>();

            if (!NVAPI.IsAvailable)
            {
                return(gpus);
            }

            var gpuHandles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];

            status = NVAPI.NvAPI_EnumPhysicalGPUs(gpuHandles, out int count);
            if (status != NvStatus.OK)
            {
                return(gpus);
            }

            for (int i = 0; i < count; i++)
            {
                var handle = gpuHandles[i];
                var sb     = new StringBuilder(NVAPI.SHORT_STRING_MAX);
                status = NVAPI.NvAPI_GPU_GetFullName(handle, sb);
                if (status != NvStatus.OK)
                {
                    continue;
                }
                NvGPUCoolerSettings settings = new NvGPUCoolerSettings
                {
                    Version = NVAPI.GPU_COOLER_SETTINGS_VER,
                    Count   = 1,
                    Coolers = new NvCooler[NVAPI.MAX_COOLER_PER_GPU]
                };
                status = NVAPI.NvAPI_GPU_GetCoolerSettings(handle, 0, ref settings);
                if (status != NvStatus.OK)
                {
                    continue;
                }
                status = NVAPI.NvAPI_GPU_GetPCIIdentifiers(handle, out uint deviceId, out uint subSystemId, out uint revisionId, out uint extDeviceId);
                if (status != NvStatus.OK)
                {
                    continue;
                }
                status = NVAPI.NvAPI_GPU_GetBusId(handle, out uint busId);
                if (status != NvStatus.OK)
                {
                    continue;
                }
                var gpu = new NvidiaGPU(handle, settings)
                {
                    BusId = busId, Name = sb.ToString(), Index = i, SubDeviceId = subSystemId
                };
                gpus.Add(gpu);
            }

            return(gpus);
        }
コード例 #2
0
 public NvidiaGPU(NvPhysicalGpuHandle handle, NvGPUCoolerSettings coolerSetting)
 {
     _handle        = handle;
     _coolerSetting = coolerSetting;
 }