import numpy from struct import pack, unpack import time import hashlib import pyopencl as cl 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('kernel.cl', 'r') fstr = ''.join(f.readlines()) program = cl.Program(ctx, fstr).build() except: ctx = False def has_opencl(): return (ctx != False) def do_opencl_pow(hash, target): output = numpy.zeros(1, dtype=[('v', numpy.uint64, 1)]) if (ctx == False): return output[0][0] data = numpy.zeros(1, dtype=hash_dt, order='C') data[0]['v'] = ("0000000000000000" + hash).decode("hex") data[0]['target'] = target hash_buf = cl.Buffer(ctx, cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=data) 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]) kernel.set_arg(0, hash_buf) kernel.set_arg(1, dest_buf) start = time.time() startpos = 0 globamt = worksize*2000 while output[0][0] == 0: kernel.set_arg(2, pack("Q',hashlib.sha512(hashlib.sha512(pack('>Q',nonce) + initialHash).digest()).digest()[0:8]) print "{} - value {} < {}".format(nonce, trialValue, target)