Exemplo n.º 1
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.º 2
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.º 3
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