Example #1
0
    def _do_call(self, args, kwargs):
        if not self.is_kernel:
            raise Error("Cannot call a non-kernel cl.oquence function.")

        # include downstream implicit variables
        args = cypy.cons(args, self.implicit_args)

        # grab context and options
        try:
            ctx = kwargs.pop('ctx')
        except KeyError:
            ctx = cl.ctx
        options = kwargs.pop('options', '')

        # generate a kernel
        kernel = self.generate_kernel(ctx, options)

        # send global size the way pyopencl likes it
        global_size = kwargs.pop('global_size')

        # get queue
        try:
            queue = kwargs.pop('queue')
        except KeyError:
            queue = ctx.queue

        # call the kernel
        return kernel(queue, global_size, *args, **kwargs)
Example #2
0
def _yield_args(visitor, args, arg_types, defaults, implicit_args):
    visit = visitor.visit
    for arg, arg_type in zip(args, arg_types):
        if not hasattr(arg_type, 'constant_value'):
            yield visit(arg)
            
    add_implicit = visitor._add_implicit
    for implicit in cypy.cons(defaults, implicit_args):
        yield "__implicit__" + str(add_implicit(implicit))
Example #3
0
 def _all_constants(self):
     # All constants (provided constants + free variable constants).
     constants = self.constants
     globals = self.globals
     return cypy.frozendict(cypy.cons(
         constants.iteritems(),
         ((name, globals[name]) 
          for name in self.free_variables if name not in constants)
     ))
Example #4
0
def _yield_args(visitor, args, arg_types, defaults, implicit_args):
    visit = visitor.visit
    for arg, arg_type in zip(args, arg_types):
        if not hasattr(arg_type, 'constant_value'):
            yield visit(arg)

    add_implicit = visitor._add_implicit
    for implicit in cypy.cons(defaults, implicit_args):
        yield "__implicit__" + str(add_implicit(implicit))
Example #5
0
 def _all_constants(self):
     # All constants (provided constants + free variable constants).
     constants = self.constants
     globals = self.globals
     return cypy.frozendict(
         cypy.cons(
             constants.iteritems(),
             ((name, globals[name])
              for name in self.free_variables if name not in constants)))
Example #6
0
 def generate_program_item(self, context):
     g = cg.CG()
     g.append(cypy.join(cypy.cons(context.modifiers, 
                                  (context.return_type.name,)), " "))
     name = self._generate_name(context)
     g.append((" ", name, "("))
     g.append(cypy.join(self._yield_arg_str(context), ", "))
     g.append((") {\n", context.tab))
     g.append((cypy.join(context.declarations, "\n"), "\n\n"))
     g.append(context.stmts)
     g.append((context.untab, "\n}\n"))
     return clq.ProgramItem(name, g.code)
Example #7
0
 def in_step_kernel(self, g):
     # TODO: Get rid of these once globals work
     constants = self.constants
     constants['get_global_id'] = clqcl.get_global_id
     constants['get_global_size'] = clqcl.get_global_size
     constants['min'] = clqcl.min
     constants['atom_add'] = clqcl.atom_add
     constants['atom_inc'] = clqcl.atom_inc 
     constants['log'] = clqcl.log
     
     "def step_fn(" >> g
     py.join(py.cons(("timestep", "realization_start"), 
                      self.constants.iterkeys()), 
               ",\n            ") >> g
     ("):\n", g.tab) >> g
     self.trigger_staged_cg_hook("step_kernel_body", g)
Example #8
0
 def _do_call(self, args, kwargs):
     if not self.is_kernel:
         raise Error("Cannot call a non-kernel cl.oquence function.")
     
     # include downstream implicit variables
     args = cypy.cons(args, self.implicit_args)
     
     # grab context and options
     try: ctx = kwargs.pop('ctx')
     except KeyError: ctx = cl.ctx
     options = kwargs.pop('options', '')
     
     # generate a kernel        
     kernel = self.generate_kernel(ctx, options)
     
     # send global size the way pyopencl likes it
     global_size = kwargs.pop('global_size')
     
     # get queue
     try: queue = kwargs.pop('queue')
     except KeyError: queue = ctx.queue
     
     # call the kernel
     return kernel(queue, global_size, *args, **kwargs)