OpenCL Fixes

Still not fully working and hardcoded device number
This commit is contained in:
mailchuck 2015-10-02 15:04:16 +02:00 committed by Peter Surda
parent 8043f1ae60
commit 9075f3f5e6
2 changed files with 22 additions and 20 deletions

View File

@ -1,31 +1,28 @@
import numpy
#!/usr/bin/env python2.7
from struct import pack, unpack
import time
import hashlib
import random
import pyopencl as cl
import os
hash_dt = numpy.dtype([('target', numpy.uint64), ('v', numpy.str_, 73)])
ctx = False
queue = False
program = False
try:
if (len(cl.get_platforms()) > 0):
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
#f = open('/usr/src/PyBitmessage/src/kernel.cl', 'r')
import os
print "working directory: " + os.getcwd()
# time.sleep(5)
f = open('kernel.cl', 'r')
fstr = ''.join(f.readlines())
program = cl.Program(ctx, fstr).build()
import numpy
import pyopencl as cl
hash_dt = numpy.dtype([('target', numpy.uint64), ('v', numpy.str_, 73)])
if (len(cl.get_platforms()) > 0):
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
full_path = os.path.dirname(os.path.realpath(__file__))
f = open(os.path.join(full_path, 'kernel.cl'), 'r')
fstr = ''.join(f.readlines())
program = cl.Program(ctx, fstr).build(options="")
except Exception as e:
print "opencl fail:" + str(e)
# time.sleep(5)
ctx = False
print "opencl fail:" + str(e)
ctx = False
def has_opencl():
return (ctx != False)
@ -43,7 +40,7 @@ def do_opencl_pow(hash, target):
dest_buf = cl.Buffer(ctx, cl.mem_flags.WRITE_ONLY, output.nbytes)
kernel = program.kernel_sha512
worksize = kernel.get_work_group_info(cl.kernel_work_group_info.WORK_GROUP_SIZE, cl.get_platforms()[0].get_devices()[0])
worksize = kernel.get_work_group_info(cl.kernel_work_group_info.WORK_GROUP_SIZE, cl.get_platforms()[0].get_devices()[1])
kernel.set_arg(0, hash_buf)
kernel.set_arg(1, dest_buf)

View File

@ -73,7 +73,7 @@ def _doFastPoW(target, initialHash):
return result[0], result[1]
time.sleep(0.2)
def _doGPUPow(target, initialHash):
def _doGPUPoW(target, initialHash):
print "GPU POW\n"
nonce = openclpow.do_opencl_pow(initialHash.encode("hex"), target)
trialValue, = unpack('>Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8])
@ -83,7 +83,12 @@ def _doGPUPow(target, initialHash):
def run(target, initialHash):
target = int(target)
if shared.safeConfigGetBoolean('bitmessagesettings', 'opencl') and openclpow.has_opencl():
return _doGPUPow(target, initialHash)
# trialvalue1, nonce1 = _doGPUPoW(target, initialHash)
# trialvalue, nonce = _doFastPoW(target, initialHash)
# print "GPU: %s, %s" % (trialvalue1, nonce1)
# print "Fast: %s, %s" % (trialvalue, nonce)
# return [trialvalue, nonce]
return _doGPUPoW(target, initialHash)
elif frozen == "macosx_app" or not frozen:
return _doFastPoW(target, initialHash)
else: