Skip to content

Commit

Permalink
Cleanup device code
Browse files Browse the repository at this point in the history
  • Loading branch information
DillonN committed Jan 17, 2018
1 parent e56eb5f commit a24087b
Show file tree
Hide file tree
Showing 30 changed files with 1,922 additions and 1,434 deletions.
11 changes: 0 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ dotnet_style_qualification_for_event = false:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:suggestion

# Naming
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Prefer "var" everywhere
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
Expand Down
10 changes: 5 additions & 5 deletions NiceHashMiner/Configs/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static void CreateBackup()
_benchmarkConfigsBackup = new Dictionary<string, DeviceBenchmarkConfig>();
foreach (var cDev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
{
_benchmarkConfigsBackup[cDev.UUID] = cDev.GetAlgorithmDeviceConfig();
_benchmarkConfigsBackup[cDev.Uuid] = cDev.GetAlgorithmDeviceConfig();
}
}

Expand All @@ -97,9 +97,9 @@ public static void RestoreBackup()
// restore benchmarks
foreach (var cDev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
{
if (_benchmarkConfigsBackup != null && _benchmarkConfigsBackup.ContainsKey(cDev.UUID))
if (_benchmarkConfigsBackup != null && _benchmarkConfigsBackup.ContainsKey(cDev.Uuid))
{
cDev.SetAlgorithmDeviceConfig(_benchmarkConfigsBackup[cDev.UUID]);
cDev.SetAlgorithmDeviceConfig(_benchmarkConfigsBackup[cDev.Uuid]);
}
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ public static void CommitBenchmarks()
{
foreach (var cDev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
{
var devUuid = cDev.UUID;
var devUuid = cDev.Uuid;
if (BenchmarkConfigFiles.ContainsKey(devUuid))
{
BenchmarkConfigFiles[devUuid].Commit(cDev.GetAlgorithmDeviceConfig());
Expand Down Expand Up @@ -174,7 +174,7 @@ public static void AfterDeviceQueryInitialization()
// create/init device benchmark configs files and configs
foreach (var cDev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
{
var keyUuid = cDev.UUID;
var keyUuid = cDev.Uuid;
BenchmarkConfigFiles[keyUuid] = new DeviceBenchmarkConfigFile(keyUuid);
// init
{
Expand Down
39 changes: 22 additions & 17 deletions NiceHashMiner/Devices/AmdGpuDevice.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NiceHashMiner.Devices {
namespace NiceHashMiner.Devices
{
[Serializable]
public class AmdGpuDevice {

public class AmdGpuDevice
{
public static readonly string DefaultParam = "--keccak-unroll 0 --hamsi-expand-big 4 --remove-disabled ";

public static readonly string TemperatureParam = " --gpu-fan 30-95 --temp-cutoff 95 --temp-overheat 90 " +
" --temp-target 75 --auto-fan --auto-gpu ";
" --temp-target 75 --auto-fan --auto-gpu ";

public int DeviceID { get { return (int)_openClSubset.DeviceID; } }
public int BusID { get { return (int)_openClSubset.AMD_BUS_ID; } }
public int DeviceID => (int) _openClSubset.DeviceID;
public int BusID => (int) _openClSubset.AMD_BUS_ID;
public string DeviceName; // init this with the ADL
public string UUID; // init this with the ADL, use PCI_VEN & DEV IDs
public ulong DeviceGlobalMemory { get { return _openClSubset._CL_DEVICE_GLOBAL_MEM_SIZE; } }
public ulong DeviceGlobalMemory => _openClSubset._CL_DEVICE_GLOBAL_MEM_SIZE;

//public bool UseOptimizedVersion { get; private set; }
private OpenCLDevice _openClSubset = new OpenCLDevice();
private readonly OpenCLDevice _openClSubset = new OpenCLDevice();

public readonly string InfSection; // has arhitecture string

// new drivers make some algorithms unusable 21.19.164.1 => driver not working with NeoScrypt and
public bool DriverDisableAlgos { get; private set; }
public bool DriverDisableAlgos { get; }

public string Codename { get { return _openClSubset._CL_DEVICE_NAME; } }
public string Codename => _openClSubset._CL_DEVICE_NAME;

public int AdapterIndex; // init this with the ADL
public int AdapterIndex; // init this with the ADL

public AmdGpuDevice(OpenCLDevice openClSubset, bool isOldDriver, string infSection, bool driverDisableAlgo) {
public AmdGpuDevice(OpenCLDevice openClSubset, bool isOldDriver, string infSection, bool driverDisableAlgo)
{
DriverDisableAlgos = driverDisableAlgo;
InfSection = infSection;
if (openClSubset != null) {
if (openClSubset != null)
{
_openClSubset = openClSubset;
}
// Check for optimized version
Expand All @@ -52,8 +56,9 @@ public AmdGpuDevice(OpenCLDevice openClSubset, bool isOldDriver, string infSecti
//}
}

public bool IsEtherumCapable() {
return _openClSubset._CL_DEVICE_GLOBAL_MEM_SIZE >= ComputeDevice.MEMORY_3GB;
public bool IsEtherumCapable()
{
return _openClSubset._CL_DEVICE_GLOBAL_MEM_SIZE >= ComputeDevice.Memory3Gb;
}
}
}
39 changes: 20 additions & 19 deletions NiceHashMiner/Devices/CPUUtils.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
using NiceHashMiner.Configs;
using NiceHashMiner.Enums;
using NiceHashMiner.Miners;
using System;
using System.Collections.Generic;
using System.Text;
using NiceHashMiner.Enums;

namespace NiceHashMiner.Devices {
public static class CPUUtils {
namespace NiceHashMiner.Devices
{
public static class CpuUtils
{
// this is the order we check and initialize if automatic
private static CPUExtensionType[] _detectOrder = new CPUExtensionType[] {
CPUExtensionType.AVX2_AES,
CPUExtensionType.AVX2,
CPUExtensionType.AVX_AES,
CPUExtensionType.AVX,
CPUExtensionType.AES,
CPUExtensionType.SSE2, // disabled
};
private static CPUExtensionType[] _detectOrder =
{
CPUExtensionType.AVX2_AES,
CPUExtensionType.AVX2,
CPUExtensionType.AVX_AES,
CPUExtensionType.AVX,
CPUExtensionType.AES,
CPUExtensionType.SSE2, // disabled
};

/// <summary>
/// HasExtensionSupport checks CPU extensions support, if type automatic just return false.
/// </summary>
/// <param name="type"></param>
/// <returns>False if type Automatic otherwise True if supported</returns>
private static bool HasExtensionSupport(CPUExtensionType type) {
switch (type) {
private static bool HasExtensionSupport(CPUExtensionType type)
{
switch (type)
{
case CPUExtensionType.AVX2_AES: return (CPUID.SupportsAVX2() == 1) && (CPUID.SupportsAES() == 1);
case CPUExtensionType.AVX2: return CPUID.SupportsAVX2() == 1;
case CPUExtensionType.AVX_AES: return (CPUID.SupportsAVX() == 1) && (CPUID.SupportsAES() == 1);
Expand Down Expand Up @@ -58,7 +58,8 @@ private static bool HasExtensionSupport(CPUExtensionType type) {
/// Checks if CPU mining is capable, CPU must have AES support
/// </summary>
/// <returns></returns>
public static bool IsCPUMiningCapable() {
public static bool IsCpuMiningCapable()
{
return HasExtensionSupport(CPUExtensionType.AES);
}
}
Expand Down
64 changes: 28 additions & 36 deletions NiceHashMiner/Devices/CUDA_Unsupported.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.Linq;

namespace NiceHashMiner.Devices {
public static class CUDA_Unsupported {
private static List<string> SM_1_0 = new List<string>() {
namespace NiceHashMiner.Devices
{
public static class CudaUnsupported
{
private static readonly List<string> SM10 = new List<string>
{
"GeForce 8800 Ultra",
"GeForce 8800 GTX",
"GeForce 8800 GTS",
Expand All @@ -15,7 +17,9 @@ public static class CUDA_Unsupported {
"Tesla D870",
"Tesla S870",
};
private static List<string> SM_1_1 = new List<string>() {

private static readonly List<string> SM11 = new List<string>
{
"GeForce GTS 250",
"GeForce 9800 GX2",
"GeForce 9800 GTX",
Expand All @@ -32,7 +36,8 @@ public static class CUDA_Unsupported {
"GeForce 9300M GS",
"GeForce 9200M GS",
"GeForce 9100M G",
"GeForce 8400M GT","GeForce G105M",
"GeForce 8400M GT",
"GeForce G105M",
"Quadro FX 4700 X2",
"Quadro FX 3700",
"Quadro FX 1800",
Expand Down Expand Up @@ -69,7 +74,9 @@ public static class CUDA_Unsupported {
"Quadro NVS 420",
"Quadro NVS 295",
};
private static List<string> SM_1_2 = new List<string>() {

private static readonly List<string> SM12 = new List<string>
{
"GeForce GT 340",
"GeForce GT 330",
"GeForce GT 320",
Expand Down Expand Up @@ -98,7 +105,9 @@ public static class CUDA_Unsupported {
"NVS 2100M",
"ION",
};
private static List<string> SM_1_3 = new List<string>() {

private static readonly List<string> SM13 = new List<string>
{
"GeForce GTX 295",
"GTX 285",
"GTX 280",
Expand All @@ -113,7 +122,9 @@ public static class CUDA_Unsupported {
"Tesla S1070",
"Tesla M1060",
};
private static List<string> SM_2_0 = new List<string>() {

private static readonly List<string> SM20 = new List<string>
{
"GeForce GTX 590",
"GeForce GTX 580",
"GeForce GTX 570",
Expand All @@ -136,33 +147,14 @@ public static class CUDA_Unsupported {
"Tesla M2090",
};

private static bool ContainsSM(List<string> list, string text) {
foreach(var el in list) {
if(text.Contains(el)) {
return true;
}
}
return false;
private static bool ContainsSM(IEnumerable<string> list, string text)
{
return list.Any(text.Contains);
}

public static bool IsSupported(string text) {
if (ContainsSM(SM_1_0, text)) {
return false;
}
if (ContainsSM(SM_1_1, text)) {
return false;
}
if (ContainsSM(SM_1_2, text)) {
return false;
}
if (ContainsSM(SM_1_3, text)) {
return false;
}
if (ContainsSM(SM_2_0, text)) {
return false;
}

return true;
public static bool IsSupported(string text)
{
return !ContainsSM(SM10, text) && !ContainsSM(SM11, text) && !ContainsSM(SM12, text) && !ContainsSM(SM13, text) && !ContainsSM(SM20, text);
}
}
}
Loading

0 comments on commit a24087b

Please sign in to comment.