-
Notifications
You must be signed in to change notification settings - Fork 0
/
stripminer.py
executable file
·142 lines (120 loc) · 4.1 KB
/
stripminer.py
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
#!/usr/bin/env python
from multiprocessing import Process
from optparse import OptionParser
import ConfigParser
import os, sys
import logging, logging.config
import pyopencl as cl
from struct import *
from time import sleep, time, strftime
from datetime import datetime
from BitcoinMiner import *
try:
import ADL
except ImportError:
print "Missing the pyADL module needed for this to work."
print "pyADL can be found at: http://www.bitshift.io/pyADL/"
sys.exit(1)
os.chdir(os.path.dirname(os.path.abspath(__file__)))
VERSION = '2011.07.06'
USER_AGENT = 'stripminer/' + VERSION
def Miner(device, options):
log = logging.getLogger('GPU%d-MINER' % device)
log.info('Worker starting on device %d', device)
log.debug('Setting DISPLAY variable for device %d', device)
os.environ['DISPLAY'] = ':0.%d' % device
log.debug('Confirming environment: %s', os.environ['DISPLAY'])
log.debug('Checking that device is found now that DISPLAY is set')
platform = cl.get_platforms()[0]
devices = platform.get_devices()
class StripMiner(BitcoinMiner):
def say(self, format, args=()):
log.info(format % args)
def sayLine(self, format, args=()):
if(format == 'verification failed, check hardware!'):
log.warn(format % args)
else:
self.say(format, args)
try:
miner = StripMiner(devices[device],
options.host,
options.user,
options.password,
int(options.port),
int(options.frames),
float(options.rate),
int(options.askrate),
int(options.worksize),
bool(options.vectors),
bool(options.verbose))
miner.mine()
except:
log.info('Miner is exiting', device)
finally:
if miner: miner.exit()
def main():
oParser = OptionParser(version=USER_AGENT,
description='Bitcoin strip mining daemon')
oParser.add_option('-c', '--config', action='store',
dest='configfile', default='stripminer.cfg')
oParser.add_option('-p', '--pool', action='store',
dest='pool', default=None)
(options, args) = oParser.parse_args()
try:
cParser = ConfigParser.SafeConfigParser()
cParser.read([options.configfile, os.path.expanduser('~/.stripminer.cfg')])
except ConfigParser.ParsingError, err:
print 'Could not parse:', err
sys.exit(1)
# Define default settings
for opt, val in cParser.defaults().iteritems():
setattr(options, opt, val)
# Define pool specific values if specified and available
if cParser.has_section('pool_%s' % options.pool):
for opt in cParser.options('pool_%s' % options.pool):
setattr(options, opt, cParser.get('pool_%s' % options.pool, opt))
# Setup logging
logging.config.fileConfig('logging.conf')
log = logging.getLogger('stripminer')
# Collection GPU card information
log.info('Collecting available GPU information')
os.environ['DISPLAY'] = ':0'
devices = ADL.getNumGPU()
# Fire off mining workers for each device
processes = []
for device in devices:
gpuidx = device['GPU']
ADL.setIndex(gpuidx)
log.info('Device[GPU%d] %s (Core: %d, Memory: %d, Fan %d%%)',
gpuidx, device['Name'], ADL.getCoreClockSpeed(),
ADL.getMemoryClockSpeed(), ADL.getFanSpeed())
if cParser.has_section('ADL_GPU%d' % gpuidx):
log.debug('Found ADL settings for GPU%d', gpuidx)
if cParser.has_option('ADL_GPU%d' % gpuidx, 'core'):
core = cParser.getint('ADL_GPU%d' % gpuidx, 'core')
log.debug('Device[GPU%d] setting Core to %d Mhz', gpuidx, core)
ADL.setCoreClockSpeed(2, core)
if cParser.has_option('ADL_GPU%d' % gpuidx, 'memory'):
memory = cParser.getint('ADL_GPU%d' % gpuidx, 'memory')
log.debug('Device[GPU%d] setting Memory to %d Mhz', gpuidx, memory)
ADL.setMemoryClockSpeed(1, memory)
ADL.setMemoryClockSpeed(2, memory)
if cParser.has_option('ADL_GPU%d' % gpuidx, 'fan'):
fan = cParser.getint('ADL_GPU%d' % gpuidx, 'fan')
log.debug('Device[GPU%d] setting Fan to %d%%', gpuidx, fan)
ADL.setFanSpeed(fan)
p = Process(target=Miner, args=(gpuidx, options))
processes.append(p)
try:
for process in processes:
process.start()
process.join()
except KeyboardInterrupt:
log.info('Closing down the mine!')
finally:
for process in processes:
if process.is_alive():
process.terminate()
sleep(1.1)
if __name__ == '__main__':
main()