Beispiel #1
0
def run(n, ps, num_runs, queues):
    LOG.info('n: %d', n)
    shape = (n, n)
    distance = 5 * q.m
    material = make_fromfile(
        os.path.join('examples', 'data', 'pmma_5_30_kev.mat'))
    energies = np.linspace(material.energies[0].magnitude,
                           material.energies[-1].magnitude,
                           100,
                           endpoint=False) * material.energies.units
    spheres = {
        queue: make_sphere(n,
                           n / 4 * ps,
                           pixel_size=ps,
                           material=material,
                           queue=queue)
        for queue in queues
    }

    durations = []
    for i in range(num_runs):
        st = time.time()
        gutil.qmap(propagate_one,
                   range(len(queues)),
                   queues=queues,
                   args=(shape, energies, distance, ps, spheres))
        durations.append((time.time() - st) / len(queues))
        LOG.info('%d. run, duration: %.2f s', i + 1, durations[-1])

    mean = np.mean(durations)
    std = np.std(durations)
    LOG.info('Mean duration: %.2f s', mean)
    LOG.info('std: %.2f s', std)

    return mean, std
Beispiel #2
0
def run(n, ps, num_runs, queues):
    LOG.info('n: %d', n)
    shape = (n, n)
    distance = 5 * q.m
    material = make_fromfile(os.path.join('examples', 'data', 'pmma_5_30_kev.mat'))
    energies = np.linspace(material.energies[0].magnitude,
                           material.energies[-1].magnitude,
                           100, endpoint=False) * material.energies.units
    spheres = {queue: make_sphere(n, n / 4 * ps, pixel_size=ps, material=material, queue=queue)
               for queue in queues}

    durations = []
    for i in range(num_runs):
        st = time.time()
        gutil.qmap(propagate_one, range(len(queues)), queues=queues,
                   args=(shape, energies, distance, ps, spheres))
        durations.append((time.time() - st) / len(queues))
        LOG.info('%d. run, duration: %.2f s', i + 1, durations[-1])

    mean = np.mean(durations)
    std = np.std(durations)
    LOG.info('Mean duration: %.2f s', mean)
    LOG.info('std: %.2f s', std)

    return mean, std
Beispiel #3
0
def make_tiles(func,
               shape,
               tile_shape,
               iterable=None,
               outlier=(0, 0),
               queues=None,
               args=(),
               kwargs=None):
    """Make tiles using *func* which can either have signature func(item, *args, **kwargs) or
    func(item, queue, *args, **kwargs), where queue is the OpenCL command queue. In the latter case,
    multiple command queues are mapped to different computation items. *shape* (y, x) is the final
    image shape, *tile_shape* (y, x) is the shape of one tile, *iterable* is the sequence to be
    mapped to *func*, if not specified, the offsets from :func:`.make_tile_offsets` are used.
    *outlier* (y, x) is the amount of overlapping region between tiles, *queues* are the OpenCL
    command queues to use, *args* and *kwargs* are additional arguments passed to *func*. Returns a
    generator.
    """
    if iterable is None:
        iterable = make_tile_offsets(shape, tile_shape, outlier=outlier)
    if kwargs is None:
        kwargs = {}

    if queues is None:
        return (func(item, *args, **kwargs) for item in iterable)
    else:
        # Use multiple comand queues
        return (item for item in g_util.qmap(
            func, iterable, queues=queues, args=args, kwargs=kwargs))
Beispiel #4
0
def run(n, m, complexity, prg, verbose=False):
    devices = cfg.OPENCL.devices
    queues = cfg.OPENCL.queues

    stop = int(m**complexity)
    complexity_fmt = 'complexity: {} x {}^{}, pixel operations: {}'
    if verbose:
        print complexity_fmt.format(n, m, complexity, stop)
    num_items = len(queues)
    events = []

    def process(item, queue):
        data = cl.array.Array(queue, (n, ), dtype=cfg.PRECISION.np_float)
        event = prg.foo(queue, (n, 1), None, data.data, np.int32(stop))
        events.append(event)
        # Wait for the event so that the command queue will not be scheduled before the work has
        # been done.
        event.wait()

    start = time.time()
    gutil.qmap(process, range(num_items))
    host_duration = time.time() - start

    if verbose:
        print '-------------------------------'
        print '     All duration: {:.2f} s'.format(host_duration)
        print '-------------------------------'

    all_duration = 0
    for i, event in enumerate(events):
        duration = get_duration(event)
        all_duration += duration
        if verbose:
            print 'Device {} duration: {:.2f} s'.format(i, duration)

    speedup = all_duration / host_duration
    if verbose:
        print '-------------------------------'
        print '    Mean duration: {:.2f} s'.format(all_duration / len(devices))
        print '-------------------------------'
        print '          Speedup: {:.2f} / {}'.format(speedup, len(devices))
        print '-------------------------------'

    return speedup
Beispiel #5
0
def run(n, m, complexity, prg, verbose=False):
    devices = cfg.OPENCL.devices
    queues = cfg.OPENCL.queues

    stop = int(m ** complexity)
    complexity_fmt = 'complexity: {} x {}^{}, pixel operations: {}'
    if verbose:
        print complexity_fmt.format(n, m, complexity, stop)
    num_items = len(queues)
    events = []

    def process(item, queue):
        data = cl.array.Array(queue, (n,), dtype=cfg.PRECISION.np_float)
        event = prg.foo(queue, (n, 1), None, data.data, np.int32(stop))
        events.append(event)
        # Wait for the event so that the command queue will not be scheduled before the work has
        # been done.
        event.wait()

    start = time.time()
    gutil.qmap(process, range(num_items))
    host_duration = time.time() - start

    if verbose:
        print '-------------------------------'
        print '     All duration: {:.2f} s'.format(host_duration)
        print '-------------------------------'

    all_duration = 0
    for i, event in enumerate(events):
        duration = get_duration(event)
        all_duration += duration
        if verbose:
            print 'Device {} duration: {:.2f} s'.format(i, duration)

    speedup = all_duration / host_duration
    if verbose:
        print '-------------------------------'
        print '    Mean duration: {:.2f} s'.format(all_duration / len(devices))
        print '-------------------------------'
        print '          Speedup: {:.2f} / {}'.format(speedup, len(devices))
        print '-------------------------------'

    return speedup
Beispiel #6
0
def make_tiles(func, shape, tile_shape, iterable=None, outlier=(0, 0), queues=None,
               args=(), kwargs=None):
    """Make tiles using *func* which can either have signature func(item, *args, **kwargs) or
    func(item, queue, *args, **kwargs), where queue is the OpenCL command queue. In the latter case,
    multiple command queues are mapped to different computation items. *shape* (y, x) is the final
    image shape, *tile_shape* (y, x) is the shape of one tile, *iterable* is the sequence to be
    mapped to *func*, if not specified, the offsets from :func:`.make_tile_offsets` are used.
    *outlier* (y, x) is the amount of overlapping region between tiles, *queues* are the OpenCL
    command queues to use, *args* and *kwargs* are additional arguments passed to *func*. Returns a
    generator.
    """
    if iterable is None:
        iterable = make_tile_offsets(shape, tile_shape, outlier=outlier)
    if kwargs is None:
        kwargs = {}

    if queues is None:
        return (func(item, *args, **kwargs) for item in iterable)
    else:
        # Use multiple comand queues
        return (item for item in g_util.qmap(func, iterable, queues=queues, args=args,
                                             kwargs=kwargs))