def get_constant_arg_decl(self, name, shape, dtype, is_written): from loopy.target.c import POD # uses the correct complex type from cgen import RestrictPointer, Const from cgen.opencl import CLConstant arg_decl = RestrictPointer(POD(self, dtype, name)) if not is_written: arg_decl = Const(arg_decl) return CLConstant(arg_decl)
def get_declarations(self): scope = self.scope_stack[-1] result = [] pre_func_decl = [] def gen_shape(start_end): return ":".join(self.gen_expr(s) for s in start_end) for name in sorted(scope.known_names()): shape = scope.dim_map.get(name) if shape is not None: dim_stmt = cgen.Statement( "dimension \"fortran\" %s[%s]" % (scope.translate_var_name(name), ", ".join( gen_shape(s) for s in shape))) # cannot omit 'dimension' decl even for rank-1 args: result.append(dim_stmt) if name in scope.data: assert name not in scope.arg_names data = scope.data[name] if shape is None: assert len(data) == 1 result.append( cgen.Initializer(self.get_declarator(name), self.gen_expr(data[0]))) else: from cgen.opencl import CLConstant pre_func_decl.append( cgen.Initializer( CLConstant( cgen.ArrayOf( self.get_declarator( "%s_%s" % (scope.subprogram_name, name)))), "{ %s }" % ",\n".join(self.gen_expr(x) for x in data))) else: if name not in scope.arg_names: if shape is not None: result.append( cgen.Statement( "%s %s[nitemsof(%s)]" % (dtype_to_ctype( scope.get_type(name)), name, name))) else: result.append(self.get_declarator(name)) return pre_func_decl, result
def wrap_global_constant(self, decl): from cgen.opencl import CLConstant return CLConstant(decl)