GpuName.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. namespace NTMiner.Core.Gpus {
  2. public class GpuName : IGpuName {
  3. public static bool IsValidTotalMemory(ulong value) {
  4. return value >= 4 * NTKeyword.ULongG;
  5. }
  6. public static string Format(GpuType gpuType, string gpuName, ulong totalMemory) {
  7. ulong totalMemoryGb = (totalMemory + NTKeyword.ULongG - 1) / NTKeyword.ULongG;
  8. // 通常显卡的名称上会带显存大小,比如1060分3G版和6G版所以NVIDIA命名显卡的时候
  9. // 已经带上了显存信息,但不能假定带了显存信息所以这里拼接上显存信息。
  10. return $"{gpuType.GetName()}///{gpuName}///{totalMemoryGb.ToString()}";
  11. }
  12. public GpuName() { }
  13. public GpuType GpuType { get; set; }
  14. public string Name { get; set; }
  15. public ulong TotalMemory { get; set; }
  16. public bool IsValid() {
  17. return GpuType != GpuType.Empty && !string.IsNullOrEmpty(Name) && IsValidTotalMemory(TotalMemory);
  18. }
  19. public override bool Equals(object obj) {
  20. if (obj == null) {
  21. return false;
  22. }
  23. return this.ToString() == obj.ToString(); ;
  24. }
  25. public override int GetHashCode() {
  26. return this.ToString().GetHashCode();
  27. }
  28. /// <summary>
  29. /// 该ToString字符串会被作为redis key使用
  30. /// </summary>
  31. /// <returns></returns>
  32. public override string ToString() {
  33. return Format(this.GpuType, this.Name, this.TotalMemory);
  34. }
  35. }
  36. }