Exemplo n.º 1
0
 def __init__(self, parameters, kernel_calls, internal_args, temp_buffers):
     self.signature = Signature(parameters)
     self.parameter = make_parameter_container(self, parameters)
     self._kernel_calls = [
         kernel_call.finalize(internal_args) for kernel_call in kernel_calls
     ]
     self._internal_args = internal_args
     self.__tempalloc__ = temp_buffers
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 __init__(self, thread, parameters, kernel_calls, internal_args, temp_buffers):
     self.thread = thread
     self.signature = Signature(parameters)
     self.parameter = make_parameter_container(self, parameters)
     self._kernel_calls = [kernel_call.finalize(internal_args) for kernel_call in kernel_calls]
     self._internal_args = internal_args
     self.__tempalloc__ = temp_buffers
Exemplo n.º 4
0
class ComputationCallable:
    """
    A result of calling :py:meth:`~reikna.core.Computation.compile` on a computation.
    Represents a callable opaque GPGPU computation.

    .. py:attribute:: signature

        A :py:class:`~reikna.core.Signature` object.

    .. py:attribute:: parameter

        A named tuple of :py:class:`~reikna.core.Type` objects corresponding
        to the callable's parameters.
    """
    def __init__(self, parameters, kernel_calls, internal_args, temp_buffers):
        self.signature = Signature(parameters)
        self.parameter = make_parameter_container(self, parameters)
        self._kernel_calls = [
            kernel_call.finalize(internal_args) for kernel_call in kernel_calls
        ]
        self._internal_args = internal_args
        self.__tempalloc__ = temp_buffers

    def __call__(self, *args, **kwds):
        """
        Execute the computation.
        """
        bound_args = self.signature.bind_with_defaults(args, kwds, cast=True)
        for kernel_call in self._kernel_calls:
            kernel_call(bound_args.arguments)
Exemplo n.º 5
0
class ComputationCallable:
    """
    A result of calling :py:meth:`~reikna.core.Computation.compile` on a computation.
    Represents a callable opaque GPGPU computation.

    .. py:attribute:: thread

        A :py:class:`~reikna.cluda.api.Thread` object used to compile the computation.

    .. py:attribute:: signature

        A :py:class:`~reikna.core.Signature` object.

    .. py:attribute:: parameter

        A named tuple of :py:class:`~reikna.core.Type` objects corresponding
        to the callable's parameters.
    """

    def __init__(self, thread, parameters, kernel_calls, internal_args, temp_buffers):
        self.thread = thread
        self.signature = Signature(parameters)
        self.parameter = make_parameter_container(self, parameters)
        self._kernel_calls = [kernel_call.finalize(internal_args) for kernel_call in kernel_calls]
        self._internal_args = internal_args
        self.__tempalloc__ = temp_buffers

    def __call__(self, *args, **kwds):
        """
        Execute the computation.
        """
        bound_args = self.signature.bind_with_defaults(args, kwds, cast=True)
        for kernel_call in self._kernel_calls:
            kernel_call(bound_args.arguments)
Exemplo n.º 6
0
 def _update_attributes(self):
     """
     Updates ``signature`` and ``parameter`` attributes.
     Called by the methods that change the signature.
     """
     leaf_params = self._tr_tree.get_leaf_parameters()
     self.signature = Signature(leaf_params)
     self.parameter = make_parameter_container(self, leaf_params)
Exemplo n.º 7
0
class ComputationCallable:
    """
    A result of calling :py:meth:`~reikna.core.Computation.compile` on a computation.
    Represents a callable opaque GPGPU computation.

    .. py:attribute:: thread

        A :py:class:`~reikna.cluda.api.Thread` object used to compile the computation.

    .. py:attribute:: signature

        A :py:class:`~reikna.core.Signature` object.

    .. py:attribute:: parameter

        A named tuple of :py:class:`~reikna.core.Type` objects corresponding
        to the callable's parameters.
    """
    def __init__(self, thread, parameters, kernel_calls, internal_args,
                 temp_buffers):
        self.thread = thread
        self.signature = Signature(parameters)
        self.parameter = make_parameter_container(self, parameters)
        self._kernel_calls = [
            kernel_call.finalize(internal_args) for kernel_call in kernel_calls
        ]
        self._internal_args = internal_args
        self.__tempalloc__ = temp_buffers

    def __call__(self, *args, **kwds):
        """
        Execute the computation.
        In case of the OpenCL backend, returns a list of ``pyopencl.Event`` objects
        from nested kernel calls.
        """
        bound_args = self.signature.bind_with_defaults(args, kwds, cast=True)
        results = []
        for kernel_call in self._kernel_calls:
            results.append(kernel_call(bound_args.arguments))
        return results