Beispiel #1
0
    def setUpClass(cls):
        super(TestGaussian, cls).setUpClass()
        cls.ctx = ocl.create_context()

        if logger.getEffectiveLevel() <= logging.INFO:
            cls.PROFILE = True
            cls.queue = pyopencl.CommandQueue(cls.ctx, properties=pyopencl.command_queue_properties.PROFILING_ENABLE)
        else:
            cls.PROFILE = False
            cls.queue = pyopencl.CommandQueue(cls.ctx)

        cls.kernels = {"preprocess": 8,
                       "gaussian": 512}

        device = cls.ctx.devices[0]
        device_id = device.platform.get_devices().index(device)
        platform_id = pyopencl.get_platforms().index(device.platform)
        maxwg = ocl.platforms[platform_id].devices[device_id].max_work_group_size
#         logger.warning("max_work_group_size: %s on (%s, %s)", maxwg, platform_id, device_id)
        for kernel in list(cls.kernels.keys()):
            if cls.kernels[kernel] < maxwg:
                logger.warning("%s Limiting workgroup size to %s", kernel, maxwg)
                cls.kernels[kernel] = maxwg
        cls.max_wg = maxwg

        for kernel in list(cls.kernels.keys()):
            kernel_src = get_opencl_code(os.path.join("sift", kernel))
            program = pyopencl.Program(cls.ctx, kernel_src).build("-D WORKGROUP=%s" % cls.kernels[kernel])
            cls.kernels[kernel] = program
Beispiel #2
0
    def setUpClass(cls):
        super(TestGaussian, cls).setUpClass()
        cls.ctx = ocl.create_context()

        if logger.getEffectiveLevel() <= logging.INFO:
            cls.PROFILE = True
            cls.queue = pyopencl.CommandQueue(
                cls.ctx,
                properties=pyopencl.command_queue_properties.PROFILING_ENABLE)
        else:
            cls.PROFILE = False
            cls.queue = pyopencl.CommandQueue(cls.ctx)

        cls.kernels = {"preprocess": 8, "gaussian": 512}

        device = cls.ctx.devices[0]
        device_id = device.platform.get_devices().index(device)
        platform_id = pyopencl.get_platforms().index(device.platform)
        maxwg = ocl.platforms[platform_id].devices[
            device_id].max_work_group_size
        #         logger.warning("max_work_group_size: %s on (%s, %s)", maxwg, platform_id, device_id)
        for kernel in list(cls.kernels.keys()):
            if cls.kernels[kernel] < maxwg:
                logger.warning("%s Limiting workgroup size to %s", kernel,
                               maxwg)
                cls.kernels[kernel] = maxwg
        cls.max_wg = maxwg

        for kernel in list(cls.kernels.keys()):
            kernel_src = get_opencl_code(os.path.join("sift", kernel))
            program = pyopencl.Program(cls.ctx, kernel_src).build(
                "-D WORKGROUP=%s" % cls.kernels[kernel])
            cls.kernels[kernel] = program
Beispiel #3
0
 def setUpClass(cls):
     super(TestMatching, cls).setUpClass()
     if ocl:
         cls.ctx = ocl.create_context()
         if logger.getEffectiveLevel() <= logging.INFO:
             cls.PROFILE = True
             cls.queue = pyopencl.CommandQueue(cls.ctx, properties=pyopencl.command_queue_properties.PROFILING_ENABLE)
         else:
             cls.PROFILE = False
             cls.queue = pyopencl.CommandQueue(cls.ctx)
Beispiel #4
0
 def setUpClass(cls):
     super(TestAddition, cls).setUpClass()
     if ocl:
         cls.ctx = ocl.create_context()
         if logger.getEffectiveLevel() <= logging.INFO:
             cls.PROFILE = True
             cls.queue = pyopencl.CommandQueue(cls.ctx, properties=pyopencl.command_queue_properties.PROFILING_ENABLE)
             import pylab
         else:
             cls.PROFILE = False
             cls.queue = pyopencl.CommandQueue(cls.ctx)
         cls.max_valid_wg = 0
Beispiel #5
0
 def setUpClass(cls):
     super(TestMatching, cls).setUpClass()
     if ocl:
         cls.ctx = ocl.create_context()
         if logger.getEffectiveLevel() <= logging.INFO:
             cls.PROFILE = True
             cls.queue = pyopencl.CommandQueue(
                 cls.ctx,
                 properties=pyopencl.command_queue_properties.
                 PROFILING_ENABLE)
         else:
             cls.PROFILE = False
             cls.queue = pyopencl.CommandQueue(cls.ctx)
 def setUpClass(cls):
     super(TestAlgebra, cls).setUpClass()
     if ocl:
         cls.ctx = ocl.create_context()
         if logger.getEffectiveLevel() <= logging.INFO:
             cls.PROFILE = True
             cls.queue = pyopencl.CommandQueue(cls.ctx, properties=pyopencl.command_queue_properties.PROFILING_ENABLE)
         else:
             cls.PROFILE = False
             cls.queue = pyopencl.CommandQueue(cls.ctx)
         device = cls.ctx.devices[0]
         device_id = device.platform.get_devices().index(device)
         platform_id = pyopencl.get_platforms().index(device.platform)
         cls.maxwg = ocl.platforms[platform_id].devices[device_id].max_work_group_size
Beispiel #7
0
 def setUpClass(cls):
     super(TestImage, cls).setUpClass()
     if ocl:
         cls.ctx = ocl.create_context()
         if logger.getEffectiveLevel() <= logging.INFO:
             cls.PROFILE = True
             cls.queue = pyopencl.CommandQueue(cls.ctx, properties=pyopencl.command_queue_properties.PROFILING_ENABLE)
         else:
             cls.PROFILE = False
             cls.queue = pyopencl.CommandQueue(cls.ctx)
         device = cls.ctx.devices[0]
         device_id = device.platform.get_devices().index(device)
         platform_id = pyopencl.get_platforms().index(device.platform)
         cls.maxwg = ocl.platforms[platform_id].devices[device_id].max_work_group_size
Beispiel #8
0
    def setUpClass(cls):
        super(TestReduction, cls).setUpClass()
        if ocl:
            cls.ctx = ocl.create_context()
            if logger.getEffectiveLevel() <= logging.INFO:
                cls.PROFILE = True
                cls.queue = pyopencl.CommandQueue(cls.ctx, properties=pyopencl.command_queue_properties.PROFILING_ENABLE)
            else:
                cls.PROFILE = False
                cls.queue = pyopencl.CommandQueue(cls.ctx)
            device = cls.ctx.devices[0]
            device_id = device.platform.get_devices().index(device)
            platform_id = pyopencl.get_platforms().index(device.platform)
            cls.maxwg = ocl.platforms[platform_id].devices[device_id].max_work_group_size
#             logger.warning("max_work_group_size: %s on (%s, %s)", cls.maxwg, platform_id, device_id)
            kernel_src = get_opencl_code(os.path.join("sift", "reductions"))
            cls.program = pyopencl.Program(cls.ctx, kernel_src).build(options="")
Beispiel #9
0
from ..alignFFT import alignFFT
from ..alignSimple import alignMin
from ..alignSimple import alignMax
from ..alignSimple import alignCentroid
from ..alignSimple import alignGaussMax
from ..types import transformationType
from . import helper_teststack
from ...utils.cli import getLogger

logger = getLogger(__name__, __file__)
logger.setLevel(logging.DEBUG)

from silx.opencl import ocl

if ocl:
    has_ocl_device = ocl.create_context() is not None
else:
    has_ocl_device = False


class test_align(unittest.TestCase):
    def compare_relativecof(self, cofs, cofrel, msg=None):
        for i in range(1, cofs.shape[0]):
            cofrelcalc = np.dot(np.linalg.inv(cofs[i - 1, ...]), cofs[i, ...])
            np.testing.assert_almost_equal(cofrelcalc,
                                           cofrel,
                                           decimal=1,
                                           err_msg=msg)

    def assertAligned(self, outputstack, stackdim):
        for stack in outputstack:
Beispiel #10
0
def process(options):
    """Perform actually the processing 
    
    :param options: The argument parsed by agrparse.
    :return: EXIT_SUCCESS or EXIT_FAILURE
    """
    if options.verbose:
        pb = None
    else:
        pb = ProgressBar("Sparsification", 100, 30)

    logger.debug("Count the number of frames")
    if pb:
        pb.update(0, message="Count the number of frames")
    dense = [fabio.open(f) for f in options.images]
    nframes = sum([f.nframes for f in dense])

    logger.debug("Initialize the geometry")
    if pb:
        pb.update(0, message="Initialize the geometry", max_value=nframes)
    ai = load(options.poni)
    if options.mask is not None:
        mask = fabio.open(options.mask).data
        ai.detector.mask = mask
    else:
        mask = ai.detector.mask
    shape = dense[0].shape

    if options.radial_range is not None:
        rrange = [
            i * numpy.mean(ai.detector.pixel1, ai.detector.pixel2)
            for i in options.radial_range
        ]
    else:
        rrange = None

    integrator = ai.setup_CSR(shape,
                              options.bins,
                              mask=mask,
                              pos0_range=rrange,
                              unit=R_M,
                              split="no",
                              scale=False)

    logger.debug("Initialize the OpenCL device")
    if pb:
        pb.update(0, message="Initialize the OpenCL device")

    if options.device is not None:
        ctx = ocl.create_context(
            platformid=options.device[0],
            deviceid=options.device[1],
        )
    else:
        ctx = ocl.create_context(devicetype=options.device_type)

    logger.debug("Initialize the sparsificator")
    pf = OCL_PeakFinder(integrator.lut,
                        image_size=shape[0] * shape[1],
                        empty=options.dummy,
                        unit=R_M,
                        bin_centers=integrator.bin_centers,
                        radius=ai._cached_array["r_center"],
                        mask=mask,
                        ctx=ctx)

    logger.debug("Start sparsification")
    frames = []

    cnt = 0

    parameters = {
        "dummy": options.dummy,
        "delta_dummy": options.delta_dummy,
        "safe": False,
        "error_model": options.error_model,
        "cutoff_clip": options.cutoff_clip,
        "cycle": options.cycle,
        "noise": options.noise,
        "cutoff_pick": options.cutoff_pick,
        "radial_range": rrange
    }
    for fabioimage in dense:
        for frame in fabioimage:
            current = pf.sparsify(frame.data, **parameters)
            frames.append(current)
            if pb:
                pb.update(cnt,
                          message="%s: %i pixels" % (os.path.basename(
                              fabioimage.filename), current.intensity.size))
            else:
                print("%s frame #%d, found %d intense pixels" %
                      (fabioimage.filename, fabioimage.currentframe,
                       current.intensity.size))
            cnt += 1

    logger.debug("Save data")
    if pb:
        pb.update(nframes, message="Saving: " + options.output)
    else:
        print("Saving: " + options.output)

    save_sparse(options.output,
                frames,
                beamline=options.beamline,
                ai=ai,
                source=options.images if options.save_source else None)
    return EXIT_SUCCESS