Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compilers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- -Ofast -march=native -mprefer-vector-width=256
28 changes: 12 additions & 16 deletions ffcx/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)

Expand Down
30 changes: 25 additions & 5 deletions forms/Elasticity.ufl
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -17,4 +37,4 @@ def eps(v):
a = k*inner(eps(u), eps(v))*dx

un = Coefficient(V)
L = action(a, un)
L = action(a, un)
29 changes: 25 additions & 4 deletions forms/Laplacian.ufl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
66 changes: 66 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down