Esempio n. 1
0
 def compile(self, source, options=""):
     """Returns a Program built from the provided ``source``.
     
     The compiler options can be provided as a single string or a sequence 
     of strings.
     """
     if cypy.is_iterable(options):
         options = " ".join(options)
     return Program(self, source).build(options)
Esempio n. 2
0
    def __call__(self, *args, **kwargs):
        """
        Extended to use the default queue if the first argument is
        not a :class:`CommandQueue` and the shape of the first kernel
        argument as the ``global_size`` if not explicitly specified.

        Also provides support for :meth:`Context.Out` and :meth:`Context.InOut`.
        
        Python ints and floats are converted to numpy ints and floats 
        automatically. The default floating point data type is ``float``, not
        ``double``, which is only used if the number cannot fit into the range
        of the float. The default integer data type is ``int``, with ``long``
        being used if the number is out of range of ``int``.
        """
        queue = args[0]
        if not isinstance(queue, CommandQueue):
            queue = kwargs.pop('queue', None)
            if queue is None:
                queue = self.queue
        else:
            args = args[1:]

        global_size = args[0]
        if not cypy.is_iterable(global_size):
            try:
                global_size = global_size.shape
                args = args[1:]
            except AttributeError:
                if global_size is None:
                    global_size = kwargs.pop('global_size')
        else:
            args = args[1:]

        args = tuple(self._process_args(args))

        event = _orig__call_Kernel(self, queue, global_size, *args, **kwargs)
        
        for arg in args:
            hook = getattr(arg, 'post_kernel_hook', None)
            if hook is not None:
                hook(self.program.context, arg, event)

        return event
Esempio n. 3
0
    def _process_nonstrings(self, code):
        if code is not None and code is not self:
            expr = getattr(code, '_CG_expression', None)
            if expr is not None:
                # Push the value's context onto stack
                context = getattr(code, '_CG_context', None)
                if context:
                    self._append_context(context)
                else:
                    context = None

                self.append(expr)

                if context:
                    self.pop_context()
            elif cypy.is_callable(code):
                code = self._call_callable(code)
                if code is not None and code is not self:
                    self.append(code)
            elif cypy.is_iterable(code):
                for item in code:
                    self.append(item)
            else:
                self.append(self._convert(code))