Guest User

Untitled

a guest
Nov 23rd, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import os
  2. import time
  3. import subprocess as sp
  4.  
  5. algos = [
  6. "bitcoin",
  7. "blake",
  8. "blakecoin",
  9. "c11",
  10. "deep",
  11. "dmd-gr",
  12. "doom",
  13. "fresh",
  14. "fugue256",
  15. "groestl",
  16. "keccak",
  17. "jackpot",
  18. "luffa",
  19. "lyra2v2",
  20. "myr-gr",
  21. "nist5",
  22. "penta",
  23. "quark",
  24. "qubit",
  25. "sia",
  26. "skein",
  27. "s3",
  28. "whirl",
  29. "whirlpoolx",
  30. "x11",
  31. "x13",
  32. "x14",
  33. "x15",
  34. "x17",
  35. "vanilla",
  36. "neoscrypt"
  37. ]
  38.  
  39. GPU_IDX = 0
  40. MAX_TIME = 60
  41.  
  42. speed_mult = {"gh/s": 10**9, "mh/s": 10**6, "kh/s": 10*3, "h/s": 1}
  43.  
  44. def parse(stdout, stderr):
  45. data = []
  46. for line in stderr.splitlines():
  47. try:
  48. speed, unit = line.split("] Total: ", 1)[1].strip().split(" ")
  49. speed = int(float(speed) * speed_mult[unit.lower()])
  50. data.append(speed)
  51. except IndexError:
  52. continue
  53. except KeyError:
  54. print(stdout)
  55. print(stderr)
  56. exit(-1)
  57. return data
  58.  
  59.  
  60. def run(command, verbose=None):
  61. proc = sp.Popen(command.split(" "), stdout=sp.PIPE, stderr=sp.PIPE)
  62. if verbose:
  63. print('Started:', command, '(pid = ' + str(proc.pid) + ')')
  64. result = proc.communicate()
  65. return map(bytes.decode, result)
  66.  
  67.  
  68. def benchmark():
  69. nvidia_cmd = "nvidia-smi --query-gpu=pci.bus_id,enforced.power.limit,clocks.sm,clocks.mem --format=csv,noheader,nounits -i %d" % GPU_IDX
  70.  
  71. for algo in set(algos):
  72. command = "timeout %(timeout)ds ./ccminer -d %(gpu_idx)d --benchmark -t 1 -a %(algo)s -q --no-color --no-cpu-verify" % dict(
  73. timeout=MAX_TIME,
  74. gpu_idx=GPU_IDX,
  75. algo=algo
  76. )
  77.  
  78. try:
  79. stdout, stderr = run(command, verbose=True)
  80. hashrates = parse(stdout, stderr)
  81. hashrate = max(hashrates)
  82. except KeyboardInterrupt:
  83. break
  84. except Exception as e:
  85. print("%s fail: %s" % (algo, e))
  86. continue
  87.  
  88. nv_out, _ = run(nvidia_cmd)
  89. result = [algo] + [x.strip() for x in nv_out.split(", ") if x.strip()] + [str(hashrate)]
  90.  
  91. with open("benchmarks.csv", "a+") as f:
  92. f.write(";".join(result) + "\n")
  93.  
  94. print(result)
  95. print()
  96. time.sleep(5)
  97.  
  98. benchmark()
Add Comment
Please, Sign In to add comment