def main():
    devices = get_devices()
    try:
        debug(CL_DEVICE_TYPE(devices[0].type))
    except IndexError as ie:
        exception(ie)
    context = Context(devices)
    queue = CommandQueue(context)  # Create queue for each kernel execution

    source = read_kernel_source("median_filter.cl")
    program = Program(context, source).build()  # Kernel function instantiation

    image = imread('../data/noisyImage.jpg',
                   flatten=True).astype(float32)  # Read in image
    imshow(image)

    start_usec = perf_counter()
    args = allocate_variables(context, image)

    program.medianFilter(queue, image.shape, None, *args)  # Call Kernel.
    # Automatically takes care of block/grid distribution. Note explicit naming of kernel to execute.

    result = copy_from_buffer(queue, args[1], image.shape,
                              image.dtype)  # Copy the result back from buffer
    debug("%g milliseconds" % (1e3 * (perf_counter() - start_usec)))

    imshow(result)
    imsave('../data/medianFilter-OpenCL.jpg', result)  # Show the blurred image