Пример #1
0
    def __init__(self, interface):
        platforms = cl.get_platforms()

        # Initialize object attributes and retrieve command-line options...)
        self.device = None
        self.kernel = None
        self.interface = interface
        self.core = self.interface.addCore()
        self.defines = ''
        self.loopExponent = 0

        # Set the initial number of nonces to run per execution
        # 2^(16 + aggression)
        self.AGGRESSION += 16
        self.AGGRESSION = min(32, self.AGGRESSION)
        self.AGGRESSION = max(16, self.AGGRESSION)
        self.size = 1 << self.AGGRESSION

        # We need a QueueReader to efficiently provide our dedicated thread
        # with work.
        self.qr = QueueReader(self.core, lambda nr: self.preprocess(nr),
                                lambda x,y: self.size * 1 << self.loopExponent)

        # The platform selection must be valid to mine.
        if self.PLATFORM >= len(platforms) or \
            (self.PLATFORM is None and len(platforms) > 1):
            self.interface.log(
                'Wrong platform or more than one OpenCL platform found, '
                'use PLATFORM=ID to select one of the following\n',
                False, True)

            for i,p in enumerate(platforms):
                self.interface.log('    [%d]\t%s' % (i, p.name), False, False)

            # Since the platform is invalid, we can't mine.
            self.interface.fatal()
            return
        elif self.PLATFORM is None:
            self.PLATFORM = 0

        devices = platforms[self.PLATFORM].get_devices()

        # The device selection must be valid to mine.
        if self.DEVICE >= len(devices) or \
            (self.DEVICE is None and len(devices) > 1):
            self.interface.log(
                'No device specified or device not found, '
                'use DEVICE=ID to specify one of the following\n',
                False, True)

            for i,d in enumerate(devices):
                self.interface.log('    [%d]\t%s' % (i, d.name), False, False)

            # Since the device selection is invalid, we can't mine.
            self.interface.fatal()
            return
        elif self.DEVICE is None:
            self.DEVICE = 0

        self.device = devices[self.DEVICE]

        # We need the appropriate kernel for this device...
        try:
            self.loadKernel(self.device)
        except Exception:
            self.interface.fatal("Failed to load OpenCL kernel!")
            return

        # Initialize a command queue to send commands to the device, and a
        # buffer to collect results in...
        self.commandQueue = cl.CommandQueue(self.context)
        self.output = np.zeros(self.OUTPUT_SIZE+1, np.uint32)
        self.output_buf = cl.Buffer(
            self.context, cl.mem_flags.WRITE_ONLY | cl.mem_flags.USE_HOST_PTR,
            hostbuf=self.output)

        self.applyMeta()