Exemplo n.º 1
0
        public AMDGpuSet() {
#if DEBUG
            NTStopwatch.Start();
#endif
            this.Properties = new List<GpuSetProperty>();
            this.OverClock = new GpuOverClock(adlHelper);
            VirtualRoot.AddEventPath<AppExitEvent>("程序退出时调用adlHelper.Close", LogEnum.None, message => {
                adlHelper.Close();
            }, this.GetType());
            int deviceCount = 0;
            deviceCount = adlHelper.GpuCount;
            for (int i = 0; i < deviceCount; i++) {
                var atiGpu = adlHelper.GetAtiGPU(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(GpuType.AMD, 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 = 5 * NTKeyword.ULongG;
                bool has470 = _gpus.Any(a => a.Key != NTMinerContext.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(NTMinerContext.GpuAllId);
                        foreach (var kv in kvs) {
                            Environment.SetEnvironmentVariable(kv.Key, kv.Value);
                        }
                    });
                }
                else {
                    Task.Factory.StartNew(() => {
                        OverClock.RefreshGpuState(NTMinerContext.GpuAllId);
                    });
                }
            }
#if DEBUG
            var elapsedMilliseconds = NTStopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) {
                NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
            }
#endif
        }
Exemplo n.º 2
0
        public AMDGpuSet(INTMinerRoot root) : this()
        {
#if DEBUG
            VirtualRoot.Stopwatch.Restart();
#endif
            _root = root;
            adlHelper.Init();
            this.OverClock = new AMDOverClock(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.GetTotalMemoryByIndex(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;
                if (_gpus.Any(a => a.Key != NTMinerRoot.GpuAllId && a.Value.TotalMemory < minG))
                {
                    Dictionary <string, string> kvs = new Dictionary <string, string> {
                        { "GPU_FORCE_64BIT_PTR", "0" },
                        { "GPU_MAX_ALLOC_PERCENT", "100" },
                        { "GPU_MAX_HEAP_SIZE", "100" },
                        { "GPU_SINGLE_ALLOC_PERCENT", "100" },
                        { "GPU_USE_SYNC_OBJECTS", "1" }
                    };
                    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);
                        }
                    });
                }
            }
#if DEBUG
            Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
        }
Exemplo n.º 3
0
        public NVIDIAGpuSet(INTMinerRoot root)
        {
            _root           = root;
            this.OverClock  = new GpuOverClock(_nvapiHelper);
            this.Properties = new List <GpuSetProperty>();
            var gpus = _nvmlHelper.GetGpus();

            if (gpus.Count > 0)
            {
                foreach (var item in gpus)
                {
                    var gpu = Gpu.Create(item.GpuIndex, item.BusId.ToString(), item.Name);
                    gpu.TotalMemory = item.TotalMemory;
                    _gpus.Add(item.GpuIndex, gpu);
                }
                _nvmlHelper.GetVersion(out _driverVersion, out string nvmlVersion);
                this.Properties.Add(new GpuSetProperty(GpuSetProperty.DRIVER_VERSION, "驱动版本", _driverVersion));
                try {
                    if (double.TryParse(_driverVersion, out double 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)
                    {
                        OverClock.RefreshGpuState(gpu.Index);
                    }
                    // 这里会耗时5秒
                    foreach (var kv in kvs)
                    {
                        Environment.SetEnvironmentVariable(kv.Key, kv.Value);
                    }
                });
            }
        }
Exemplo n.º 4
0
        public AMDGpuSet()
        {
#if DEBUG
            NTStopwatch.Start();
#endif
            adlHelper.Init();
            this.Properties = new List <GpuSetProperty>();
            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
            var elapsedMilliseconds = NTStopwatch.Stop();
            if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
            {
                Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
            }
#endif
        }
Exemplo n.º 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 {
                 if (double.TryParse(_driverVersion, out double 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)
                 {
                     OverClock.RefreshGpuState(gpu.Index);
                 }
                 // 这里会耗时5秒
                 foreach (var kv in kvs)
                 {
                     Environment.SetEnvironmentVariable(kv.Key, kv.Value);
                 }
             });
         }
     }
 }