예제 #1
0
        public Nvidia(uint i, nvmlDevice device)
        {
            this.deviceIndex = i;
            this.device      = device;
            this.type        = GPUType.NVIDIA;

            nvmlPciInfo pciInfo = new nvmlPciInfo();

            if (NvmlNativeMethods.nvmlDeviceGetPciInfo(device, ref pciInfo) == nvmlReturn.Success)
            {
                this.bus = pciInfo.bus;
            }

            if (NvmlNativeMethods.nvmlDeviceGetSerial(device, out string serialOut) == nvmlReturn.Success)
            {
                this.serial = serialOut;
            }

            if (NvmlNativeMethods.nvmlDeviceGetUUID(device, out string uuidOut) == nvmlReturn.Success)
            {
                this.uuid = uuidOut;
            }

            if (NvmlNativeMethods.nvmlDeviceGetName(device, out string name) == nvmlReturn.Success)
            {
                this.name = name;
            }

            NVAPIhandle = this.FindPhysicalGpuHandleForBus(this.bus);
        }
예제 #2
0
        //TODO fix constructor to not include 3rd party handles + refactor inside interface device info (lookup fans speed/temps/...)
        public CudaComputeDevice(CudaDevice cudaDevice, DeviceGroupType group, int gpuCount,
                                 NvPhysicalGpuHandle nvHandle, nvmlDevice nvmlHandle)
            : base((int)cudaDevice.DeviceID,
                   cudaDevice.GetName(),
                   true,
                   group,
                   DeviceType.NVIDIA,
                   string.Format(Translations.Tr("GPU#{0}"), gpuCount),
                   cudaDevice.DeviceGlobalMemory)
        {
            BusID             = cudaDevice.pciBusID;
            SMMajor           = cudaDevice.SM_major;
            SMMinor           = cudaDevice.SM_minor;
            Uuid              = cudaDevice.UUID;
            AlgorithmSettings = DefaultAlgorithms.GetAlgorithmsForDevice(this);
            Index             = ID + AvailableDevices.AvailCpus; // increment by CPU count

            _nvHandle   = nvHandle;
            _nvmlDevice = nvmlHandle;

            ShouldRunEthlargement = cudaDevice.DeviceName.Contains("1080") || cudaDevice.DeviceName.Contains("Titan Xp");
            // plugin device
            var bd = new BaseDevice(DeviceType.NVIDIA, cudaDevice.UUID, cudaDevice.GetName(), (int)cudaDevice.DeviceID);

            PluginDevice = new CUDADevice(bd, cudaDevice.pciBusID, cudaDevice.DeviceGlobalMemory, cudaDevice.SM_major, cudaDevice.SM_minor);
        }
        //TODO fix constructor to not include 3rd party handles + refactor inside interface device info (lookup fans speed/temps/...)
        public CudaComputeDevice(CudaDevice cudaDevice, DeviceGroupType group, int gpuCount,
                                 NvPhysicalGpuHandle nvHandle, nvmlDevice nvmlHandle)
            : base((int)cudaDevice.DeviceID,
                   cudaDevice.GetName(),
                   true,
                   group,
                   DeviceType.NVIDIA,
                   string.Format(Translations.Tr("GPU#{0}"), gpuCount),
                   cudaDevice.DeviceGlobalMemory)
        {
            BusID   = cudaDevice.pciBusID;
            SMMajor = cudaDevice.SM_major;
            SMMinor = cudaDevice.SM_minor;
            // if no nvml loaded fallback ID
            if (string.IsNullOrEmpty(cudaDevice.UUID))
            {
                Uuid = GetUuid(ID, GroupNames.GetGroupName(DeviceGroupType, ID), Name, DeviceGroupType);
            }
            else
            {
                Uuid = cudaDevice.UUID;
            }
            AlgorithmSettings = DefaultAlgorithms.GetAlgorithmsForDevice(this);
            Index             = ID + AvailableDevices.AvailCpus; // increment by CPU count

            _nvHandle   = nvHandle;
            _nvmlDevice = nvmlHandle;

            ShouldRunEthlargement = cudaDevice.DeviceName.Contains("1080") || cudaDevice.DeviceName.Contains("Titan Xp");
        }
예제 #4
0
        internal static void LogNvidiaMonitorManagerState()
        {
            // Enumerate NVAPI handles and map to busid
            var idHandles = InitNvapi();

            foreach (var pair in _nvidiaUUIDAndBusIds)
            {
                var uuid  = pair.Key;
                var busID = pair.Value;


                var nvmlResultStr = "InitalNVMLInitSuccess==FALSE";
                if (InitalNVMLInitSuccess)
                {
                    var nvmlHandle = new nvmlDevice();
                    var nvmlRet    = NvmlNativeMethods.nvmlDeviceGetHandleByUUID(uuid, ref nvmlHandle);
                    if (nvmlRet != nvmlReturn.Success)
                    {
                        nvmlResultStr = $"Failed with code ret {nvmlRet}";
                    }
                    else
                    {
                        nvmlResultStr = nvmlHandle.Pointer.ToString();
                    }
                }
                var nvapiResultStr = "NVAPI found no handle";
                var nvHandle       = new NvPhysicalGpuHandle();
                if (idHandles.TryGetValue(busID, out nvHandle))
                {
                    nvapiResultStr = nvHandle.ptr.ToString();
                }
                Logger.Info($"{Tag}.Init", $"UUID({uuid})-BusID({busID}): NVML_HANDLE({nvmlResultStr}) NVAPI_HANDLE({nvapiResultStr})");
            }
        }
예제 #5
0
        private NVAPIService()
        {
            DllImportAttribute attribute = new DllImportAttribute(GetLibraryName());

            attribute.CallingConvention = CallingConvention.Cdecl;
            attribute.PreserveSig       = true;
            attribute.EntryPoint        = "nvapi_QueryInterface";
            PInvokeDelegateFactory.CreateDelegate(attribute, out nvapi_QueryInterface);

            GetNvAPIDelegate(0x0150E828, out NvAPI_Initialize);
            NvAPI_Initialize();
            GetNvAPIDelegate(0xE5AC921F, out NvAPI_EnumPhysicalGPUs);
            GetNvAPIDelegate(0xD9930B07, out NvAPI_EnumTCCPhysicalGPUs);
            GetNvAPIDelegate(0x9ABDD40D, out NvAPI_EnumNvidiaDisplayHandle);
            GetNvAPIDelegate(0x34EF9506, out NvAPI_GetPhysicalGPUsFromDisplay);
            GetNvAPIDelegate(0x1BE0B8E5, out NvAPI_GPU_GetBusId);
            GetNvAPIDelegate(0xE3640A56, out NvAPI_GPU_GetThermalSettings);
            GetNvAPIDelegate(0x60DED2ED, out NvAPI_GPU_GetDynamicPstatesInfoEx);
            GetNvAPIDelegate(0x189A1FDF, out NvAPI_GPU_GetDynamicPstatesInfo);

            {
                NvPhysicalGpuHandle[] physicalGpuHandles = new NvPhysicalGpuHandle[MAX_PHYSICAL_GPUS];
                if (NvAPI_EnumPhysicalGPUs(physicalGpuHandles, out int physicalGpuCount) == 0)
                {
                    nvPhysicalGpuHandles.AddRange(physicalGpuHandles.Where((handle, i) => i < physicalGpuCount && handle.IsValid).ToList());
                }

                NvPhysicalGpuHandle[] TCCPhysicalGpuHandles = new NvPhysicalGpuHandle[MAX_PHYSICAL_GPUS];
                if (NvAPI_EnumTCCPhysicalGPUs(TCCPhysicalGpuHandles, out int TCCPhysicalGpuCount) == 0)
                {
                    nvPhysicalGpuHandles.AddRange(TCCPhysicalGpuHandles.Where((handle, i) => i < TCCPhysicalGpuCount && handle.IsValid).ToList());
                }
            }
        }
예제 #6
0
 public NvidiaGpuModel(int adapterIndex, NvPhysicalGpuHandle handle, NvDisplayHandle displayHandle)
 {
     AdapterIndex   = adapterIndex;
     _handle        = handle;
     _displayHandle = displayHandle;
     NVAPI.NvAPI_GPU_GetFullName(handle, out _gpuName);
 }
예제 #7
0
        public override bool InitializeHardware()
        {
            Logger.Debug("Initializing hardware ...");

            if (NvApi.NvApiEnumPhysicalGpUs == null || NvApi.NvApiGetPhysicalGpUsFromDisplay == null || NvApi.NvApiEnumNvidiaDisplayHandle == null)
            {
                Logger.Debug("Unable to init hardware, NvApiEnumPhysicalGpUs, NvApiEnumNvidiaDisplayHandle and NvApiGetPhysicalGpUsFromDisplay are null pointer");
                return(false);
            }

            NvStatus status;
            var      handles = new NvPhysicalGpuHandle[NvApi.MaxPhysicalGpus];

            if ((status = NvApi.NvApiEnumPhysicalGpUs(handles, out var gpuCount)) != NvStatus.Ok)
            {
                Logger.Error($"Unable to enumerate physical gpus, the API status is: {status}");
                return(false);
            }

            for (var gpuIndex = 0; gpuIndex < gpuCount; gpuIndex++)
            {
                var ngpu = new NVidiaGpu(gpuIndex, handles[gpuIndex]);
                Logger.Debug($"Adding GPU {ngpu}");
                ngpu.InitializeSensors();
                Hardware.Add(ngpu);
            }

            return(true);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
0
        internal DeviceMonitorNVIDIA(NvapiNvmlInfo info)
        {
            UUID        = info.UUID;
            BusID       = info.BusID;
            _nvHandle   = info.nvHandle;
            _nvmlDevice = info.nvmlHandle;

            try
            {
                var powerInfo = new NvGPUPowerInfo
                {
                    Version = NVAPI.GPU_POWER_INFO_VER,
                    Entries = new NvGPUPowerInfoEntry[4]
                };

                var ret = NVAPI.NvAPI_DLL_ClientPowerPoliciesGetInfo(_nvHandle, ref powerInfo);
                if (ret != NvStatus.OK)
                {
                    throw new Exception(ret.ToString());
                }

                Debug.Assert(powerInfo.Entries.Length == 4);

                if (powerInfo.Entries[0].MinPower == 0 || powerInfo.Entries[0].MaxPower == 0)
                {
                    throw new Exception("Power control not available!");
                }

                _minPowerLimit     = powerInfo.Entries[0].MinPower;
                _maxPowerLimit     = powerInfo.Entries[0].MaxPower;
                _defaultPowerLimit = powerInfo.Entries[0].DefPower;

                PowerLimitsEnabled = true;
                // set to high by default
                var defaultLevel = PowerLevel.High;
                if (!DeviceMonitorManager.DisableDevicePowerModeSettings)
                {
                    var success = SetPowerTarget(defaultLevel);
                    if (!success)
                    {
                        Logger.Info("NVML", $"Cannot set power target ({defaultLevel.ToString()}) for device with BusID={BusID}");
                    }
                }
                else
                {
                    PowerLevel = PowerLevel.Disabled;
                }
            }
            catch (Exception e)
            {
                Logger.Error("NVML", $"Getting power info failed with message \"{e.Message}\", disabling power setting");
                PowerLimitsEnabled = false;
            }
        }
예제 #11
0
파일: nvapi.cs 프로젝트: igherman26/uba
   public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle,
 out string name)
   {
       StringBuilder builder = new StringBuilder(64);
       NvStatus status;
       if (_NvAPI_GPU_GetFullName != null)
           status = _NvAPI_GPU_GetFullName(gpuHandle, builder);
       else
           status = NvStatus.FUNCTION_NOT_FOUND;
       name = builder.ToString();
       return status;
   }
예제 #12
0
파일: Nvidia.cs 프로젝트: curi1119/monitor
        private static string GetName(NvPhysicalGpuHandle handle)
        {
            string gpuName;

            if (NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName) == NvStatus.OK)
            {
                return(gpuName.Trim());
            }
            else
            {
                return("NVIDIA");
            }
        }
예제 #13
0
        static NvGPUThermalSettings GetThermalSettings(NvPhysicalGpuHandle handle)
        {
            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];
            if (NVAPI.NvAPI_GPU_GetThermalSettings(handle, (int)NvThermalTarget.ALL,
                                                   ref settings) != NvStatus.OK)
            {
                settings.Count = 0;
            }
            return(settings);
        }
예제 #14
0
        private NvPhysicalGpuHandle?GetNvPhysicalGpuHandle()
        {
            if (_NvPhysicalGpuHandle.HasValue)
            {
                return(_NvPhysicalGpuHandle.Value);
            }
            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
            {
                Logger.DebugDelayed("NVAPI", "NvAPI_EnumPhysicalGPUs unavailable", TimeSpan.FromMinutes(5));
                return(null);
            }
            if (NVAPI.NvAPI_GPU_GetBusID == null)
            {
                Logger.DebugDelayed("NVAPI", "NvAPI_GPU_GetBusID unavailable", TimeSpan.FromMinutes(5));
                return(null);
            }


            var handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
            var status  = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out _);

            if (status != NvStatus.OK)
            {
                Logger.DebugDelayed("NVAPI", $"Enum physical GPUs failed with status: {status}", TimeSpan.FromMinutes(5));
            }
            else
            {
                foreach (var handle in handles)
                {
                    var idStatus = NVAPI.NvAPI_GPU_GetBusID(handle, out var id);

                    if (idStatus == NvStatus.EXPECTED_PHYSICAL_GPU_HANDLE)
                    {
                        continue;
                    }

                    if (idStatus != NvStatus.OK)
                    {
                        Logger.DebugDelayed("NVAPI", "Bus ID get failed with status: " + idStatus, TimeSpan.FromMinutes(5));
                    }
                    else if (id == BusID)
                    {
                        Logger.DebugDelayed("NVAPI", "Found handle for busid " + id, TimeSpan.FromMinutes(5));
                        _NvPhysicalGpuHandle = handle;
                        return(handle);
                    }
                }
            }
            return(null);
        }
예제 #15
0
        private static Dictionary <int, NvPhysicalGpuHandle> InitNvapi()
        {
            var idHandles = new Dictionary <int, NvPhysicalGpuHandle>();

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

            var handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];

            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
            {
                Logger.Debug("NVAPI", "NvAPI_EnumPhysicalGPUs unavailable");
            }
            else
            {
                var status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out _);
                if (status != NvStatus.OK)
                {
                    Logger.Debug("NVAPI", $"Enum physical GPUs failed with status: {status}");
                }
                else
                {
                    foreach (var handle in handles)
                    {
                        var idStatus = NVAPI.NvAPI_GPU_GetBusID(handle, out var id);

                        if (idStatus == NvStatus.EXPECTED_PHYSICAL_GPU_HANDLE)
                        {
                            continue;
                        }

                        if (idStatus != NvStatus.OK)
                        {
                            Logger.Debug("NVAPI",
                                         "Bus ID get failed with status: " + idStatus);
                        }
                        else
                        {
                            Logger.Debug("NVAPI", "Found handle for busid " + id);
                            idHandles[id] = handle;
                        }
                    }
                }
            }

            return(idHandles);
        }
        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));
            }
        }
예제 #17
0
        private NvPhysicalGpuHandle FindPhysicalGpuHandleForBus(uint bus)
        {
            NvPhysicalGpuHandle[] handlesFromDisplay =
                new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
            if (NVAPI.NvAPI_EnumPhysicalGPUs(handlesFromDisplay, out int count) == NvStatus.OK)
            {
                foreach (NvPhysicalGpuHandle physHandle in handlesFromDisplay)
                {
                    if (NVAPI.NvAPI_GPU_GetBusID(physHandle, out int physBus) == NvStatus.OK && physBus == bus)
                    {
                        return(physHandle);
                    }
                }
            }

            return(new NvPhysicalGpuHandle());
        }
예제 #18
0
        public CudaComputeDevice(CudaDevice cudaDevice, DeviceGroupType group, int GPUCount, NvPhysicalGpuHandle nvHandle)
            : base((int)cudaDevice.DeviceID,
                   cudaDevice.GetName(),
                   true,
                   group,
                   cudaDevice.IsEtherumCapable(),
                   DeviceType.NVIDIA,
                   String.Format(International.GetText("ComputeDevice_Short_Name_NVIDIA_GPU"), GPUCount),
                   cudaDevice.DeviceGlobalMemory)
        {
            _SM_major         = cudaDevice.SM_major;
            _SM_minor         = cudaDevice.SM_minor;
            UUID              = cudaDevice.UUID;
            AlgorithmSettings = GroupAlgorithms.CreateForDeviceList(this);
            Index             = ID + ComputeDeviceManager.Avaliable.AvailCPUs; // increment by CPU count

            this.nvHandle = nvHandle;
        }
예제 #19
0
        public static NvStatus NvApiGpuGetFullName(NvPhysicalGpuHandle handle, out string name)
        {
            if (GpuGetFullName == null)
            {
                name = "Unknown";
                return(NvStatus.FunctionNotFound);
            }

            try {
                var builder = new StringBuilder(short.MaxValue);
                var status  = GpuGetFullName(handle, builder);
                name = builder.ToString();
                return(status);
            } catch (AccessViolationException ave) {
                Logger.Error($"Unable to get GPU name from handle {handle}", ave);
                name = "Unknown";
                return(NvStatus.FunctionNotFound);
            }
        }
예제 #20
0
        public float GetSensorValue(int deviceIndex, SensorType sensorType)
        {
            NvPhysicalGpuHandle physicalHandle = nvPhysicalGpuHandles[deviceIndex];

            switch (sensorType)
            {
            case SensorType.GFX_LOAD:
                if (NvAPI_GPU_GetDynamicPstatesInfoEx != null)
                {
                    NvDynamicPstatesInfoEx infoEx = new NvDynamicPstatesInfoEx();
                    infoEx.Version            = GPU_DYNAMIC_PSTATES_INFO_EX_VER;
                    infoEx.UtilizationDomains = new NvUtilizationDomainEx[NVAPI_MAX_GPU_UTILIZATIONS];
                    return(NvAPI_GPU_GetDynamicPstatesInfoEx(physicalHandle, ref infoEx) == 0 && infoEx.UtilizationDomains[0].Present ? infoEx.UtilizationDomains[0].Percentage / 100.0f : 0);
                }
                if (NvAPI_GPU_GetDynamicPstatesInfo != null)
                {
                    NvDynamicPstatesInfo info = new NvDynamicPstatesInfo();
                    info.Version            = GPU_DYNAMIC_PSTATES_INFO_VER;
                    info.UtilizationDomains = new NvUtilizationDomain[NVAPI_MAX_GPU_UTILIZATIONS];
                    return(NvAPI_GPU_GetDynamicPstatesInfo(physicalHandle, ref info) == 0 && info.UtilizationDomains[0].Present ? info.UtilizationDomains[0].Percentage : 0);
                }
                break;

            case SensorType.GFX_TEMPERATURE:
                if (NvAPI_GPU_GetThermalSettings != null)
                {
                    NvGPUThermalSettings thermalSettings = new NvGPUThermalSettings();
                    thermalSettings.Version = GPU_THERMAL_SETTINGS_VER;
                    thermalSettings.Count   = MAX_THERMAL_SENSORS_PER_GPU;
                    thermalSettings.Sensor  = new NvSensor[MAX_THERMAL_SENSORS_PER_GPU];

                    return(NvAPI_GPU_GetThermalSettings(physicalHandle, (int)NvThermalTarget.ALL, ref thermalSettings) == 0 ?
                           Array.Find(thermalSettings.Sensor, sensor => sensor.Target == NvThermalTarget.GPU).CurrentTemp : 0);
                }
                break;

            case SensorType.GFX_POWER:
                break;
            }
            return(0);
        }
예제 #21
0
        public NVidiaGpu(int adapterIndex, NvPhysicalGpuHandle handle)
        {
            AdapterHandle = handle;
            _gpuIdentifer = new NVidiaGpuIdentifer(this);

            GpuModelName = NvApi.NvApiGpuGetFullName(handle, out var gpuName) == NvStatus.Ok ? gpuName.Trim() : "Unknown";

            if (NvApi.GetPciIdentifiers != null && NvApi.GetPciIdentifiers(AdapterHandle, out var deviceId, out var subSystemId, out var revisionId, out var extDeviceId) == NvStatus.Ok)
            {
                DeviceId    = $"0x{deviceId:X}";
                SubSystemId = $"0x{subSystemId:X}";
                RevisionId  = $"0x{revisionId:X}";
            }

            if (NvApi.GetBusSlotId != null && NvApi.GetBusId(AdapterHandle, out _busId) != NvStatus.Ok)
            {
                throw new Exception("Unable to obtain bus slot id");
            }

            GpuFullName = $"NVIDIA {GpuModelName}";
        }
        public CudaComputeDevice(CudaDevice cudaDevice, DeviceGroupType group, int gpuCount,
                                 NvPhysicalGpuHandle nvHandle, nvmlDevice nvmlHandle)
            : base((int)cudaDevice.DeviceID,
                   cudaDevice.GetName(),
                   true,
                   group,
                   cudaDevice.IsEtherumCapable(),
                   DeviceType.NVIDIA,
                   string.Format(International.GetText("ComputeDevice_Short_Name_NVIDIA_GPU"), gpuCount),
                   cudaDevice.DeviceGlobalMemory)
        {
            BusID             = cudaDevice.pciBusID;
            SMMajor           = cudaDevice.SM_major;
            SMMinor           = cudaDevice.SM_minor;
            UUID              = cudaDevice.UUID;
            AlgorithmSettings = GroupAlgorithms.CreateForDeviceList(this);
            Index             = ID + ComputeDeviceManager.Avaliable.AvailCPUs; // increment by CPU count

            _nvHandle             = nvHandle;
            nvmlDevice            = nvmlHandle;
            ShouldRunEthlargement = cudaDevice.DeviceName.Contains("1080") || cudaDevice.DeviceName.Contains("Titan Xp");
        }
        public CudaComputeDevice(CudaDevice cudaDevice, DeviceGroupType group, int gpuCount,
                                 NvPhysicalGpuHandle nvHandle, nvmlDevice nvmlHandle)
            : base((int)cudaDevice.DeviceID,
                   cudaDevice.GetName(),
                   true,
                   group,
                   cudaDevice.IsEtherumCapable(),
                   DeviceType.NVIDIA,
                   string.Format(Translations.Tr("GPU#{0}"), gpuCount),
                   cudaDevice.DeviceGlobalMemory)
        {
            BusID             = cudaDevice.pciBusID;
            SMMajor           = cudaDevice.SM_major;
            SMMinor           = cudaDevice.SM_minor;
            Uuid              = cudaDevice.UUID;
            AlgorithmSettings = GroupAlgorithms.CreateForDeviceList(this);
            Index             = ID + AvailableDevices.AvailCpus; // increment by CPU count

            _nvHandle   = nvHandle;
            _nvmlDevice = nvmlHandle;

            ShouldRunEthlargement = cudaDevice.DeviceName.Contains("1080") || cudaDevice.DeviceName.Contains("Titan Xp");
        }
예제 #24
0
        public void ResetHandles(NvapiNvmlInfo info)
        {
            _nvHandle   = info.nvHandle;
            _nvmlDevice = info.nvmlHandle;

            try
            {
                var powerInfo = new NvGPUPowerInfo
                {
                    Version = NVAPI.GPU_POWER_INFO_VER,
                    Entries = new NvGPUPowerInfoEntry[4]
                };

                var ret = NVAPI.NvAPI_DLL_ClientPowerPoliciesGetInfo(_nvHandle, ref powerInfo);
                if (ret != NvStatus.OK)
                {
                    throw new Exception(ret.ToString());
                }

                Debug.Assert(powerInfo.Entries.Length == 4);

                if (powerInfo.Entries[0].MinPower == 0 || powerInfo.Entries[0].MaxPower == 0)
                {
                    throw new Exception("Power control not available!");
                }

                _minPowerLimit     = powerInfo.Entries[0].MinPower;
                _maxPowerLimit     = powerInfo.Entries[0].MaxPower;
                _defaultPowerLimit = powerInfo.Entries[0].DefPower;
            }
            catch (Exception e)
            {
                Logger.Error("NVML", $"Getting power info failed with message \"{e.Message}\", disabling power setting");
                PowerLimitsEnabled = false;
            }
        }
예제 #25
0
                public static void QueryCudaDevices()
                {
                    Helpers.ConsolePrint(Tag, "QueryCudaDevices START");
                    QueryCudaDevices(ref _cudaDevices);

                    if (_cudaDevices != null && _cudaDevices.Count != 0)
                    {
                        Available.HasNvidia = true;
                        var stringBuilder = new StringBuilder();
                        stringBuilder.AppendLine("");
                        stringBuilder.AppendLine("CudaDevicesDetection:");

                        // Enumerate NVAPI handles and map to busid
                        var idHandles = new Dictionary <int, NvPhysicalGpuHandle>();
                        if (NVAPI.IsAvailable)
                        {
                            var handles = new NvPhysicalGpuHandle[NVAPI.MAX_PHYSICAL_GPUS];
                            if (NVAPI.NvAPI_EnumPhysicalGPUs == null)
                            {
                                Helpers.ConsolePrint("NVAPI", "NvAPI_EnumPhysicalGPUs unavailable");
                            }
                            else
                            {
                                var status = NVAPI.NvAPI_EnumPhysicalGPUs(handles, out var _);
                                if (status != NvStatus.OK)
                                {
                                    Helpers.ConsolePrint("NVAPI", "Enum physical GPUs failed with status: " + status);
                                }
                                else
                                {
                                    foreach (var handle in handles)
                                    {
                                        var idStatus = NVAPI.NvAPI_GPU_GetBusID(handle, out var id);
                                        if (idStatus != NvStatus.EXPECTED_PHYSICAL_GPU_HANDLE)
                                        {
                                            if (idStatus != NvStatus.OK)
                                            {
                                                Helpers.ConsolePrint("NVAPI",
                                                                     "Bus ID get failed with status: " + idStatus);
                                            }
                                            else
                                            {
                                                Helpers.ConsolePrint("NVAPI", "Found handle for busid " + id);
                                                idHandles[id] = handle;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        var nvmlInit = false;
                        try
                        {
                            var ret = NvmlNativeMethods.nvmlInit();
                            if (ret != nvmlReturn.Success)
                            {
                                throw new Exception($"NVML init failed with code {ret}");
                            }
                            nvmlInit = true;
                        }
                        catch (Exception e)
                        {
                            Helpers.ConsolePrint("NVML", e.ToString());
                        }

                        foreach (var cudaDev in _cudaDevices)
                        {
                            // check sm vesrions
                            bool isUnderSM21;
                            {
                                var isUnderSM2Major = cudaDev.SM_major < 2;
                                var isUnderSM1Minor = cudaDev.SM_minor < 1;
                                isUnderSM21 = isUnderSM2Major && isUnderSM1Minor;
                            }
                            //bool isOverSM6 = cudaDev.SM_major > 6;
                            var          skip               = isUnderSM21;
                            var          skipOrAdd          = skip ? "SKIPED" : "ADDED";
                            const string isDisabledGroupStr = ""; // TODO remove
                            var          etherumCapableStr  = cudaDev.IsEtherumCapable() ? "YES" : "NO";
                            stringBuilder.AppendLine($"\t{skipOrAdd} device{isDisabledGroupStr}:");
                            stringBuilder.AppendLine($"\t\tID: {cudaDev.DeviceID}");
                            stringBuilder.AppendLine($"\t\tBusID: {cudaDev.pciBusID}");
                            stringBuilder.AppendLine($"\t\tNAME: {cudaDev.GetName()}");
                            stringBuilder.AppendLine($"\t\tVENDOR: {cudaDev.VendorName}");
                            stringBuilder.AppendLine($"\t\tUUID: {cudaDev.UUID}");
                            stringBuilder.AppendLine($"\t\tSM: {cudaDev.SMVersionString}");
                            stringBuilder.AppendLine($"\t\tMEMORY: {cudaDev.DeviceGlobalMemory}");
                            stringBuilder.AppendLine($"\t\tETHEREUM: {etherumCapableStr}");

                            if (!skip)
                            {
                                DeviceGroupType group;
                                switch (cudaDev.SM_major)
                                {
                                case 2:
                                    group = DeviceGroupType.NVIDIA_2_1;
                                    break;

                                case 3:
                                    group = DeviceGroupType.NVIDIA_3_x;
                                    break;

                                case 5:
                                    group = DeviceGroupType.NVIDIA_5_x;
                                    break;

                                case 6:
                                    group = DeviceGroupType.NVIDIA_6_x;
                                    break;

                                default:
                                    group = DeviceGroupType.NVIDIA_6_x;
                                    break;
                                }

                                var nvmlHandle = new nvmlDevice();

                                if (nvmlInit)
                                {
                                    var ret = NvmlNativeMethods.nvmlDeviceGetHandleByUUID(cudaDev.UUID, ref nvmlHandle);
                                    stringBuilder.AppendLine(
                                        "\t\tNVML HANDLE: " +
                                        $"{(ret == nvmlReturn.Success ? nvmlHandle.Pointer.ToString() : $"Failed with code ret {ret}")}");
                                }

                                idHandles.TryGetValue(cudaDev.pciBusID, out var handle);
                                Available.Devices.Add(
                                    new CudaComputeDevice(cudaDev, group, ++GpuCount, handle, nvmlHandle)
                                    );
                            }
                        }
                        Helpers.ConsolePrint(Tag, stringBuilder.ToString());
                    }
예제 #26
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);
        }
예제 #27
0
        public NvidiaGPU(int adapterIndex, NvPhysicalGpuHandle handle,
            NvDisplayHandle? displayHandle, ISettings settings)
            : base(GetName(handle), new Identifier("nvidiagpu",
          adapterIndex.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.adapterIndex = adapterIndex;
              this.handle = handle;
              this.displayHandle = displayHandle;

              NvGPUThermalSettings thermalSettings = GetThermalSettings();
              temperatures = new Sensor[thermalSettings.Count];
              for (int i = 0; i < temperatures.Length; i++) {
            NvSensor sensor = thermalSettings.Sensor[i];
            string name;
            switch (sensor.Target) {
              case NvThermalTarget.BOARD: name = "GPU Board"; break;
              case NvThermalTarget.GPU: name = "GPU Core"; break;
              case NvThermalTarget.MEMORY: name = "GPU Memory"; break;
              case NvThermalTarget.POWER_SUPPLY: name = "GPU Power Supply"; break;
              case NvThermalTarget.UNKNOWN: name = "GPU Unknown"; break;
              default: name = "GPU"; break;
            }
            temperatures[i] = new Sensor(name, i, SensorType.Temperature, this,
              new ParameterDescription[0], settings);
            ActivateSensor(temperatures[i]);
              }

              int value;
              if (NVAPI.NvAPI_GPU_GetTachReading != null &&
            NVAPI.NvAPI_GPU_GetTachReading(handle, out value) == NvStatus.OK) {
            if (value >= 0) {
              fan = new Sensor("GPU", 0, SensorType.Fan, this, settings);
              ActivateSensor(fan);
            }
              }

              clocks = new Sensor[3];
              clocks[0] = new Sensor("GPU Core", 0, SensorType.Clock, this, settings);
              clocks[1] = new Sensor("GPU Memory", 1, SensorType.Clock, this, settings);
              clocks[2] = new Sensor("GPU Shader", 2, SensorType.Clock, this, settings);
              for (int i = 0; i < clocks.Length; i++)
            ActivateSensor(clocks[i]);

              loads = new Sensor[3];
              loads[0] = new Sensor("GPU Core", 0, SensorType.Load, this, settings);
              loads[1] = new Sensor("GPU Memory Controller", 1, SensorType.Load, this, settings);
              loads[2] = new Sensor("GPU Video Engine", 2, SensorType.Load, this, settings);
              memoryLoad = new Sensor("GPU Memory", 3, SensorType.Load, this, settings);
              memoryFree = new Sensor("GPU Memory Free", 1, SensorType.SmallData, this, settings);
              memoryUsed = new Sensor("GPU Memory Used", 2, SensorType.SmallData, this, settings);
              memoryAvail = new Sensor("GPU Memory Total", 3, SensorType.SmallData, this, settings);
              control = new Sensor("GPU Fan", 0, SensorType.Control, this, settings);

              NvGPUCoolerSettings coolerSettings = GetCoolerSettings();
              if (coolerSettings.Count > 0) {
            fanControl = new Control(control, settings,
              coolerSettings.Cooler[0].DefaultMin,
              coolerSettings.Cooler[0].DefaultMax);
            fanControl.ControlModeChanged += ControlModeChanged;
            fanControl.SoftwareControlValueChanged += SoftwareControlValueChanged;
            ControlModeChanged(fanControl);
            control.Control = fanControl;
              }
              Update();
        }
예제 #28
0
 private static string GetName(NvPhysicalGpuHandle handle)
 {
     string gpuName;
       if (NVAPI.NvAPI_GPU_GetFullName(handle, out gpuName) == NvStatus.OK) {
     return "NVIDIA " + gpuName.Trim();
       } else {
     return "NVIDIA";
       }
 }
예제 #29
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);
        }
예제 #30
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();
        }
예제 #31
-1
 static NvGPUThermalSettings GetThermalSettings(NvPhysicalGpuHandle handle)
 {
     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];
       if (NVAPI.NvAPI_GPU_GetThermalSettings(handle, (int)NvThermalTarget.ALL,
     ref settings) != NvStatus.OK)
       {
     settings.Count = 0;
       }
       return settings;
 }