diff --git a/llvm/kernelcreation.py b/llvm/kernelcreation.py index c403a8810fc140ceba95211f8d9bd1417c376e16..4f95505dc60fb943fef667361eb4ceb208bd7be3 100644 --- a/llvm/kernelcreation.py +++ b/llvm/kernelcreation.py @@ -1,8 +1,4 @@ -from pystencils.astnodes import SympyAssignment, Block, LoopOverCoordinate, KernelFunction -from pystencils.transformations import resolve_field_accesses, \ - type_all_equations, move_constants_before_loop, insert_casts -from pystencils.data_types import TypedSymbol, BasicType, StructType -from pystencils.field import FieldType +from pystencils.transformations import insert_casts from functools import partial from pystencils.llvm.llvmjit import make_python_function @@ -54,51 +50,4 @@ def create_indexed_kernel(assignments, index_fields, function_name="kernel", typ :param coordinate_names: name of the coordinate fields in the struct data type :return: abstract syntax tree """ - fields_read, fields_written, assignments = type_all_equations(assignments, type_info) - all_fields = fields_read.union(fields_written) - - for indexField in index_fields: - indexField.fieldType = FieldType.INDEXED - assert FieldType.is_indexed(indexField) - assert indexField.spatial_dimensions == 1, "Index fields have to be 1D" - - non_index_fields = [f for f in all_fields if f not in index_fields] - spatial_coordinates = {f.spatial_dimensions for f in non_index_fields} - assert len(spatial_coordinates) == 1, "Non-index fields do not have the same number of spatial coordinates" - spatial_coordinates = list(spatial_coordinates)[0] - - def get_coordinate_symbol_assignment(name): - for index_field in index_fields: - assert isinstance(index_field.dtype, StructType), "Index fields have to have a struct datatype" - data_type = index_field.dtype - if data_type.has_element(name): - rhs = index_field[0](name) - lhs = TypedSymbol(name, BasicType(data_type.get_element_type(name))) - return SympyAssignment(lhs, rhs) - raise ValueError("Index %s not found in any of the passed index fields" % (name,)) - - coordinate_symbol_assignments = [get_coordinate_symbol_assignment(n) - for n in coordinate_names[:spatial_coordinates]] - coordinate_typed_symbols = [eq.lhs for eq in coordinate_symbol_assignments] - assignments = coordinate_symbol_assignments + assignments - - # make 1D loop over index fields - loop_body = Block([]) - loop_node = LoopOverCoordinate(loop_body, coordinate_to_loop_over=0, start=0, stop=index_fields[0].shape[0]) - - for assignment in assignments: - loop_body.append(assignment) - - function_body = Block([loop_node]) - ast = KernelFunction(function_body, None, function_name, backend='llvm') - - read_only_fields = set([f.name for f in fields_read - fields_written]) - fixed_coordinate_mapping = {f.name: coordinate_typed_symbols for f in non_index_fields} - resolve_field_accesses(ast, read_only_fields, field_to_fixed_coordinates=fixed_coordinate_mapping) - move_constants_before_loop(ast) - - desympy_ast(ast) - insert_casts(ast) - ast.compile = partial(make_python_function, ast) - - return ast + raise NotImplementedError diff --git a/llvm/llvmjit.py b/llvm/llvmjit.py index 56649be9e3d9c31de23bfa731e587958bfcbec13..571a31b60b720db6404957bc5c3b4aa7b0797cc4 100644 --- a/llvm/llvmjit.py +++ b/llvm/llvmjit.py @@ -105,24 +105,6 @@ class Jit(object): pmb.populate(pm) pm.run(self.llvmmod) - def optimize_polly(self, opt): - if shutil.which(opt) is None: - print('Path to the executable is wrong') - return - canonicalize = subprocess.Popen([opt, '-polly-canonicalize'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) - - analyze = subprocess.Popen( - [opt, '-polly-codegen', '-polly-vectorizer=polly', '-polly-parallel', '-polly-process-unprofitable', '-f'], - stdin=canonicalize.stdout, stdout=subprocess.PIPE) - - canonicalize.communicate(input=self.llvmmod.as_bitcode()) - - optimize = subprocess.Popen([opt, '-O3', '-f'], stdin=analyze.stdout, stdout=subprocess.PIPE) - opts, _ = optimize.communicate() - llvmmod = llvm.parse_bitcode(opts) - llvmmod.verify() - self.llvmmod = llvmmod - def compile(self): fptr = {} for func in self.module.functions: