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 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 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
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
47 changes: 26 additions & 21 deletions examples/euler/acoustic_pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@

import pyopencl as cl
import pyopencl.tools as cl_tools
from arraycontext import ArrayContext
from meshmode.mesh import BTAG_ALL
from arraycontext import ArrayContext, NumpyArrayContext
from meshmode.discretization.poly_element import (
InterpolatoryEdgeClusteredGroupFactory,
QuadratureGroupFactory,
)
from meshmode.mesh import BTAG_ALL, SimplexElementGroup, TensorProductElementGroup
from pytools.obj_array import make_obj_array

import grudge.op as op
from grudge.array_context import PyOpenCLArrayContext, PytatoPyOpenCLArrayContext
from grudge.array_context import PytatoPyOpenCLArrayContext
from grudge.models.euler import ConservedEulerField, EulerOperator, InviscidWallBC
from grudge.shortcuts import rk4_step

Expand Down Expand Up @@ -106,7 +110,8 @@ def run_acoustic_pulse(actx,
final_time=1,
resolution=16,
overintegration=False,
visualize=False):
visualize=False,
tensor_product_elements=False):

# eos-related parameters
gamma = 1.4
Expand All @@ -115,18 +120,19 @@ def run_acoustic_pulse(actx,

from meshmode.mesh.generation import generate_regular_rect_mesh

if tensor_product_elements:
group_cls = TensorProductElementGroup
else:
group_cls = SimplexElementGroup

dim = 2
box_ll = -0.5
box_ur = 0.5
mesh = generate_regular_rect_mesh(
a=(box_ll,)*dim,
b=(box_ur,)*dim,
nelements_per_axis=(resolution,)*dim)

from meshmode.discretization.poly_element import (
QuadratureSimplexGroupFactory,
default_simplex_group_factory,
)
nelements_per_axis=(resolution,)*dim,
group_cls=group_cls)

from grudge.discretization import make_discretization_collection
from grudge.dof_desc import DISCR_TAG_BASE, DISCR_TAG_QUAD
Expand All @@ -141,9 +147,8 @@ def run_acoustic_pulse(actx,
dcoll = make_discretization_collection(
actx, mesh,
discr_tag_to_group_factory={
DISCR_TAG_BASE: default_simplex_group_factory(
base_dim=mesh.dim, order=order),
DISCR_TAG_QUAD: QuadratureSimplexGroupFactory(2*order)
DISCR_TAG_BASE: InterpolatoryEdgeClusteredGroupFactory(order=order),
DISCR_TAG_QUAD: QuadratureGroupFactory(2*order)
}
)

Expand Down Expand Up @@ -208,7 +213,8 @@ def rhs(t, q):


def main(ctx_factory, order=3, final_time=1, resolution=16,
overintegration=False, visualize=False, lazy=False):
overintegration=False, visualize=False, lazy=False,
tensor_product_elements=False):
cl_ctx = ctx_factory()
queue = cl.CommandQueue(cl_ctx)

Expand All @@ -218,26 +224,24 @@ def main(ctx_factory, order=3, final_time=1, resolution=16,
allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)),
)
else:
actx = PyOpenCLArrayContext(
queue,
allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)),
force_device_scalars=True,
)
actx = NumpyArrayContext()

run_acoustic_pulse(
actx,
order=order,
resolution=resolution,
overintegration=overintegration,
final_time=final_time,
visualize=visualize
visualize=visualize,
tensor_product_elements=tensor_product_elements
)


if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--tpe", action="store_true")
parser.add_argument("--order", default=3, type=int)
parser.add_argument("--tfinal", default=0.1, type=float)
parser.add_argument("--resolution", default=16, type=int)
Expand All @@ -256,4 +260,5 @@ def main(ctx_factory, order=3, final_time=1, resolution=16,
resolution=args.resolution,
overintegration=args.oi,
visualize=args.visualize,
lazy=args.lazy)
lazy=args.lazy,
tensor_product_elements=args.tpe)
33 changes: 33 additions & 0 deletions grudge/array_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
from pytools import to_identifier
from pytools.tag import Tag

from grudge.transform.metadata import OutputIsTensorProductDOFArrayOrdered


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -140,6 +142,33 @@ def __init__(self, queue: "pyopencl.CommandQueue",
super().__init__(queue, allocator,
wait_event_queue_length, force_device_scalars)

def transform_loopy_program(self, t_unit):
knl = t_unit.default_entrypoint

# {{{ process tensor product specific metadata

# NOTE: This differs from the lazy case b/c we don't have access to axis
# tags that can be manipulated pre-execution. In eager, we update
# strides/loop nest ordering for the output array
if knl.tags_of_type(OutputIsTensorProductDOFArrayOrdered):
new_args = []
for arg in knl.args:
if arg.is_output:
arg = arg.copy(dim_tags=(
f"N{len(arg.shape)-1},"
+ ",".join(f"N{i}"
for i in range(len(arg.shape)-1))
))

new_args.append(arg)

knl = knl.copy(args=new_args)
t_unit = t_unit.with_kernel(knl)

# }}}

return super().transform_loopy_program(t_unit)

# }}}


Expand Down Expand Up @@ -170,6 +199,9 @@ def __init__(self, queue, allocator=None,
super().__init__(queue, allocator,
compile_trace_callback=compile_trace_callback)

def transform_loopy_program(self, t_unit):
return t_unit

# }}}


Expand Down Expand Up @@ -558,6 +590,7 @@ def __call__(self):


class PytestNumpyArrayContextFactory(_PytestNumpyArrayContextFactory):
from arraycontext import NumpyArrayContext
actx_class = NumpyArrayContext

def __call__(self):
Expand Down
Loading
Loading