Skip to content

Commit

Permalink
Add X-Work-Identifier support to RPC for better compatibility with P2…
Browse files Browse the repository at this point in the history
…Pool.

Tweaked kernel worksize validation.
Bump version to 1.7.4

Signed-off-by: jedi95 <jedi95@gmail.com>
  • Loading branch information
jedi95 committed Jan 21, 2012
1 parent 297945a commit 8263f65
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 40 deletions.
4 changes: 2 additions & 2 deletions WorkQueue.py
Expand Up @@ -94,12 +94,12 @@ def storeWork(self, wu):
work.base = 0

#check if there is a new block, if so reset queue
newBlock = (wu.data[4:36] != self.block)
newBlock = (wu.identifier != self.block)
if newBlock:
self.queue.clear()
self.currentUnit = None
self.lastBlock = self.block
self.block = wu.data[4:36]
self.block = wu.identifier
self.logger.reportDebug("New block (WorkQueue)")

#clear the idle flag since we just added work to queue
Expand Down
22 changes: 11 additions & 11 deletions kernels/phatk/__init__.py
Expand Up @@ -210,7 +210,7 @@ def __init__(self, interface):
try:
self.loadKernel(self.device)
except Exception:
self.interface.fatal("Failed to load OpenCL kernel!")
self.interface.fatal('Failed to load OpenCL kernel!')
return

# Initialize a command queue to send commands to the device, and a
Expand All @@ -236,18 +236,18 @@ def loadKernel(self, device):
# get the maximum worksize of the device
maxWorkSize = self.device.get_info(cl.device_info.MAX_WORK_GROUP_SIZE)

# If the user didn't specify their own worksize, use the maximum supported worksize of the device
# If the user didn't specify their own worksize,
# use the maximum supported worksize of the device
if self.WORKSIZE is None:
self.interface.error('WORKSIZE not supplied, using HW max. of ' + str(maxWorkSize))
self.interface.debug('WORKSIZE not supplied, using HW max. of '
+ str(maxWorkSize))
self.WORKSIZE = maxWorkSize
else:
# If the worksize is larger than the maximum supported worksize of the device
# If the worksize is larger than the maximum supported
# worksize of the device
if (self.WORKSIZE > maxWorkSize):
self.interface.error('WORKSIZE out of range, using HW max. of ' + str(maxWorkSize))
self.WORKSIZE = maxWorkSize
# If the worksize is not a power of 2
if (self.WORKSIZE & (self.WORKSIZE - 1)) != 0:
self.interface.error('WORKSIZE invalid, using HW max. of ' + str(maxWorkSize))
self.interface.error('WORKSIZE out of range, using HW max. of '
+ str(maxWorkSize))
self.WORKSIZE = maxWorkSize

# These definitions are required for the kernel to function.
Expand Down Expand Up @@ -304,7 +304,7 @@ def loadKernel(self, device):
patcher = BFIPatcher(self.interface)
binaryData = patcher.patch(self.kernel.binaries[0])

self.interface.debug("Applied BFI_INT patch")
self.interface.debug('Applied BFI_INT patch')

#reload the kernel with the patched binary
self.kernel = cl.Program(
Expand All @@ -321,7 +321,7 @@ def loadKernel(self, device):
self.context, [device], [binaryData]).build(self.defines)

except cl.LogicError:
self.interface.fatal("Failed to compile OpenCL kernel!")
self.interface.fatal('Failed to compile OpenCL kernel!')
return
except PatchError:
self.interface.fatal('Failed to apply BFI_INT patch to kernel! '
Expand Down
22 changes: 11 additions & 11 deletions kernels/phatk2/__init__.py
Expand Up @@ -216,7 +216,7 @@ def __init__(self, interface):
try:
self.loadKernel(self.device)
except Exception:
self.interface.fatal("Failed to load OpenCL kernel!")
self.interface.fatal('Failed to load OpenCL kernel!')
return

# Initialize a command queue to send commands to the device, and a
Expand All @@ -242,18 +242,18 @@ def loadKernel(self, device):
# get the maximum worksize of the device
maxWorkSize = self.device.get_info(cl.device_info.MAX_WORK_GROUP_SIZE)

# If the user didn't specify their own worksize, use the maximum supported worksize of the device
# If the user didn't specify their own worksize,
# use the maximum supported worksize of the device
if self.WORKSIZE is None:
self.interface.error('WORKSIZE not supplied, using HW max. of ' + str(maxWorkSize))
self.interface.debug('WORKSIZE not supplied, using HW max. of '
+ str(maxWorkSize))
self.WORKSIZE = maxWorkSize
else:
# If the worksize is larger than the maximum supported worksize of the device
# If the worksize is larger than the maximum supported
# worksize of the device
if (self.WORKSIZE > maxWorkSize):
self.interface.error('WORKSIZE out of range, using HW max. of ' + str(maxWorkSize))
self.WORKSIZE = maxWorkSize
# If the worksize is not a power of 2
if (self.WORKSIZE & (self.WORKSIZE - 1)) != 0:
self.interface.error('WORKSIZE invalid, using HW max. of ' + str(maxWorkSize))
self.interface.error('WORKSIZE out of range, using HW max. of '
+ str(maxWorkSize))
self.WORKSIZE = maxWorkSize

# These definitions are required for the kernel to function.
Expand Down Expand Up @@ -317,7 +317,7 @@ def loadKernel(self, device):
patcher = BFIPatcher(self.interface)
binaryData = patcher.patch(self.kernel.binaries[0])

self.interface.debug("Applied BFI_INT patch")
self.interface.debug('Applied BFI_INT patch')

#reload the kernel with the patched binary
self.kernel = cl.Program(
Expand All @@ -334,7 +334,7 @@ def loadKernel(self, device):
self.context, [device], [binaryData]).build(self.defines)

except cl.LogicError:
self.interface.fatal("Failed to compile OpenCL kernel!")
self.interface.fatal('Failed to compile OpenCL kernel!')
return
except PatchError:
self.interface.fatal('Failed to apply BFI_INT patch to kernel! '
Expand Down
22 changes: 11 additions & 11 deletions kernels/poclbm/__init__.py
Expand Up @@ -193,7 +193,7 @@ def __init__(self, interface):
try:
self.loadKernel(self.device)
except Exception:
self.interface.fatal("Failed to load OpenCL kernel!")
self.interface.fatal('Failed to load OpenCL kernel!')
return

# Initialize a command queue to send commands to the device, and a
Expand All @@ -219,18 +219,18 @@ def loadKernel(self, device):
# get the maximum worksize of the device
maxWorkSize = self.device.get_info(cl.device_info.MAX_WORK_GROUP_SIZE)

# If the user didn't specify their own worksize, use the maximum supported worksize of the device
# If the user didn't specify their own worksize,
# use the maximum supported worksize of the device
if self.WORKSIZE is None:
self.interface.error('WORKSIZE not supplied, using HW max. of ' + str(maxWorkSize))
self.interface.debug('WORKSIZE not supplied, using HW max. of '
+ str(maxWorkSize))
self.WORKSIZE = maxWorkSize
else:
# If the worksize is larger than the maximum supported worksize of the device
# If the worksize is larger than the maximum supported
# worksize of the device
if (self.WORKSIZE > maxWorkSize):
self.interface.error('WORKSIZE out of range, using HW max. of ' + str(maxWorkSize))
self.WORKSIZE = maxWorkSize
# If the worksize is not a power of 2
if (self.WORKSIZE & (self.WORKSIZE - 1)) != 0:
self.interface.error('WORKSIZE invalid, using HW max. of ' + str(maxWorkSize))
self.interface.error('WORKSIZE out of range, using HW max. of '
+ str(maxWorkSize))
self.WORKSIZE = maxWorkSize

# These definitions are required for the kernel to function.
Expand Down Expand Up @@ -291,7 +291,7 @@ def loadKernel(self, device):
patcher = BFIPatcher(self.interface)
binaryData = patcher.patch(self.kernel.binaries[0])

self.interface.debug("Applied BFI_INT patch")
self.interface.debug('Applied BFI_INT patch')

#reload the kernel with the patched binary
self.kernel = cl.Program(
Expand All @@ -308,7 +308,7 @@ def loadKernel(self, device):
self.context, [device], [binaryData]).build(self.defines)

except cl.LogicError:
self.interface.fatal("Failed to compile OpenCL kernel!")
self.interface.fatal('Failed to compile OpenCL kernel!')
return
except PatchError:
self.interface.fatal('Failed to apply BFI_INT patch to kernel! '
Expand Down
1 change: 1 addition & 0 deletions minerutil/ClientBase.py
Expand Up @@ -27,6 +27,7 @@ class AssignedWork(object):
target = None
maxtime = None
time = None
identifier = None
def setMaxTimeIncrement(self, n):
self.time = n
self.maxtime = struct.unpack('>I', self.data[68:72])[0] + n
Expand Down
1 change: 1 addition & 0 deletions minerutil/MMPProtocol.py
Expand Up @@ -143,6 +143,7 @@ def cmd_WORK(self, work, mask):
wu.mask = mask
wu.target = self.target
wu.setMaxTimeIncrement(self.time)
wu.identifier = data[4:36]
self.runCallback('work', wu)
# Since the server is giving work, we know it has accepted our
# login details, so we can reset the factory's reconnect delay.
Expand Down
13 changes: 8 additions & 5 deletions minerutil/RPCProtocol.py
Expand Up @@ -180,7 +180,8 @@ def call(self, method, params=[]):
{
'Authorization': self.root.auth,
'User-Agent': self.root.version,
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'X-Work-Identifier': '1'
})

(headers, data) = response
Expand All @@ -206,10 +207,10 @@ class LongPoller(HTTPBase):
callback function.
"""

#Changed to 1800, since 600 seconds will cause it to reconnect
#Changed to 3600, since 600 seconds will cause it to reconnect
#once every 10 minutes. Most pools will not cancel a long poll if the block
#exceeds 10 minutes. 30 minutes should be a sane value for this.
timeout = 1800
#exceeds 10 minutes. 60 minutes should be a sane value for this.
timeout = 3600

def __init__(self, url, root):
self.url = url
Expand All @@ -235,7 +236,8 @@ def _request(self):
None,
{
'Authorization': self.root.auth,
'User-Agent': self.root.version
'User-Agent': self.root.version,
'X-Work-Identifier': '1'
})
d.addBoth(self._requestComplete)

Expand Down Expand Up @@ -425,6 +427,7 @@ def handleWork(self, work, headers, pushed=False):
aw.target = work['target'].decode('hex')
aw.mask = work.get('mask', 32)
aw.setMaxTimeIncrement(maxtime)
aw.identifier = work.get('identifier', aw.data[4:36])
if pushed:
self.runCallback('push', aw)
self.runCallback('work', aw)
Expand Down

0 comments on commit 8263f65

Please sign in to comment.