def get_function_definition(self, codegen_state, codegen_result, schedule_index, function_decl, function_body): kernel = codegen_state.kernel from cgen import ( FunctionBody, # Post-mid-2016 cgens have 'Collection', too. Module as Collection, Initializer, Line) result = [] from loopy.kernel.data import AddressSpace from loopy.schedule import CallKernel # We only need to write declarations for global variables with # the first device program. `is_first_dev_prog` determines # whether this is the first device program in the schedule. is_first_dev_prog = codegen_state.is_generating_device_code for i in range(schedule_index): if isinstance(kernel.schedule[i], CallKernel): is_first_dev_prog = False break if is_first_dev_prog: for tv in sorted( six.itervalues(kernel.temporary_variables), key=lambda tv: tv.name): if tv.address_space == AddressSpace.GLOBAL and ( tv.initializer is not None): assert tv.read_only decl_info, = tv.decl_info(self.target, index_dtype=kernel.index_dtype) decl = self.wrap_global_constant( self.get_temporary_decl( codegen_state, schedule_index, tv, decl_info)) if tv.initializer is not None: decl = Initializer(decl, generate_array_literal( codegen_state, tv, tv.initializer)) result.append(decl) fbody = FunctionBody(function_decl, function_body) if not result: return fbody else: return Collection(result+[Line(), fbody])
def get_function_definition(self, codegen_state, codegen_result, schedule_index, function_decl, function_body): kernel = codegen_state.kernel from cgen import ( FunctionBody, # Post-mid-2016 cgens have 'Collection', too. Module as Collection, Initializer, Line) result = [] from loopy.kernel.data import temp_var_scope for tv in sorted( six.itervalues(kernel.temporary_variables), key=lambda tv: tv.name): if tv.scope == temp_var_scope.GLOBAL and tv.initializer is not None: assert tv.read_only decl_info, = tv.decl_info(self.target, index_dtype=kernel.index_dtype) decl = self.wrap_global_constant( self.get_temporary_decl( codegen_state, schedule_index, tv, decl_info)) if tv.initializer is not None: decl = Initializer(decl, generate_array_literal( codegen_state, tv, tv.initializer)) result.append(decl) fbody = FunctionBody(function_decl, function_body) if not result: return fbody else: return Collection(result+[Line(), fbody])