Example #1
0
def get_cl_kernels(src):
    """
    Return OpenCL kernels.

    :param src: OpenCL source.
    :return: Kernel implementations.
    """
    idxs = smith.get_substring_idxs('__kernel', src)
    kernels = [get_cl_kernel(src, i) for i in idxs]
    return kernels
Example #2
0
def extract_prototype(src):
    """
    Extract OpenCL kernel prototype from rewritten file.

    :param src: OpenCL kernel source.
    :return: KernelPrototype object instance.
    """
    idxs = smith.get_substring_idxs('__kernel void ', src)
    if len(idxs) != 1:
        raise PrototypeException("Invalid number of kernels found: {}"
                                 .format(len(idxs)))
    src = get_cl_kernel(src, idxs[0])

    try:
        index = src.index('{') + 1
        prototype = src[:index]
    except ValueError:
        raise PrototypeException("malformed seed")

    return KernelPrototype(prototype)
Example #3
0
def strip_attributes(src):
    idxs = sorted(smith.get_substring_idxs('__attribute__', src))
    ranges = [get_attribute_range(src, i) for i in idxs]
    for r in reversed(ranges):
        src = src[:r[0]] + src[r[1]:]
    return src