Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fast operator evaluation for tensor-product discretizations #362

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
8bd3969
start updating grad
a-alveyblanc Jul 25, 2024
0afe732
add TODOs
a-alveyblanc Jul 25, 2024
9c4c150
add strong form tensor product gradient
a-alveyblanc Jul 26, 2024
c264cf9
Merge branch 'main' of https://github.com/inducer/grudge into tensor-…
a-alveyblanc Aug 31, 2024
e105a64
start working on weak-overint case for TP elements
a-alveyblanc Sep 5, 2024
a3f7f7e
start brainstorming better ways to handle weak overintegration
a-alveyblanc Sep 6, 2024
830c2e0
small changes
a-alveyblanc Sep 6, 2024
102f6e0
do not support overintegration (yet)
a-alveyblanc Sep 6, 2024
597fcc9
fix gradient tests
a-alveyblanc Sep 6, 2024
790ab13
fix tensor product gradient
a-alveyblanc Sep 6, 2024
91e3121
do not compute stiffness matrix; apply mass to all axes and diff op t…
a-alveyblanc Sep 6, 2024
9ff324b
arg name change
a-alveyblanc Sep 6, 2024
7b50e32
add fast operator eval for weak and strong divergence
a-alveyblanc Sep 6, 2024
230c1bd
add tensor product inverse mass
a-alveyblanc Sep 6, 2024
30f984e
tag mass operator as such
a-alveyblanc Sep 6, 2024
92b54a2
add fast operator eval for mass operator application
a-alveyblanc Sep 7, 2024
34b1cd6
toward overintegration support
a-alveyblanc Sep 7, 2024
b8e312e
minor changes to adjust for changes in pytato
a-alveyblanc Sep 8, 2024
a79a603
adjust operators to accept 1D tensor product discretizations
a-alveyblanc Sep 8, 2024
51884a7
Merge branch 'main' of https://github.com/inducer/grudge into tensor-…
a-alveyblanc Sep 9, 2024
c8d0a92
checkpoint before adding wadg + overintegration + fast operator evalu…
a-alveyblanc Sep 12, 2024
ad0d2e4
tag axes of grad result
a-alveyblanc Sep 12, 2024
ca22480
add WADG + overintegration for simplices
a-alveyblanc Sep 12, 2024
092a6cc
add WADG + overintegration for simplices
a-alveyblanc Sep 12, 2024
bea91ad
start fixing up fast operator eval + overintegration + wadg
a-alveyblanc Sep 13, 2024
8182571
small changes
a-alveyblanc Sep 16, 2024
4cacc6b
overintegration + fast operator evaluation
a-alveyblanc Sep 19, 2024
73ba29a
first round of clean-ups
a-alveyblanc Sep 19, 2024
0a431d4
start updating face mass for TP
a-alveyblanc Sep 23, 2024
3dfaeec
undo face mass changes; add rough version of bilinear form evaluator
a-alveyblanc Oct 4, 2024
851a1f9
rename bilinear forms file; add rough draft of SeparableBilinearForm
a-alveyblanc Oct 4, 2024
91c87df
minor change: fix typing on generic dispatching function
a-alveyblanc Oct 4, 2024
351ae62
changes after review; bilinear forms now only internal
a-alveyblanc Oct 8, 2024
d174c40
get things working with quadrature; improve test_mass_operator_inverse
a-alveyblanc Oct 13, 2024
21a5855
remove unused variable
a-alveyblanc Oct 13, 2024
4e8b5f8
remove large refined mesh files
a-alveyblanc Oct 13, 2024
16f7f36
add default quadrature for computing bilinear forms
a-alveyblanc Oct 22, 2024
4d8d468
get all tests passing with quadrature rules + numpy array context
a-alveyblanc Oct 27, 2024
5b53482
fix merge conflicts
a-alveyblanc Oct 27, 2024
0a91985
some ruff fixes
a-alveyblanc Oct 28, 2024
53abda5
fix failing MPI wave op test
a-alveyblanc Oct 29, 2024
943f9ca
add redundant mass/inverse mass mappers
a-alveyblanc Oct 31, 2024
fa5b24e
remove 2x refined gh-339 mesh
a-alveyblanc Nov 1, 2024
5c74b6e
toward transformations
a-alveyblanc Nov 9, 2024
8898863
resolve merge conflicts
a-alveyblanc Nov 9, 2024
19f7a49
some dag rewriter work; restrict fast operator eval to non-overintegr…
a-alveyblanc Nov 13, 2024
2dfd7ff
rewrite operators to be more predictable in the DAG
a-alveyblanc Nov 13, 2024
9359246
remove tagging for now
a-alveyblanc Nov 13, 2024
da6dff7
bypass WADG if base and quad discretizations are the same
a-alveyblanc Nov 14, 2024
3f88f04
initial algebraic dag xforms for tp
a-alveyblanc Nov 16, 2024
5bd67ed
algebraic transforms v0.1
a-alveyblanc Nov 17, 2024
5a95360
basic (more like primitive) parallelization scheme; add more dag tran…
a-alveyblanc Nov 17, 2024
8c5be5a
ruff fixes
a-alveyblanc Nov 17, 2024
aad468a
changes to make ruff and pylint happy
a-alveyblanc Nov 17, 2024
7f8fb0e
ruff fix
a-alveyblanc Nov 17, 2024
654dd36
remove ghost nodes left over after TP DAG xforms
a-alveyblanc Nov 18, 2024
7819616
update some docs; fix dim from num faces computation
a-alveyblanc Nov 19, 2024
6a84f74
op refactor updates + transform updates
a-alveyblanc Dec 16, 2024
f6fd35d
move matrices to their own file and update operators accordingly
a-alveyblanc Dec 20, 2024
5b23379
all tests passing except mpi tests
a-alveyblanc Dec 24, 2024
3b69323
all tests passing; disable xforms for now
a-alveyblanc Dec 24, 2024
65cfe02
attempt to resolve missing axis tags; minor transform changes
a-alveyblanc Dec 30, 2024
d46246a
track down final culprit for untagged axes
a-alveyblanc Dec 31, 2024
a70cdb3
add name hints and propert tags to matrices
a-alveyblanc Jan 3, 2025
567637c
re-implementation of tp transforms
a-alveyblanc Jan 5, 2025
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
Prev Previous commit
Next Next commit
algebraic transforms v0.1
  • Loading branch information
a-alveyblanc committed Nov 17, 2024
commit 5bd67edec233fa76820cee112fb9a0a878fd52a8
34 changes: 13 additions & 21 deletions grudge/array_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,6 @@ class PytatoPyOpenCLArrayContext(_PytatoPyOpenCLArrayContextBase):
which there isn't any, for now.)
"""

dot_codes_before: list[str] = []
dot_codes_after: list[str] = []

num_nodes_before: int = 0
num_nodes_after: int = 0

device_code: str = ""

def __init__(self, queue, allocator=None,
*,
compile_trace_callback: Callable[[Any, str, Any], None] | None
Expand All @@ -251,21 +243,23 @@ def __init__(self, queue, allocator=None,

def transform_dag(self, dag):

self.num_nodes_before += get_num_nodes(dag)
self.dot_codes_before.append(pt.visualization.get_dot_graph(dag))

# {{{ tensor-product algebraic DAG rewrites

# FIXME: remove after enough cases have been tested
if 1:
# step 1: distribute mass inverse through DAG, across index lambdas
dag = InverseMassPropagator()(dag)
num_nodes_before = get_num_nodes(dag)
# step 1: distribute mass inverse through DAG, across index lambdas
dag = InverseMassPropagator()(dag)

# step 2: remove mass-times-mass-inverse einsums
dag = InverseMassRemover()(dag)

# step 2: remove mass-times-mass-inverse einsums
dag = InverseMassRemover()(dag)
# step 3: create new operator out of inverse mass times stiffness
dag = MassInverseTimesStiffnessSimplifier()(dag)
num_nodes_after = get_num_nodes(dag)

# step 3: create new operator out of inverse mass times stiffness
dag = MassInverseTimesStiffnessSimplifier()(dag)
if num_nodes_before != num_nodes_after:
logger.info("tensor-product xforms: %d nodes via tensor-product "
"algebraic transformations ",
num_nodes_before - num_nodes_after)

# }}}

Expand All @@ -283,8 +277,6 @@ def eliminate_reshapes_of_data_wrappers(ary):

dag = pt.transform.map_and_copy(dag,
eliminate_reshapes_of_data_wrappers)
self.dot_codes_after.append(pt.visualization.get_dot_graph(dag))
self.num_nodes_after += get_num_nodes(dag)

return dag

Expand Down
31 changes: 21 additions & 10 deletions grudge/bilinear_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def _compute_reference_gradient(self, vec: DOFArray) -> DOFArray:
self.output_group.space,
reference_gradient[rst_axis])

return DOFArray(self.actx, data=tuple(reference_gradient))
return reference_gradient

def mass_operator(self, vec: DOFArray,
exclude_axis: int | None = None,
Expand Down Expand Up @@ -541,20 +541,31 @@ def divergence_operator(self, vec: DOFArray) -> DOFArray:
derivative in the field.
"""

vec = vec * self.area_element
vec = vec * self.area_element * self.metric_terms

if self.input_group.dim != 1:
vec = fold(self.input_group.space, vec)

reference_gradients = DOFArray(self.actx, data=tuple([
self._compute_reference_gradient(vec[func_axis])
for func_axis in range(self.input_group.dim)]))
div = 0.0
for xyz_axis in range(self.input_group.dim):
partial = 0.0
for rst_axis in range(self.input_group.dim):
reference_partial = self.mass_operator(
vec[xyz_axis, rst_axis],
exclude_axis=rst_axis,
exclude_metric=True)

return self.actx.einsum(
"xrej,xrej->ej",
self.metric_terms,
reference_gradients,
arg_names=("metrics", "vec"))
partial += single_axis_contraction(
self.actx, self.input_group.dim, rst_axis,
self._stiffness_operator, reference_partial,
arg_names=("stiffness_1d",
f"ref_partial_{rst_axis}"))

if self.input_group.dim != 1:
partial = unfold(self.output_group.space, partial)
div += partial

return div

def derivative_operator(self, vec: DOFArray, derivative: int) -> DOFArray:
"""
Expand Down
6 changes: 2 additions & 4 deletions test/test_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ def get_flux(u_tpair, dcoll=dcoll):
vis.write_vtk_file(filename, [
("u", u),
("grad_u", grad_u),
("expected_grad_u", expected_grad_u),
], overwrite=True)
("expected_grad_u", expected_grad_u), ], overwrite=True)

rel_linf_err = actx.to_numpy(
op.norm(dcoll, grad_u - expected_grad_u, np.inf)
Expand All @@ -254,7 +253,6 @@ def get_flux(u_tpair, dcoll=dcoll):
@pytest.mark.parametrize("form", ["strong", "weak", "weak-overint"])
@pytest.mark.parametrize("dim", [1, 2, 3])
@pytest.mark.parametrize("order", [2, 3])
@pytest.mark.parametrize("warp_mesh", [True])
@pytest.mark.parametrize(("vectorize", "nested"), [
(False, False),
(True, False),
Expand All @@ -265,7 +263,7 @@ def get_flux(u_tpair, dcoll=dcoll):
TensorProductElementGroup
])
def test_divergence(actx_factory, form, dim, order, vectorize, nested,
group_cls, warp_mesh, visualize=False):
group_cls, visualize=False):

actx = actx_factory()

Expand Down