Example #1
0
        public void LoadGpuState()
        {
            for (int i = 0; i < Count; i++)
            {
                uint power = adlHelper.GetPowerUsageByIndex(i);
                uint temp  = adlHelper.GetTemperatureByIndex(i);
                uint speed = adlHelper.GetFanSpeedByIndex(i);

                Gpu  gpu       = (Gpu)_gpus[i];
                bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;
                gpu.Temperature = temp;
                gpu.PowerUsage  = power;
                gpu.FanSpeed    = speed;

                if (isChanged)
                {
                    VirtualRoot.Happened(new GpuStateChangedEvent(gpu));
                }
            }
        }
Example #2
0
        public void LoadGpuState(int gpuIndex)
        {
            if (gpuIndex == NTMinerRoot.GpuAllId)
            {
                return;
            }
            uint power = adlHelper.GetPowerUsage(gpuIndex);
            int  temp  = adlHelper.GetTemperature(gpuIndex);
            uint speed = adlHelper.GetFanSpeed(gpuIndex);

            Gpu  gpu       = _gpus[gpuIndex];
            bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;

            gpu.Temperature = temp;
            gpu.PowerUsage  = power;
            gpu.FanSpeed    = speed;

            if (isChanged)
            {
                VirtualRoot.RaiseEvent(new GpuStateChangedEvent(gpu));
            }
        }
Example #3
0
        private void LoadGpuState()
        {
            for (int i = 0; i < _nvmlDevices.Length; i++)
            {
                var  nvmlDevice = _nvmlDevices[i];
                uint power      = 0;
                NvmlNativeMethods.nvmlDeviceGetPowerUsage(nvmlDevice, ref power);
                uint temp = 0;
                NvmlNativeMethods.nvmlDeviceGetTemperature(nvmlDevice, nvmlTemperatureSensors.Gpu, ref temp);
                uint speed = 0;
                NvmlNativeMethods.nvmlDeviceGetFanSpeed(nvmlDevice, ref speed);

                Gpu  gpu       = (Gpu)_gpus[i];
                bool isChanged = gpu.Temperature != temp || gpu.PowerUsage != power || gpu.FanSpeed != speed;
                gpu.Temperature = temp;
                gpu.PowerUsage  = power;
                gpu.FanSpeed    = speed;

                if (isChanged)
                {
                    Global.Happened(new GpuStateChangedEvent(gpu));
                }
            }
        }
Example #4
0
        private static void SetGpuStatus(Gpu gpu, nvmlReturn nvmlReturn)
        {
            switch (nvmlReturn)
            {
            case nvmlReturn.Success:
                gpu.State = GpuStatus.Ok;
                break;

            case nvmlReturn.Uninitialized:
                break;

            case nvmlReturn.InvalidArgument:
                break;

            case nvmlReturn.NotSupported:
                break;

            case nvmlReturn.NoPermission:
                break;

            case nvmlReturn.NotFound:
                break;

            case nvmlReturn.InsufficientSize:
                break;

            case nvmlReturn.InsufficientPower:
                break;

            case nvmlReturn.DriverNotLoaded:
                break;

            case nvmlReturn.TimeOut:
                break;

            case nvmlReturn.IRQIssue:
                break;

            case nvmlReturn.LibraryNotFound:
                break;

            case nvmlReturn.FunctionNotFound:
                break;

            case nvmlReturn.CorruptedInfoROM:
                break;

            case nvmlReturn.GPUIsLost:
                gpu.State = GpuStatus.GpuIsLost;
                break;

            case nvmlReturn.ResetRequired:
                break;

            case nvmlReturn.OperatingSystem:
                break;

            case nvmlReturn.LibRMVersionMismatch:
                break;

            case nvmlReturn.InUse:
                break;

            case nvmlReturn.Unknown:
                gpu.State = GpuStatus.Unknown;
                break;

            default:
                break;
            }
        }
Example #5
0
 public NVIDIAGpuSet(INTMinerRoot root)
 {
     _root           = root;
     this.Properties = new List <GpuSetProperty>();
     if (NvmlInit())
     {
         NvmlNativeMethods.nvmlDeviceGetCount(ref deviceCount);
         for (int i = 0; i < deviceCount; i++)
         {
             Gpu        gpu        = Gpu.Create(i, string.Empty);
             nvmlDevice nvmlDevice = new nvmlDevice();
             var        nvmlReturn = NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice);
             SetGpuStatus(gpu, nvmlReturn);
             NvmlNativeMethods.nvmlDeviceGetName(nvmlDevice, out string name);
             nvmlMemory memory = new nvmlMemory();
             NvmlNativeMethods.nvmlDeviceGetMemoryInfo(nvmlDevice, ref memory);
             // short gpu name
             if (!string.IsNullOrEmpty(name))
             {
                 name = name.Replace("GeForce GTX ", string.Empty);
                 name = name.Replace("GeForce ", string.Empty);
             }
             gpu.Name        = name;
             gpu.TotalMemory = memory.total;
             _gpus.Add(i, gpu);
         }
         if (deviceCount > 0)
         {
             NvmlNativeMethods.nvmlSystemGetDriverVersion(out _driverVersion);
             NvmlNativeMethods.nvmlSystemGetNVMLVersion(out string nvmlVersion);
             this.Properties.Add(new GpuSetProperty(GpuSetProperty.DRIVER_VERSION, "驱动版本", _driverVersion));
             try {
                 double driverVersionNum;
                 if (double.TryParse(_driverVersion, out driverVersionNum))
                 {
                     var item = root.SysDicItemSet.GetSysDicItems("CudaVersion")
                                .Select(a => new { Version = double.Parse(a.Value), a })
                                .OrderByDescending(a => a.Version)
                                .FirstOrDefault(a => driverVersionNum >= a.Version);
                     if (item != null)
                     {
                         this.Properties.Add(new GpuSetProperty("CudaVersion", "Cuda版本", item.a.Code));
                     }
                 }
             }
             catch (Exception e) {
                 Logger.ErrorDebugLine(e);
             }
             this.Properties.Add(new GpuSetProperty("NVMLVersion", "NVML版本", nvmlVersion));
             Dictionary <string, string> kvs = new Dictionary <string, string> {
                 { "CUDA_DEVICE_ORDER", "PCI_BUS_ID" }
             };
             foreach (var kv in kvs)
             {
                 var property = new GpuSetProperty(kv.Key, kv.Key, kv.Value);
                 this.Properties.Add(property);
             }
             Task.Factory.StartNew(() => {
                 foreach (var gpu in _gpus.Values)
                 {
                     NVIDIAOverClock.RefreshGpuState(gpu);
                 }
                 // 这里会耗时5秒
                 foreach (var kv in kvs)
                 {
                     Environment.SetEnvironmentVariable(kv.Key, kv.Value);
                 }
             });
         }
     }
 }
Example #6
0
        public AMDGpuSet(INTMinerRoot root) : this()
        {
#if DEBUG
            Write.Stopwatch.Restart();
#endif
            _root = root;
            adlHelper.Init();
            this.OverClock = new GpuOverClock(adlHelper);
            int deviceCount = 0;
            deviceCount = adlHelper.GpuCount;
            for (int i = 0; i < deviceCount; i++)
            {
                var    atiGpu = adlHelper.GetGpuName(i);
                string name   = atiGpu.AdapterName;
                // short gpu name
                if (!string.IsNullOrEmpty(name))
                {
                    name = name.Replace("Radeon (TM) RX ", string.Empty);
                    name = name.Replace("Radeon RX ", string.Empty);
                }
                var gpu = Gpu.Create(i, atiGpu.BusNumber.ToString(), name);
                gpu.TotalMemory = adlHelper.GetTotalMemory(i);
                _gpus.Add(i, gpu);
            }
            if (deviceCount > 0)
            {
                this.DriverVersion = adlHelper.GetDriverVersion();
                this.Properties.Add(new GpuSetProperty(GpuSetProperty.DRIVER_VERSION, "驱动版本", DriverVersion));
                const ulong minG   = (ulong)5 * 1024 * 1024 * 1024;
                bool        has470 = _gpus.Any(a => a.Key != NTMinerRoot.GpuAllId && a.Value.TotalMemory < minG);
                if (has470)
                {
                    Dictionary <string, string> kvs = new Dictionary <string, string> {
                        { "GPU_MAX_ALLOC_PERCENT", "100" },
                        { "GPU_MAX_HEAP_SIZE", "100" },
                        { "GPU_SINGLE_ALLOC_PERCENT", "100" }
                    };
                    foreach (var kv in kvs)
                    {
                        var property = new GpuSetProperty(kv.Key, kv.Key, kv.Value);
                        this.Properties.Add(property);
                    }
                    Task.Factory.StartNew(() => {
                        OverClock.RefreshGpuState(NTMinerRoot.GpuAllId);
                        foreach (var kv in kvs)
                        {
                            Environment.SetEnvironmentVariable(kv.Key, kv.Value);
                        }
                    });
                }
                else
                {
                    Task.Factory.StartNew(() => {
                        OverClock.RefreshGpuState(NTMinerRoot.GpuAllId);
                    });
                }
            }
#if DEBUG
            Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
        }
Example #7
0
        public NVIDIAGpuSet(INTMinerRoot root) : this()
        {
            _root = root;
            if (Design.IsInDesignMode)
            {
                return;
            }
            string nvsmiDir = Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles), "NVIDIA Corporation", "NVSMI");

            if (Directory.Exists(nvsmiDir))
            {
                Windows.NativeMethods.SetDllDirectory(nvsmiDir);
                NvmlNativeMethods.nvmlInit();
                _isNvmlInited = true;
                NvmlNativeMethods.nvmlDeviceGetCount(ref deviceCount);
                for (int i = 0; i < deviceCount; i++)
                {
                    nvmlDevice nvmlDevice = new nvmlDevice();
                    NvmlNativeMethods.nvmlDeviceGetHandleByIndex((uint)i, ref nvmlDevice);
                    uint gClock = 0, mClock = 0;
                    NvmlNativeMethods.nvmlDeviceGetName(nvmlDevice, out string name);
                    NvmlNativeMethods.nvmlDeviceGetMaxClockInfo(nvmlDevice, nvmlClockType.Graphics, ref gClock);
                    NvmlNativeMethods.nvmlDeviceGetMaxClockInfo(nvmlDevice, nvmlClockType.Mem, ref mClock);
                    if (!string.IsNullOrEmpty(name))
                    {
                        name = name.Replace("GeForce ", string.Empty);
                    }
                    Gpu gpu = new Gpu {
                        Index       = i,
                        Name        = name,
                        Temperature = 0,
                        PowerUsage  = 0,
                        FanSpeed    = 0,
                        OverClock   = new NVIDIAOverClock()
                    };
                    _gpus.Add(i, gpu);
                }
                if (deviceCount > 0)
                {
                    NvmlNativeMethods.nvmlSystemGetDriverVersion(out string driverVersion);
                    NvmlNativeMethods.nvmlSystemGetNVMLVersion(out string nvmlVersion);
                    this.Properties.Add(new GpuSetProperty("DriverVersion", "driver version", driverVersion));
                    this.Properties.Add(new GpuSetProperty("NVMLVersion", "NVML version", nvmlVersion));
                    Dictionary <string, string> kvs = new Dictionary <string, string> {
                        { "CUDA_DEVICE_ORDER", "PCI_BUS_ID" }
                    };
                    foreach (var kv in kvs)
                    {
                        var property = new GpuSetProperty(kv.Key, kv.Key, kv.Value);
                        this.Properties.Add(property);
                    }
                    Task.Factory.StartNew(() => {
                        // 这里会耗时5秒
                        foreach (var kv in kvs)
                        {
                            Environment.SetEnvironmentVariable(kv.Key, kv.Value);
                        }
                        foreach (var gpu in _gpus.Values)
                        {
                            NVIDIAOverClock.RefreshGpuState(gpu);
                        }
                    });
                }
            }
        }