static SystemSpecs() { var query = WindowsManagementObjectSearcher.GetSystemSpecs(); FreePhysicalMemory = query.Item1 as ulong? ?? FreePhysicalMemory; FreeVirtualMemory = query.Item2 as ulong? ?? FreeVirtualMemory; // log Helpers.ConsolePrint("SystemSpecs", $"FreePhysicalMemory = {FreePhysicalMemory}"); Helpers.ConsolePrint("SystemSpecs", $"FreeVirtualMemory = {FreeVirtualMemory}"); }
public static List <CpuComputeDevice> QueryCpus(out bool failed64Bit, out bool failedCpuCount) { Helpers.ConsolePrint(Tag, "QueryCpus START"); // get all CPUs var cpuCount = CpuID.GetPhysicalProcessorCount(); Helpers.ConsolePrint(Tag, CpuID.IsHypeThreadingEnabled() ? "HyperThreadingEnabled = TRUE" : "HyperThreadingEnabled = FALSE"); // get all cores (including virtual - HT can benefit mining) var threadsPerCpu = WindowsManagementObjectSearcher.GetVirtualCoresCount() / cpuCount; failed64Bit = !Helpers.Is64BitOperatingSystem; failedCpuCount = threadsPerCpu * cpuCount > 64; // TODO important move this to settings var threadsPerCpuMask = threadsPerCpu; Globals.ThreadsPerCpu = threadsPerCpu; var cpus = new List <CpuComputeDevice>(); if (CpuUtils.IsCpuMiningCapable() && !failed64Bit && !failedCpuCount) { if (cpuCount == 1) { cpus.Add(new CpuComputeDevice(0, "CPU0", CpuID.GetCpuName().Trim(), threadsPerCpu, 0, 1)); } else if (cpuCount > 1) { for (var i = 0; i < cpuCount; i++) { cpus.Add( new CpuComputeDevice(i, "CPU" + i, CpuID.GetCpuName().Trim(), threadsPerCpu, CpuID.CreateAffinityMask(i, threadsPerCpuMask), i + 1) ); } } } Helpers.ConsolePrint(Tag, "QueryCpus END"); return(cpus); }
public static void InitializeConfig() { // init defaults GeneralConfig.SetDefaults(); GeneralConfig.hwid = WindowsManagementObjectSearcher.GetCpuID(); // if exists load file GeneralConfig fromFile = null; if (GeneralConfigFile.IsFileExists()) { fromFile = GeneralConfigFile.ReadFile(); } // just in case if (fromFile != null) { // set config loaded from file _isGeneralConfigFileInit = true; GeneralConfig = fromFile; if (GeneralConfig.ConfigFileVersion == null || GeneralConfig.ConfigFileVersion.CompareTo(System.Reflection.Assembly.GetExecutingAssembly() .GetName().Version) != 0) { if (GeneralConfig.ConfigFileVersion == null) { Helpers.ConsolePrint(Tag, "Loaded Config file no version detected falling back to defaults."); GeneralConfig.SetDefaults(); } Helpers.ConsolePrint(Tag, "Config file is from an older version of NiceHashMiner.."); _isNewVersion = true; GeneralConfigFile.CreateBackup(); } GeneralConfig.FixSettingBounds(); } else { GeneralConfigFileCommit(); } }
/* * internal static IEnumerable<VideoControllerData> QueryVideoControllers() * { * var vidControllers = new List<VideoControllerData>(); * var allVideoContollersOK = true; * * var stringBuilder = new StringBuilder(); * stringBuilder.AppendLine(""); * stringBuilder.AppendLine("QueryVideoControllers: "); * * using (var moc = new ManagementObjectSearcher("root\\CIMV2", * "SELECT * FROM Win32_VideoController WHERE PNPDeviceID LIKE 'PCI%'").Get()) * { * foreach (var manObj in moc) * { * ulong.TryParse(SafeGetProperty(manObj, "AdapterRAM"), out var memTmp); * var vidController = new VideoControllerData * ( * SafeGetProperty(manObj, "Name"), * SafeGetProperty(manObj, "Description"), * SafeGetProperty(manObj, "PNPDeviceID"), * SafeGetProperty(manObj, "DriverVersion"), * SafeGetProperty(manObj, "Status"), * SafeGetProperty(manObj, "InfSection"), * memTmp * ); * * stringBuilder.AppendLine("\tWin32_VideoController detected:"); * stringBuilder.AppendLine($"{vidController.GetFormattedString()}"); * * // check if controller ok * if (allVideoContollersOK && !vidController.Status.ToLower().Equals("ok")) * { * allVideoContollersOK = false; * } * * vidControllers.Add(vidController); * } * } * * AvailableVideoControllers = vidControllers; * * Helpers.ConsolePrint(Tag, stringBuilder.ToString()); * * if (allVideoContollersOK) return Enumerable.Empty<VideoControllerData>(); * * return vidControllers.Where(vc => vc.Status.ToLower() != "ok"); * } */ internal static IEnumerable <VideoControllerData> QueryVideoControllers() { var allVideoContollersOK = true; var vidControllers = WindowsManagementObjectSearcher.GetVideoControllersData(); AvailableVideoControllers = vidControllers; foreach (var controller in vidControllers) { if (allVideoContollersOK && !controller.Status.ToLower().Equals("ok")) { allVideoContollersOK = false; } } if (allVideoContollersOK) { return(Enumerable.Empty <VideoControllerData>()); } return(vidControllers.Where(vc => vc.Status.ToLower() != "ok")); }
public static bool IsHypeThreadingEnabled() { return(WindowsManagementObjectSearcher.GetVirtualCoresCount() > WindowsManagementObjectSearcher.GetNumberOfCores()); }
static void Main(string[] argv) { // Set working directory to exe var pathSet = false; var path = Path.GetDirectoryName(Application.ExecutablePath); if (path != null) { Environment.CurrentDirectory = path; pathSet = true; } // Add common folder to path for launched processes var pathVar = Environment.GetEnvironmentVariable("PATH"); pathVar += ";" + Path.Combine(Environment.CurrentDirectory, "common"); Environment.SetEnvironmentVariable("PATH", pathVar); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; //Console.OutputEncoding = System.Text.Encoding.Unicode; // #0 set this first so data parsing will work correctly Globals.JsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, Culture = CultureInfo.InvariantCulture }; // #1 first initialize config ConfigManager.InitializeConfig(); // #2 check if multiple instances are allowed if (ConfigManager.GeneralConfig.AllowMultipleInstances == false) { try { var current = Process.GetCurrentProcess(); foreach (var process in Process.GetProcessesByName(current.ProcessName)) { if (process.Id != current.Id) { // already running instance, return from Main return; } } } catch { } } // start program if (ConfigManager.GeneralConfig.LogToFile) { Logger.ConfigureWithFile(); } if (ConfigManager.GeneralConfig.DebugConsole) { PInvokeHelpers.AllocConsole(); } // init active display currency after config load ExchangeRateApi.ActiveDisplayCurrency = ConfigManager.GeneralConfig.DisplayCurrency; Helpers.ConsolePrint("NICEHASH", "Starting up NiceHashMiner v" + Application.ProductVersion); if (!pathSet) { Helpers.ConsolePrint("NICEHASH", "Path not set to executable"); } // check TOS if (ConfigManager.GeneralConfig.agreedWithTOS != Globals.CurrentTosVer) { Helpers.ConsolePrint("NICEHASH", $"TOS differs! agreed: {ConfigManager.GeneralConfig.agreedWithTOS} != Current {Globals.CurrentTosVer}. Showing TOS Form."); Application.Run(new FormEula()); // check TOS after if (ConfigManager.GeneralConfig.agreedWithTOS != Globals.CurrentTosVer) { Helpers.ConsolePrint("NICEHASH", $"TOS differs AFTER TOS confirmation FORM"); // TOS not confirmed return from Main return; } } // if config created show language select if (string.IsNullOrEmpty(ConfigManager.GeneralConfig.Language)) { if (Translations.GetAvailableLanguagesNames().Count > 1) { Application.Run(new Form_ChooseLanguage()); } else { ConfigManager.GeneralConfig.Language = "en"; ConfigManager.GeneralConfigFileCommit(); } } Translations.SetLanguage(ConfigManager.GeneralConfig.Language); // check WMI if (WindowsManagementObjectSearcher.IsWmiEnabled()) { // if no BTC address show login/register form if (ConfigManager.GeneralConfig.BitcoinAddress.Trim() == "") { Application.Run(new EnterBTCDialogSwitch()); } // finally run Application.Run(new Form_Main()); } else { MessageBox.Show(Translations.Tr("NiceHash Miner Legacy cannot run needed components. It seems that your system has Windows Management Instrumentation service Disabled. In order for NiceHash Miner Legacy to work properly Windows Management Instrumentation service needs to be Enabled. This service is needed to detect RAM usage and Avaliable Video controler information. Enable Windows Management Instrumentation service manually and start NiceHash Miner Legacy."), Translations.Tr("Windows Management Instrumentation Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static async Task <QueryResult> QueryDevicesAsync() { // #0 get video controllers, used for cross checking var badVidCtrls = SystemSpecs.QueryVideoControllers(); // Order important CPU Query must be first // #1 CPU var cpuDevs = CpuQuery.QueryCpus(out var failed64Bit, out var failedCpuCount); AvailableDevices.AddDevices(cpuDevs); // #2 CUDA OnProgressUpdate?.Invoke(null, Tr("Querying CUDA devices")); var nv = new NvidiaQuery(); var nvDevs = nv.QueryCudaDevices(); if (nvDevs != null) { AvailableDevices.NumDetectedNvDevs = nvDevs.Count; if (ConfigManager.GeneralConfig.DeviceDetection.DisableDetectionNVIDIA) { Helpers.ConsolePrint(Tag, "Skipping NVIDIA device detection, settings are set to disabled"); } else { AvailableDevices.AddDevices(nvDevs); } } // OpenCL and AMD var amd = new AmdQuery(AvailableDevices.NumDetectedNvDevs); // #3 OpenCL OnProgressUpdate?.Invoke(null, Tr("Querying OpenCL devices")); amd.QueryOpenCLDevices(); // #4 AMD query AMD from OpenCL devices, get serial and add devices OnProgressUpdate?.Invoke(null, Tr("Checking AMD OpenCL GPUs")); var amdDevs = amd.QueryAmd(out var failedAmdDriverCheck); if (amdDevs != null) { AvailableDevices.NumDetectedAmdDevs = amdDevs.Count; if (ConfigManager.GeneralConfig.DeviceDetection.DisableDetectionAMD) { Helpers.ConsolePrint(Tag, "Skipping AMD device detection, settings set to disabled"); } else { AvailableDevices.AddDevices(amdDevs); } } // #5 uncheck CPU if GPUs present, call it after we Query all devices AvailableDevices.UncheckCpuIfGpu(); // TODO update this to report undetected hardware // #6 check NVIDIA, AMD devices count bool nvCountMatched; { var amdCount = 0; var nvidiaCount = 0; foreach (var vidCtrl in SystemSpecs.AvailableVideoControllers) { if (vidCtrl.IsNvidia) { if (CudaUnsupported.IsSupported(vidCtrl.Name)) { nvidiaCount++; } else { Helpers.ConsolePrint(Tag, "Device not supported NVIDIA/CUDA device not supported " + vidCtrl.Name); } } else if (vidCtrl.IsAmd) { amdCount++; } } nvCountMatched = nvidiaCount == AvailableDevices.NumDetectedNvDevs; Helpers.ConsolePrint(Tag, nvCountMatched ? "Cuda NVIDIA/CUDA device count GOOD" : "Cuda NVIDIA/CUDA device count BAD!!!"); Helpers.ConsolePrint(Tag, amdCount == amdDevs?.Count ? "AMD GPU device count GOOD" : "AMD GPU device count BAD!!!"); } var result = new QueryResult(NvidiaMinDetectionDriver.ToString(), NvidiaRecomendedDriver.ToString()); var ramOK = CheckRam(); if (!ConfigManager.GeneralConfig.ShowDriverVersionWarning) { return(result); } if (SystemSpecs.HasNvidiaVideoController) { var currentDriver = WindowsManagementObjectSearcher.GetNvSmiDriver(); result.CurrentDriverString = currentDriver.ToString(); result.FailedMinNVDriver = !nvCountMatched && currentDriver < NvidiaMinDetectionDriver; result.FailedRecommendedNVDriver = currentDriver <NvidiaRecomendedDriver && currentDriver.LeftPart> -1; } result.NoDevices = AvailableDevices.Devices.Count <= 0; result.FailedRamCheck = !ramOK; foreach (var failedVc in badVidCtrls) { result.FailedVidControllerStatus = true; result.FailedVidControllerInfo += $"{Tr("Name: {0}, Status {1}, PNPDeviceID {2}", failedVc.Name, failedVc.Status, failedVc.PnpDeviceID)}\n"; } result.FailedAmdDriverCheck = failedAmdDriverCheck; result.FailedCpu64Bit = failed64Bit; result.FailedCpuCount = failedCpuCount; return(result); }