-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprofiler.py
More file actions
executable file
·260 lines (231 loc) · 8.07 KB
/
profiler.py
File metadata and controls
executable file
·260 lines (231 loc) · 8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#! /usr/bin/env python3
# Copyright (c) 2014, HashFast Technologies LLC
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of HashFast Technologies LLC nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL HASHFAST TECHNOLOGIES LLC BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import argparse
def parse_args():
parser = argparse.ArgumentParser(description='Profile HashFast boards in order to find optimal operating points.')
parser.add_argument('-r', '--revision', dest='revision', type=int, default=3, help='HashFast board major revision number')
return parser.parse_args()
if __name__ == '__main__':
# parse args before other imports
args = parse_args()
if args.revision is 3:
FRQ_MIN = 925
VLT_MIN = 900
else:
FRQ_MIN = 500
VLT_MIN = 720
# frequency steps
FRQ_STEP = 25
# voltage steps
VLT_STEP = 5
import sys
import time
import threading
import csv
from collections import OrderedDict
from abc import ABCMeta, abstractmethod
from datetime import datetime
from hf.ui.base import BaseUI
from hf.load import hf
from hf.load import talkusb
from hf.load.routines import settings
from hf.load.routines import thermal
from hf.usb import usbbulk
from hf.usb import usbctrl
fn = OrderedDict([('die',None),('frequency',None),('voltage',None),('hashrate',None),('hashes',None),('jobs',None),('nonces',None),
('lhw',None),('dhw',None),('chw',None),('temperature',None),('core_voltage',None),('thermal_cutoff',None),('elapsed',None)])
class HFProfilerData:
def __init__(self):
pass
class HFProfilerBase(object):
def __init__(self):
pass
class HFProfilerInteractive(HFProfilerBase):
def __init__(self):
self.frequency = [None]*4
self.voltage = [None]*4
self.csvfilename = 'profiler_{}.csv'.format(int(time.time()))
with open(self.csvfilename, 'w') as csvfile:
csvwriter = csv.DictWriter(csvfile, fn, extrasaction='ignore')
csvwriter.writeheader()
def start(self, ui, dev):
talkusb.talkusb(hf.INIT, None, 0);
self.test(ui, dev)
def test(self, ui, dev):
option = ui.prompt_int_single("Option? 0=PROM 1=DEFAULTS")
if option is 1:
self.frequency = [FRQ_MIN]*4
self.voltage = [VLT_MIN]*4
while True:
try:
time.sleep(1)
# do settings for this round
self.set(ui)
# wait for settings to be applied
time.sleep(3)
# run test
self.run(ui, dev, option)
for x in range(4):
do = ui.prompt_int_single("Die {}? 0:SAME 1:VU 2:VD 3:FU 4:FD".format(x+1))
if do is 1:
self.voltage[x] += VLT_STEP
elif do is 2:
self.voltage[x] -= VLT_STEP
elif do is 3:
self.frequency[x] += FRQ_STEP
elif do is 4:
self.frequency[x] -= FRQ_STEP
else:
return 0
except KeyboardInterrupt:
ui.log("exiting")
ui.end()
return
except:
ui.log("Error")
def set(self, ui):
ui.prompt_show("Updating Die Settings")
talkusb.talkusb(hf.INIT, None, 0)
setter = settings.SettingsRoutine(talkusb.talkusb, 1, ui.log)
for x in range(4):
frq = self.frequency[x]
vlt = self.voltage[x]
if frq is None or vlt is None:
return None
else:
setter.setup(x, frq, vlt)
# run
rslt = True
while rslt:
rslt = setter.one_cycle()
# wait for settings to be applied
time.sleep(3)
def vset(self, ui, dev):
for x in range(4):
vlt = self.voltage[x]
dev.voltage_set(0, x, vlt)
time.sleep(0.1)
def run(self, ui, dev, option):
talkusb.talkusb(hf.INIT, None, 0)
self.test = thermal.ThermalRoutine(talkusb.talkusb, 1, ui.log, deterministic=True)
ui.prompt_show("Running option "+str(option)+". Press board 'RESET' or ctrl+c to end.")
self.cr = ui.current_round
self.cr.clockrate = option
rslt = True
# thread
thread = threading.Thread(target=self.monitor_temp, args={ui})
self.running = True
#thread.daemon = True
thread.start()
# run
while rslt:
rslt = self.test.one_cycle()
if self.req_stop is True:
self.test.end()
rslt = False
# record current voltage and frequency
for x in range(4):
if self.test.dies[x] is not None:
die = self.test.dies[x]
if die['voltage'] is not None:
self.voltage[x] = die['voltage']
if die['frequency'] is not None:
self.frequency[x] = die['frequency']
# write logfile
with open(self.csvfilename, 'a') as csvfile:
csvwriter = csv.DictWriter(csvfile, fn, extrasaction='ignore')
for x in range(4):
if self.test.dies[x] is not None:
die = self.test.dies[x]
csvwriter.writerow(die)
#if rslt is -2:
# self.run(ui, dev, clockrate)
# cycle loop complete
#ui.prompt_enter("Round Complete. Check temperature.")
self.running = False
# wait for board to reset
time.sleep(3)
def monitor_temp(self, ui):
runtime = 0
self.req_stop = False
while self.running:
time.sleep(0.5)
runtime += 0.5
if runtime > 180: # three minutes
self.req_stop = True
self.cr.total_hashes = self.test.stats['hashes']
self.cr.total_errors = self.test.stats['lhw']
self.cr.hash_rate = self.test.stats['hashrate']
self.cr.stats = self.test.stats
if self.test.dies is not None:
for dinfo in ui.die_info:
if dinfo is not None:
die = self.test.dies[dinfo.index]
if die is not None:
dinfo.die = die
if self.voltage[dinfo.index] is not None:
die['voltage'] = self.voltage[dinfo.index]
dinfo.thermal_cutoff = die['thermal_cutoff']
dinfo.active = die['active']
dinfo.pending = die['pending']
dinfo.temp = die['temperature']
dinfo.vm = die['core_voltage']
def input(self, msg):
pass
class HFProfilerUI(BaseUI):
def setup_ui(self):
# column 0
self.setup_log( 0, 0, w=4)
# column 4
self.setup_logo( 4, 1, "HashFast Profiling Tool", "v0.1")
self.setup_input( 4, 8 )
self.setup_output( 4, 12)
self.setup_expmodule( 4, 16, coremap=0)
self.setup_stats( 4, 42)
# column 9
self.setup_info( 9, 1 )
def update_ui(self):
self.update_module()
self.update_expmodule()
self.update_info()
self.update_current()
def refresh_ui(self):
pass
def main(args):
ui = HFProfilerUI()
try:
ui.setup()
ui.refresh()
ui.prompt_show("Please connect device.")
dev = usbctrl.poll_hf_ctrl_device(printer=ui.log)
ret = ui.prompt("HashFast Profiling Tool. Press 's' to start", "s")
if ret:
profiler = HFProfilerInteractive()
profiler.start(ui, dev)
finally:
ui.end()
if __name__ == "__main__":
main(args)