Exemplo n.º 1
0
    def _build_plan(self, plan_factory, _device_params, *args):

        plan = plan_factory()

        # Using root_parameters to avoid duplicated names
        # (can happen if this computation is nested and
        # the same arrays are passed to it as arguments)
        arglist = ", ".join(self._root_parameters)
        idxs = Indices(self._guiding_shape)

        template = helpers.template_def(
            ['kernel_declaration'] + self._root_parameters,
            """
            ${kernel_declaration}
            {
                VIRTUAL_SKIP_THREADS;

                %for i, idx in enumerate(idxs):
                VSIZE_T ${idx} = virtual_global_id(${i});
                %endfor

                ${snippet(idxs, """ + arglist + """)}
            }
            """)

        plan.kernel_call(
            template, args,
            kernel_name="kernel_pure_parallel",
            global_size=(1,) if len(self._guiding_shape) == 0 else self._guiding_shape,
            render_kwds=dict(
                idxs=idxs,
                product=helpers.product,
                snippet=self._snippet))

        return plan
Exemplo n.º 2
0
    def __init__(self, parameters, code, render_kwds=None, connectors=None):

        for param in parameters:
            if param.annotation.input and param.annotation.output:
                raise ValueError(
                    "Transformation cannot have 'io' parameters ('" +
                    param.name + "')")

        self.signature = Signature(parameters)

        for param in self.signature.parameters.values():
            setattr(
                self, param.name,
                TransformationParameter(self, param.name,
                                        param.annotation.type))

        if connectors is not None:
            self.connectors = connectors
        else:
            self.connectors = [
                param.name for param in parameters if param.annotation.array
            ]

        tr_param_names = ['idxs'] + [
            param.name for param in self.signature.parameters.values()
        ]
        self.snippet = Snippet(template_def(tr_param_names, code),
                               render_kwds=render_kwds)
Exemplo n.º 3
0
    def _build_plan(self, plan_factory, _device_params, *args):

        plan = plan_factory()

        # Using root_parameters to avoid duplicated names
        # (can happen if this computation is nested and
        # the same arrays are passed to it as arguments)
        arglist = ", ".join(self._root_parameters)
        idxs = Indices(self._guiding_shape)

        template = helpers.template_def(['kernel_declaration'] +
                                        self._root_parameters, """
            ${kernel_declaration}
            {
                VIRTUAL_SKIP_THREADS;

                %for i, idx in enumerate(idxs):
                VSIZE_T ${idx} = virtual_global_id(${i});
                %endfor

                ${snippet(idxs, """ + arglist + """)}
            }
            """)

        plan.kernel_call(template,
                         args,
                         kernel_name="kernel_pure_parallel",
                         global_size=(1, ) if len(self._guiding_shape) == 0
                         else self._guiding_shape,
                         render_kwds=dict(idxs=idxs,
                                          product=helpers.product,
                                          snippet=self._snippet))

        return plan
Exemplo n.º 4
0
    def create(cls, func_or_str, render_kwds=None):
        """
        Creates a snippet from the ``Mako`` def:

        * if ``func_or_str`` is a function, then the def has the same signature as ``func_or_str``,
          and the body equal to the string it returns;
        * if ``func_or_str`` is a string, then the def has empty signature.
        """
        signature, code = extract_signature_and_value(func_or_str)
        return cls(template_def(signature, code), render_kwds=render_kwds)
Exemplo n.º 5
0
    def create(cls, func_or_str, render_kwds=None):
        """
        Creates a snippet from the ``Mako`` def:

        * if ``func_or_str`` is a function, then the def has the same signature as ``func_or_str``,
          and the body equal to the string it returns;
        * if ``func_or_str`` is a string, then the def has empty signature.
        """
        signature, code = extract_signature_and_value(func_or_str)
        return cls(template_def(signature, code), render_kwds=render_kwds)
Exemplo n.º 6
0
    def create(cls, func_or_str, render_kwds=None):
        """
        Creates a module from the ``Mako`` def:

        * if ``func_or_str`` is a function, then the def has the same signature as ``func_or_str``
          (prefix will be passed as the first positional parameter),
          and the body equal to the string it returns;
        * if ``func_or_str`` is a string, then the def has a single positional argument ``prefix``.
          and the body ``code``.
        """
        signature, code = extract_signature_and_value(func_or_str, default_parameters=["prefix"])
        return cls(template_def(signature, code), render_kwds=render_kwds)
Exemplo n.º 7
0
    def create(cls, func_or_str, render_kwds=None):
        """
        Creates a module from the ``Mako`` def:

        * if ``func_or_str`` is a function, then the def has the same signature as ``func_or_str``
          (prefix will be passed as the first positional parameter),
          and the body equal to the string it returns;
        * if ``func_or_str`` is a string, then the def has a single positional argument ``prefix``.
          and the body ``code``.
        """
        signature, code = extract_signature_and_value(
            func_or_str, default_parameters=['prefix'])
        return cls(template_def(signature, code), render_kwds=render_kwds)
Exemplo n.º 8
0
    def __init__(self, parameters, code, guiding_array=None, render_kwds=None):

        Computation.__init__(self, parameters)

        self._root_parameters = list(self.signature.parameters.keys())

        if isinstance(code, Snippet):
            self._snippet = code
        else:
            self._snippet = Snippet(helpers.template_def(
                ['idxs'] + self._root_parameters, code), render_kwds=render_kwds)

        if guiding_array is None:
            guiding_array = self._root_parameters[0]

        if isinstance(guiding_array, str):
            self._guiding_shape = self.signature.parameters[guiding_array].annotation.type.shape
        else:
            self._guiding_shape = guiding_array
Exemplo n.º 9
0
    def __init__(self, parameters, code, guiding_array=None, render_kwds=None):

        Computation.__init__(self, parameters)

        self._root_parameters = list(self.signature.parameters.keys())

        if isinstance(code, Snippet):
            self._snippet = code
        else:
            self._snippet = Snippet(helpers.template_def(
                ['idxs'] + self._root_parameters, code),
                                    render_kwds=render_kwds)

        if guiding_array is None:
            guiding_array = self._root_parameters[0]

        if isinstance(guiding_array, str):
            self._guiding_shape = self.signature.parameters[
                guiding_array].annotation.type.shape
        else:
            self._guiding_shape = guiding_array
Exemplo n.º 10
0
    def __init__(self, parameters, code, render_kwds=None, connectors=None):

        for param in parameters:
            if param.annotation.input and param.annotation.output:
                raise ValueError(
                    "Transformation cannot have 'io' parameters ('" + param.name + "')")

        self.signature = Signature(parameters)

        for param in self.signature.parameters.values():
            setattr(
                self, param.name,
                TransformationParameter(self, param.name, param.annotation.type))

        if connectors is not None:
            self.connectors = connectors
        else:
            self.connectors = [param.name for param in parameters if param.annotation.array]

        tr_param_names = ['idxs'] + [param.name for param in self.signature.parameters.values()]
        self.snippet = Snippet(template_def(tr_param_names, code), render_kwds=render_kwds)
Exemplo n.º 11
0
        ctype = param.annotation.type.ctype
        if param.annotation.array:
            qualifier = ("CONSTANT_MEM" if param.annotation.constant else "GLOBAL_MEM")
            return qualifier + " " + str(ctype) + " *" + name
        else:
            return str(ctype) + " " + name
    else:
        return name


def param_cnames_seq(parameters, qualified=False):
    return [param_cname(p, qualified=qualified) for p in parameters]


_snippet_kernel_declaration = helpers.template_def(
    [],
    "KERNEL void ${kernel_name}(${', '.join(param_cnames_seq(parameters, qualified=True))})")

def kernel_declaration(kernel_name, parameters):
    return Snippet(
        _snippet_kernel_declaration,
        render_kwds=dict(
            param_cnames_seq=param_cnames_seq,
            kernel_name=kernel_name,
            parameters=parameters))


def node_connector(output):
    if output:
        return VALUE_NAME
    else:
Exemplo n.º 12
0
    if qualified:
        ctype = param.annotation.type.ctype
        if param.annotation.array:
            return "GLOBAL_MEM " + str(ctype) + " *" + name
        else:
            return str(ctype) + " " + name
    else:
        return name


def param_cnames_seq(parameters, qualified=False):
    return [param_cname(p, qualified=qualified) for p in parameters]


_snippet_kernel_declaration = helpers.template_def(
    [],
    "KERNEL void ${kernel_name}(${', '.join(param_cnames_seq(parameters, qualified=True))})"
)


def kernel_declaration(kernel_name, parameters):
    return Snippet(_snippet_kernel_declaration,
                   render_kwds=dict(param_cnames_seq=param_cnames_seq,
                                    kernel_name=kernel_name,
                                    parameters=parameters))


def node_connector(output):
    if output:
        return VALUE_NAME
    else:
        return VALUE_NAME + " ="