From 9c723ee03e6e7eca3b42b46971b122d976695082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20S=2E=20Dokken?= Date: Mon, 3 Jun 2024 08:50:37 +0200 Subject: [PATCH] Update local-iperator to latest ufl/ffc/ffcx version. Split toml deps for each compiler. --- compilers.yaml | 6 ++-- ffcx/compile.py | 28 ++++++++----------- forms/Elasticity.ufl | 30 ++++++++++++++++---- forms/Laplacian.ufl | 29 ++++++++++++++++--- pyproject.toml | 66 ++++++++++++++++++++++++++++++++++++++++++++ run.py | 2 +- utils.py | 4 +-- 7 files changed, 134 insertions(+), 31 deletions(-) create mode 100644 pyproject.toml diff --git a/compilers.yaml b/compilers.yaml index 74676ba..7b504ce 100644 --- a/compilers.yaml +++ b/compilers.yaml @@ -2,8 +2,8 @@ gcc-10: version: - 10 cpp: - - g++-10 + - g++-13 cc: - - gcc-10 + - gcc-13 flags: - - -Ofast -march=native -mprefer-vector-width=256 \ No newline at end of file + - -Ofast -march=native -mprefer-vector-width=256 diff --git a/ffcx/compile.py b/ffcx/compile.py index 334cca3..5002b8d 100644 --- a/ffcx/compile.py +++ b/ffcx/compile.py @@ -2,11 +2,9 @@ from ffcx.codegeneration.backend import FFCXBackend from ffcx.analysis import analyze_ufl_objects from ffcx.ir.representation import compute_ir -from ffcx.codegeneration.integrals import IntegralGenerator -from ffcx.element_interface import create_element -from ffcx.codegeneration.C.format_lines import format_indented_lines +from ffcx.codegeneration.integral_generator import IntegralGenerator +from ffcx.codegeneration.C.c_implementation import CFormatter from ffcx.options import get_options -import basix import ufl import typing import problem @@ -79,13 +77,14 @@ """ -def compute_integral_body(ir, backend): +def compute_integral_body(ir, backend, scalar_type): # Configure kernel generator ig = IntegralGenerator(ir, backend) # Generate code ast for the tabulate_tensor body parts = ig.generate() # Format code as string - body = format_indented_lines(parts.cs_format(ir.precision), 1) + CF = CFormatter(scalar_type) + body = CF.c_format(parts) return body @@ -97,7 +96,7 @@ def compile_form(form: ufl.Form, name: str, parameters = get_options() # Stage 1: analysis - analysis = analyze_ufl_objects([form], parameters) + analysis = analyze_ufl_objects([form], parameters["scalar_type"]) # Stage 2: intermediate representation ir = compute_ir(analysis, {}, " ", parameters, visualise) @@ -117,11 +116,10 @@ def compile_form(form: ufl.Form, name: str, if batch_size and batch_size > 1: geom_type += str(batch_size) scalar_type += str(batch_size) - settings = {"scalar_type": scalar_type, "geom_type": geom_type} arguments = _arguments.format(**settings) signature = "inline void " + name + arguments - body = compute_integral_body(integral_ir, backend) + body = compute_integral_body(integral_ir, backend, scalar_type) code = signature + " {\n" + body + "\n}\n" return code @@ -138,25 +136,23 @@ def generate_code(action, scalar_type, global_size, batch_size): if action: code = compile_form(problem.L, "kernel", parameters) num_coefficients = analyze_ufl_objects( - [problem.L], parameters).form_data[0].num_coefficients + [problem.L], scalar_type).form_data[0].num_coefficients rank = 1 else: code = compile_form(problem.a, "kernel", parameters) num_coefficients = analyze_ufl_objects( - [problem.a], parameters).form_data[0].num_coefficients + [problem.a], scalar_type).form_data[0].num_coefficients rank = 2 - - element = create_element(problem.element) - num_nodes = element.cell().num_vertices() + num_nodes = problem.element.cell.num_vertices() geom_type = scalar_type.replace(' _Complex', '') if batch_size > 1: - headers = _headers_batched.format(dim=element.dim, global_size=global_size, + headers = _headers_batched.format(dim=problem.element.dim, global_size=global_size, scalar_type=scalar_type, rank=rank, geom_type=geom_type, batch_size=batch_size, num_nodes=num_nodes, num_coefficients=num_coefficients) else: - headers = _headers.format(dim=element.dim, global_size=global_size, + headers = _headers.format(dim=problem.element.dim, global_size=global_size, scalar_type=scalar_type, rank=rank, geom_type=geom_type, batch_size=batch_size, num_nodes=num_nodes, num_coefficients=num_coefficients) diff --git a/forms/Elasticity.ufl b/forms/Elasticity.ufl index 4f06939..854879f 100644 --- a/forms/Elasticity.ufl +++ b/forms/Elasticity.ufl @@ -1,14 +1,34 @@ -from ufl import * +backend = "$backend" +if backend == "ffcx": + from ufl import * + import basix.ufl +elif backend == "ffc": + from ufl_legacy import * +elif backend == "tsfc": + from ufl import * + from finat.ufl import FiniteElement, VectorElement +else: + raise ValueError("Invalid backend: {}".format(backend)) -element = VectorElement("Lagrange", $cell, $degree) -mesh = Mesh(VectorElement("Lagrange", $cell, 1)) + +if backend == "ffc" or backend == "tsfc": + c_el = VectorElement("Lagrange", "$cell", 1) + element = VectorElement("Lagrange", "$cell", $degree) + s_el = FiniteElement("Lagrange", "$cell", 1) +else: + gdim = basix.cell.geometry(basix.cell.string_to_type("$cell")).shape[1] + c_el = basix.ufl.element("Lagrange", "$cell", 1, shape=(gdim, )) + element = basix.ufl.element("Lagrange", "$cell", $degree, shape=(gdim, )) + s_el = basix.ufl.element("Lagrange", "$cell", 1) + +mesh = Mesh(c_el) V = FunctionSpace(mesh, element) u = TrialFunction(V) v = TestFunction(V) -W = FunctionSpace(mesh, FiniteElement("Lagrange", $cell, 1)) +W = FunctionSpace(mesh, s_el) k = Coefficient(W) def eps(v): @@ -17,4 +37,4 @@ def eps(v): a = k*inner(eps(u), eps(v))*dx un = Coefficient(V) -L = action(a, un) \ No newline at end of file +L = action(a, un) diff --git a/forms/Laplacian.ufl b/forms/Laplacian.ufl index dca1be4..002cecd 100644 --- a/forms/Laplacian.ufl +++ b/forms/Laplacian.ufl @@ -1,13 +1,34 @@ -from ufl import * +backend = "$backend" +if backend == "ffcx": + from ufl import * + import basix.ufl +elif backend == "ffc": + from ufl_legacy import * +elif backend == "tsfc": + from ufl import * + from finat.ufl import FiniteElement +else: + raise ValueError("Invalid backend: {}".format(backend)) -element = FiniteElement("Lagrange", $cell, $degree) -mesh = Mesh(VectorElement("Lagrange", $cell, 1)) + +if backend == "ffc" or backend == "tsfc": + c_el = VectorElement("Lagrange", "$cell", 1) + element = FiniteElement("Lagrange", "$cell", $degree) + s_el = element.sub(0) +else: + gdim = basix.cell.geometry(basix.cell.string_to_type("$cell")).shape[1] + c_el = basix.ufl.element("Lagrange", "$cell", 1, shape=(gdim, )) + element = basix.ufl.element("Lagrange", "$cell", $degree, shape=(gdim, )) + s_el = basix.ufl.element("Lagrange", "$cell", 1) + + +mesh = Mesh(c_el) V = FunctionSpace(mesh, element) u = TrialFunction(V) v = TestFunction(V) -W = FunctionSpace(mesh, FiniteElement("Lagrange", $cell, 1)) +W = FunctionSpace(mesh, s_el) k = Coefficient(W) a = k*inner(grad(u), grad(v))*dx diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d30c2d7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,66 @@ +[build-system] +requires = ["setuptools>=61.2"] +build-backend = "setuptools.build_meta" + +[project] +name = "local_operator" +version = "0.1.0" +dependencies = ["pyyaml"] + +[project.optional-dependencies] +ffcx = [ + "fenics-ufl@git+https://github.com/FEniCS/ufl.git@main", + "fenics-basix@git+https://github.com/FEniCS/basix.git@main", + "fenics-ffcx@git+https://github.com/FEniCS/ffcx.git@main", +] +tsfc = [ + "fenics-ufl@git+https://github.com/firedrakeproject/ufl.git", + "fenics-fiat@git+https://github.com/firedrakeproject/fiat.git", + "finat@git+https://github.com/FInAT/FInAT.git", + "loopy@git+https://github.com/firedrakeproject/loopy.git", + "tsfc@git+https://github.com/firedrakeproject/tsfc.git", +] +ffc = [ + "fenics-ufl-legacy@git+https://github.com/FEniCS/ufl-legacy.git", + "fenics-dijitso@git+https://bitbucket.org/fenics-project/dijitso.git", + "fenics-fiat@git+https://bitbucket.org/fenics-project/fiat.git", + "fenics-ffc@git+https://bitbucket.org/fenics-project/ffc.git", +] + +[tool.setuptools] +packages = [] + + +[tool.mypy] +ignore_missing_imports = true + + +[tool.ruff] +line-length = 100 +indent-width = 4 + +[tool.ruff.lint] +select = [ + # Pyflakes + "F", + # Pycodestyle + "E", + "W", + # isort + "I001", +] + + +[tool.ruff.lint.isort] +known-third-party = ["basix", "ffcx", "ufl", "ufl_legacy", "tsfc"] +section-order = [ + "future", + "standard-library", + "mpi", + "third-party", + "first-party", + "local-folder", +] + +[tool.ruff.lint.isort.sections] +"mpi" = ["mpi4py", "petsc4py"] diff --git a/run.py b/run.py index 2f7389a..a204c8b 100644 --- a/run.py +++ b/run.py @@ -73,7 +73,7 @@ text = f"\n{machine}, {problem}, {c_name}, {compiler_version}, {flag}, {degree}, {form_compiler}, {scalar_type}, {batch_size}, {cell_type}, " results = utils.run(problem, degree, nrepeats, flag, action, scalar_type, global_size, batch_size, - mpi_size, cell_type) + mpi_size, cell_type, form_compiler) for result in results: row = text + f"{rank}, {result}" with open(out_file, "a") as file: diff --git a/utils.py b/utils.py index 1cb91a3..5aa2214 100644 --- a/utils.py +++ b/utils.py @@ -56,7 +56,7 @@ def create_ouput(problem): def run(problem: str, degree: int, nrepeats: int, flag: str, action: bool, scalar_type: str, global_size: int, batch_size: int, mpi_size: int, - cell_type: str): + cell_type: str, form_compiler: str): try: import ffcx @@ -67,7 +67,7 @@ def run(problem: str, degree: int, nrepeats: int, flag: str, action: bool, with open("forms/" + problem + ".ufl", 'r') as f: src = Template(f.read()) d = {'degree': str(degree), 'vdegree': str( - degree + 1), "cell": cell_type} + degree + 1), "cell": cell_type, "backend": form_compiler} result = src.substitute(d) with open("ffcx/problem.py", "w") as f2: