diff --git a/doc/conf.py b/doc/conf.py index 4665159d9..362edebee 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,4 +1,5 @@ # -- Project information ----------------------------------------------------- +import sys project = "mirgecom" copyright = ("2020, University of Illinois Board of Trustees") @@ -97,3 +98,5 @@ nitpick_ignore_regex = [ ("py:class", r".*BoundaryDomainTag.*") ] + +sys._BUILDING_SPHINX_DOCS = True diff --git a/doc/support/tools.rst b/doc/support/tools.rst index d29d63c2e..196fe56fd 100644 --- a/doc/support/tools.rst +++ b/doc/support/tools.rst @@ -3,3 +3,4 @@ Random Pile'o'Tools .. automodule:: mirgecom.simutil .. automodule:: mirgecom.utils +.. automodule:: mirgecom.array_context diff --git a/examples/autoignition-mpi.py b/examples/autoignition-mpi.py index 16dfe379b..48963d3a7 100644 --- a/examples/autoignition-mpi.py +++ b/examples/autoignition-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL @@ -75,13 +74,11 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_overintegration=False, use_profiling=False, - casename=None, lazy=False, rst_filename=None, log_dependent=True, +def main(actx_class, use_logmgr=True, + use_leap=False, use_overintegration=False, + casename=None, rst_filename=None, log_dependent=True, viscous_terms_on=False): """Drive example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -96,19 +93,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue(cl_ctx, - properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # Some discretization parameters dim = 2 @@ -690,8 +678,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -701,8 +690,8 @@ def my_rhs(t, state): rst_filename = args.restart_file main(actx_class, use_logmgr=args.log, use_leap=args.leap, - use_overintegration=args.overintegration, use_profiling=args.profiling, - lazy=lazy, casename=casename, rst_filename=rst_filename, + use_overintegration=args.overintegration, + casename=casename, rst_filename=rst_filename, log_dependent=log_dependent, viscous_terms_on=args.navierstokes) # vim: foldmethod=marker diff --git a/examples/combozzle-mpi.py b/examples/combozzle-mpi.py index 331c5608d..2aedd8730 100644 --- a/examples/combozzle-mpi.py +++ b/examples/combozzle-mpi.py @@ -27,7 +27,6 @@ import time import yaml import numpy as np -import pyopencl as cl from functools import partial from meshmode.array_context import PyOpenCLArrayContext @@ -160,15 +159,12 @@ def __call__(self, x_vec, *, time=0.0): @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_overintegration=False, - use_profiling=False, casename=None, lazy=False, +def main(use_logmgr=True, + use_overintegration=False, casename=None, rst_filename=None, actx_class=PyOpenCLArrayContext, log_dependent=False, input_file=None, force_eval=True): """Drive example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -600,19 +596,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, print(f"ACTX setup start: {time.ctime(time.time())}") comm.Barrier() - if use_profiling: - queue = cl.CommandQueue(cl_ctx, - properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) rst_path = "restart_data/" rst_pattern = ( @@ -1287,8 +1274,9 @@ def dummy_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -1306,9 +1294,8 @@ def dummy_rhs(t, state): print(f"Calling main: {time.ctime(time.time())}") - main(use_logmgr=args.log, use_leap=args.leap, input_file=input_file, + main(use_logmgr=args.log, input_file=input_file, use_overintegration=args.overintegration, - use_profiling=args.profiling, lazy=lazy, casename=casename, rst_filename=rst_filename, actx_class=actx_class, log_dependent=log_dependent, force_eval=force_eval) diff --git a/examples/doublemach-mpi.py b/examples/doublemach-mpi.py index f249c7d80..e7454a167 100644 --- a/examples/doublemach-mpi.py +++ b/examples/doublemach-mpi.py @@ -26,7 +26,6 @@ import logging import numpy as np -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -116,15 +115,13 @@ def get_doublemach_mesh(): @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, use_overintegration=False, - casename=None, rst_filename=None, actx_class=None, lazy=False): +def main(use_logmgr=True, + use_leap=False, use_overintegration=False, + casename=None, rst_filename=None, actx_class=None): """Drive the example.""" if actx_class is None: raise RuntimeError("Array context class missing.") - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -136,19 +133,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # Timestepping control current_step = 0 @@ -461,8 +449,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True, + profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -471,8 +460,8 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(use_logmgr=args.log, use_leap=args.leap, use_profiling=args.profiling, - use_overintegration=args.overintegration, lazy=lazy, + main(use_logmgr=args.log, use_leap=args.leap, + use_overintegration=args.overintegration, casename=casename, rst_filename=rst_filename, actx_class=actx_class) # vim: foldmethod=marker diff --git a/examples/doublemach_physical_av-mpi.py b/examples/doublemach_physical_av-mpi.py index d667da451..8c462ed23 100644 --- a/examples/doublemach_physical_av-mpi.py +++ b/examples/doublemach_physical_av-mpi.py @@ -26,7 +26,6 @@ import logging import numpy as np -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -120,15 +119,13 @@ def get_doublemach_mesh(): @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, use_overintegration=False, - casename=None, rst_filename=None, actx_class=None, lazy=False): +def main(use_logmgr=True, + use_leap=False, use_overintegration=False, + casename=None, rst_filename=None, actx_class=None): """Drive the example.""" if actx_class is None: raise RuntimeError("Array context class missing.") - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -151,19 +148,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=logname, mode="wo", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # Timestepping control current_step = 0 @@ -732,9 +720,10 @@ def _my_rhs_phys_visc_div_av(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class + from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class(lazy=lazy, - distributed=True) + distributed=True, + profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -743,8 +732,8 @@ def _my_rhs_phys_visc_div_av(t, state): if args.restart_file: rst_filename = args.restart_file - main(use_logmgr=args.log, use_leap=args.leap, use_profiling=args.profiling, - use_overintegration=args.overintegration, lazy=lazy, + main(use_logmgr=args.log, use_leap=args.leap, + use_overintegration=args.overintegration, casename=casename, rst_filename=rst_filename, actx_class=actx_class) # vim: foldmethod=marker diff --git a/examples/heat-source-mpi.py b/examples/heat-source-mpi.py index 37b208a7d..18ecf36c6 100644 --- a/examples/heat-source-mpi.py +++ b/examples/heat-source-mpi.py @@ -25,7 +25,6 @@ import numpy as np import numpy.linalg as la # noqa -import pyopencl as cl from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa import grudge.op as op @@ -48,13 +47,9 @@ @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, lazy=False, - rst_filename=None): +def main(actx_class, use_logmgr=True, + use_leap=False, casename=None, rst_filename=None): """Run the example.""" - cl_ctx = cl.create_some_context() - queue = cl.CommandQueue(cl_ctx) - from mpi4py import MPI comm = MPI.COMM_WORLD num_parts = comm.Get_size() @@ -62,19 +57,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename="heat-source.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) from meshmode.distributed import MPIMeshDistributor, get_partition_by_pymetis mesh_dist = MPIMeshDistributor(comm) @@ -208,8 +194,9 @@ def rhs(t, u): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -218,7 +205,7 @@ def rhs(t, u): if args.restart_file: rst_filename = args.restart_file - main(actx_class, use_logmgr=args.log, use_leap=args.leap, lazy=lazy, - use_profiling=args.profiling, casename=casename, rst_filename=rst_filename) + main(actx_class, use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/hotplate-mpi.py b/examples/hotplate-mpi.py index e08fda011..f9cd042b2 100644 --- a/examples/hotplate-mpi.py +++ b/examples/hotplate-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -81,15 +80,13 @@ def _get_box_mesh(dim, a, b, n, t=None): @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, - rst_filename=None, actx_class=None, lazy=False): +def main(use_logmgr=True, + use_leap=False, casename=None, + rst_filename=None, actx_class=None): """Drive the example.""" if actx_class is None: raise RuntimeError("Array context class missing.") - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -104,19 +101,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control timestepper = rk4_step @@ -465,8 +453,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -475,8 +464,7 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(use_logmgr=args.log, use_leap=args.leap, use_profiling=args.profiling, - casename=casename, rst_filename=rst_filename, actx_class=actx_class, - lazy=lazy) + main(use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename, actx_class=actx_class) # vim: foldmethod=marker diff --git a/examples/lump-mpi.py b/examples/lump-mpi.py index b26d9a58f..6129a6e32 100644 --- a/examples/lump-mpi.py +++ b/examples/lump-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -66,12 +65,9 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, lazy=False, - rst_filename=None): +def main(actx_class, use_logmgr=True, + use_leap=False, casename=None, rst_filename=None): """Drive example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -86,19 +82,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue(cl_ctx, - properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control if use_leap: @@ -385,8 +372,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -395,7 +383,7 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(actx_class, use_logmgr=args.log, use_leap=args.leap, lazy=lazy, - use_profiling=args.profiling, casename=casename, rst_filename=rst_filename) + main(actx_class, use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/mixture-mpi.py b/examples/mixture-mpi.py index 5a8215f78..ea88431b4 100644 --- a/examples/mixture-mpi.py +++ b/examples/mixture-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -72,12 +71,10 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, rst_filename=None, - log_dependent=False, lazy=False): +def main(actx_class, use_logmgr=True, + use_leap=False, casename=None, rst_filename=None, + log_dependent=False): """Drive example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -92,19 +89,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control if use_leap: @@ -464,8 +452,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -474,8 +463,8 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(actx_class, use_logmgr=args.log, use_leap=args.leap, lazy=lazy, - use_profiling=args.profiling, casename=casename, rst_filename=rst_filename, + main(actx_class, use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename, log_dependent=log_dependent) # vim: foldmethod=marker diff --git a/examples/multiple-volumes-mpi.py b/examples/multiple-volumes-mpi.py index 67d466d80..55648ba3c 100644 --- a/examples/multiple-volumes-mpi.py +++ b/examples/multiple-volumes-mpi.py @@ -33,7 +33,6 @@ from mirgecom.mpi import mpi_entry_point import numpy as np from functools import partial -import pyopencl as cl from pytools.obj_array import make_obj_array from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -82,12 +81,10 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_overintegration=False, lazy=False, use_leap=False, use_profiling=False, +def main(actx_class, use_logmgr=True, + use_overintegration=False, use_leap=False, casename=None, rst_filename=None): """Drive the example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -102,19 +99,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control current_step = 0 @@ -408,8 +396,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -419,7 +408,7 @@ def my_rhs(t, state): rst_filename = args.restart_file main(actx_class, use_logmgr=args.log, use_overintegration=args.overintegration, - use_leap=args.leap, use_profiling=args.profiling, lazy=lazy, + use_leap=args.leap, casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/nsmix-mpi.py b/examples/nsmix-mpi.py index 4e88b1910..0a61030ff 100644 --- a/examples/nsmix-mpi.py +++ b/examples/nsmix-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from pytools.obj_array import make_obj_array @@ -78,16 +77,14 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, - rst_filename=None, actx_class=None, lazy=False, +def main(use_logmgr=True, + use_leap=False, casename=None, + rst_filename=None, actx_class=None, log_dependent=True, use_overintegration=False): """Drive example.""" if actx_class is None: raise RuntimeError("Array context class missing.") - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -102,19 +99,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # Timestepping control # This example runs only 3 steps by default (to keep CI ~short) @@ -643,8 +631,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -653,9 +642,9 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(use_logmgr=args.log, use_leap=args.leap, use_profiling=args.profiling, + main(use_logmgr=args.log, use_leap=args.leap, casename=casename, rst_filename=rst_filename, actx_class=actx_class, - log_dependent=log_dependent, lazy=lazy, + log_dependent=log_dependent, use_overintegration=args.overintegration) # vim: foldmethod=marker diff --git a/examples/poiseuille-local_dt-mpi.py b/examples/poiseuille-local_dt-mpi.py index 0b04656cc..2159093a4 100644 --- a/examples/poiseuille-local_dt-mpi.py +++ b/examples/poiseuille-local_dt-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from pytools.obj_array import make_obj_array from functools import partial @@ -72,16 +71,14 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, - use_overintegration=False, lazy=False, - use_leap=False, use_profiling=False, casename=None, +def main(use_logmgr=True, + use_overintegration=False, + use_leap=False, casename=None, rst_filename=None, actx_class=None): """Drive the example.""" if actx_class is None: raise RuntimeError("Array context class missing.") - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -96,19 +93,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control timestepper = rk4_step @@ -499,8 +487,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -509,8 +498,8 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(use_logmgr=args.log, use_leap=args.leap, use_profiling=args.profiling, - use_overintegration=args.overintegration, lazy=lazy, + main(use_logmgr=args.log, use_leap=args.leap, + use_overintegration=args.overintegration, casename=casename, rst_filename=rst_filename, actx_class=actx_class) # vim: foldmethod=marker diff --git a/examples/poiseuille-mpi.py b/examples/poiseuille-mpi.py index fdbf119e9..690dbe2ac 100644 --- a/examples/poiseuille-mpi.py +++ b/examples/poiseuille-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from pytools.obj_array import make_obj_array from functools import partial @@ -82,16 +81,14 @@ def _get_box_mesh(dim, a, b, n, t=None): @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, - use_overintegration=False, lazy=False, - use_leap=False, use_profiling=False, casename=None, +def main(use_logmgr=True, + use_overintegration=False, + use_leap=False, casename=None, rst_filename=None, actx_class=None): """Drive the example.""" if actx_class is None: raise RuntimeError("Array context class missing.") - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -106,19 +103,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control timestepper = rk4_step @@ -483,8 +471,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -493,8 +482,8 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(use_logmgr=args.log, use_leap=args.leap, use_profiling=args.profiling, - use_overintegration=args.overintegration, lazy=lazy, + main(use_logmgr=args.log, use_leap=args.leap, + use_overintegration=args.overintegration, casename=casename, rst_filename=rst_filename, actx_class=actx_class) # vim: foldmethod=marker diff --git a/examples/pulse-mpi.py b/examples/pulse-mpi.py index 5674ab57e..15b77ad1d 100644 --- a/examples/pulse-mpi.py +++ b/examples/pulse-mpi.py @@ -28,7 +28,6 @@ from mirgecom.mpi import mpi_entry_point import numpy as np from functools import partial -import pyopencl as cl from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from grudge.shortcuts import make_visualizer @@ -78,12 +77,10 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_overintegration=False, lazy=False, use_leap=False, use_profiling=False, +def main(actx_class, use_logmgr=True, + use_overintegration=False, use_leap=False, casename=None, rst_filename=None): """Drive the example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -98,19 +95,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control current_step = 0 @@ -393,8 +381,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -404,7 +393,7 @@ def my_rhs(t, state): rst_filename = args.restart_file main(actx_class, use_logmgr=args.log, use_overintegration=args.overintegration, - use_leap=args.leap, use_profiling=args.profiling, lazy=lazy, + use_leap=args.leap, casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/scalar-advdiff-mpi.py b/examples/scalar-advdiff-mpi.py index 9b88de6e6..abf3db45f 100644 --- a/examples/scalar-advdiff-mpi.py +++ b/examples/scalar-advdiff-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from pytools.obj_array import make_obj_array @@ -70,12 +69,10 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, - rst_filename=None, lazy=False): +def main(actx_class, use_logmgr=True, + use_leap=False, casename=None, + rst_filename=None): """Drive example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -90,19 +87,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control current_step = 0 @@ -423,8 +411,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True, + profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -433,7 +422,7 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(actx_class, use_logmgr=args.log, use_leap=args.leap, lazy=lazy, - use_profiling=args.profiling, casename=casename, rst_filename=rst_filename) + main(actx_class, use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/scalar-lump-mpi.py b/examples/scalar-lump-mpi.py index 6b0ee947c..8c14feb9c 100644 --- a/examples/scalar-lump-mpi.py +++ b/examples/scalar-lump-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from pytools.obj_array import make_obj_array @@ -67,12 +66,10 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, - rst_filename=None, lazy=False): +def main(actx_class, use_logmgr=True, + use_leap=False, casename=None, + rst_filename=None): """Drive example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -87,19 +84,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control current_step = 0 @@ -396,8 +384,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -406,7 +395,7 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(actx_class, use_logmgr=args.log, use_leap=args.leap, lazy=lazy, - use_profiling=args.profiling, casename=casename, rst_filename=rst_filename) + main(actx_class, use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/sod-mpi.py b/examples/sod-mpi.py index a8de0e204..acebeaea8 100644 --- a/examples/sod-mpi.py +++ b/examples/sod-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np # noqa -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -66,12 +65,10 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, lazy=False, +def main(actx_class, use_logmgr=True, + use_leap=False, casename=None, rst_filename=None): """Drive the example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -86,19 +83,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control if use_leap: @@ -384,8 +372,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -394,7 +383,7 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(actx_class, use_logmgr=args.log, use_leap=args.leap, lazy=lazy, - use_profiling=args.profiling, casename=casename, rst_filename=rst_filename) + main(actx_class, use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/thermally-coupled-mpi.py b/examples/thermally-coupled-mpi.py index 835a2f2a1..73c655671 100644 --- a/examples/thermally-coupled-mpi.py +++ b/examples/thermally-coupled-mpi.py @@ -29,7 +29,6 @@ import numpy as np from functools import partial from pytools.obj_array import make_obj_array -import pyopencl as cl from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa from meshmode.discretization.connection import FACE_RESTR_ALL # noqa @@ -157,13 +156,11 @@ def coupled_ns_heat_operator( @mpi_entry_point -def main(ctx_factory=cl.create_some_context, use_logmgr=True, +def main(use_logmgr=True, use_overintegration=False, - use_leap=False, use_profiling=False, casename=None, - rst_filename=None, actx_class=None, lazy=False): + use_leap=False, casename=None, + rst_filename=None, actx_class=None): """Drive the example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -178,19 +175,10 @@ def main(ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control current_step = 0 @@ -669,8 +657,9 @@ def my_rhs_and_gradients(t, state): if args.lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=args.lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=args.lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -680,8 +669,8 @@ def my_rhs_and_gradients(t, state): rst_filename = args.restart_file main(use_logmgr=args.log, use_overintegration=args.overintegration, - use_leap=args.leap, use_profiling=args.profiling, + use_leap=args.leap, casename=casename, rst_filename=rst_filename, actx_class=actx_class, - lazy=args.lazy) + ) # vim: foldmethod=marker diff --git a/examples/vortex-mpi.py b/examples/vortex-mpi.py index 47b69d933..3bbc69a02 100644 --- a/examples/vortex-mpi.py +++ b/examples/vortex-mpi.py @@ -25,7 +25,6 @@ """ import logging import numpy as np -import pyopencl as cl from functools import partial from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa @@ -68,12 +67,9 @@ class MyRuntimeError(RuntimeError): @mpi_entry_point -def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, - use_leap=False, use_profiling=False, casename=None, lazy=False, - rst_filename=None): +def main(actx_class, use_logmgr=True, + use_leap=False, casename=None, rst_filename=None): """Drive the example.""" - cl_ctx = ctx_factory() - if casename is None: casename = "mirgecom" @@ -88,19 +84,10 @@ def main(actx_class, ctx_factory=cl.create_some_context, use_logmgr=True, logmgr = initialize_logmgr(use_logmgr, filename=f"{casename}.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue( - cl_ctx, properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + use_profiling = actx_class_is_profiling(actx_class) # timestepping control current_step = 0 @@ -409,8 +396,9 @@ def my_rhs(t, state): if lazy: raise ValueError("Can't use lazy and profiling together.") - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class( + lazy=lazy, distributed=True, profiling=args.profiling) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: @@ -419,7 +407,7 @@ def my_rhs(t, state): if args.restart_file: rst_filename = args.restart_file - main(actx_class, use_logmgr=args.log, use_leap=args.leap, lazy=lazy, - use_profiling=args.profiling, casename=casename, rst_filename=rst_filename) + main(actx_class, use_logmgr=args.log, use_leap=args.leap, + casename=casename, rst_filename=rst_filename) # vim: foldmethod=marker diff --git a/examples/wave-mpi.py b/examples/wave-mpi.py index b9f25f4d9..5c6aecfae 100644 --- a/examples/wave-mpi.py +++ b/examples/wave-mpi.py @@ -23,29 +23,23 @@ """ import logging +import grudge.op as op import numpy as np import numpy.linalg as la # noqa -import pyopencl as cl - -from pytools.obj_array import flat_obj_array - -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa - from grudge.shortcuts import make_visualizer -import grudge.op as op +from logpyle import IntervalTimer, set_dt +from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from pytools.obj_array import flat_obj_array from mirgecom.discretization import create_discretization_collection -from mirgecom.mpi import mpi_entry_point from mirgecom.integrators import rk4_step -from mirgecom.wave import wave_operator -from mirgecom.utils import force_evaluation - -from logpyle import IntervalTimer, set_dt - from mirgecom.logging_quantities import (initialize_logmgr, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, - logmgr_add_mempool_usage,) + logmgr_add_mempool_usage) +from mirgecom.mpi import mpi_entry_point +from mirgecom.utils import force_evaluation +from mirgecom.wave import wave_operator def bump(actx, nodes, t=0): @@ -69,11 +63,8 @@ def bump(actx, nodes, t=0): @mpi_entry_point def main(actx_class, snapshot_pattern="wave-mpi-{step:04d}-{rank:04d}.pkl", - restart_step=None, use_profiling=False, use_logmgr=False, lazy=False): + restart_step=None, use_logmgr: bool = False) -> None: """Drive the example.""" - cl_ctx = cl.create_some_context() - queue = cl.CommandQueue(cl_ctx) - from mpi4py import MPI comm = MPI.COMM_WORLD rank = comm.Get_rank() @@ -81,23 +72,17 @@ def main(actx_class, snapshot_pattern="wave-mpi-{step:04d}-{rank:04d}.pkl", logmgr = initialize_logmgr(use_logmgr, filename="wave-mpi.sqlite", mode="wu", mpi_comm=comm) - if use_profiling: - queue = cl.CommandQueue(cl_ctx, - properties=cl.command_queue_properties.PROFILING_ENABLE) - else: - queue = cl.CommandQueue(cl_ctx) - from mirgecom.simutil import get_reasonable_memory_pool - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(comm, queue, mpi_base_tag=12000, allocator=alloc) - else: - actx = actx_class(comm, queue, allocator=alloc, force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, comm) + queue = getattr(actx, "queue", None) + alloc = getattr(actx, "allocator", None) + use_profiling = actx_class_is_profiling(actx_class) if restart_step is None: - from meshmode.distributed import MPIMeshDistributor, get_partition_by_pymetis + from meshmode.distributed import (MPIMeshDistributor, + get_partition_by_pymetis) mesh_dist = MPIMeshDistributor(comm) dim = 2 @@ -139,7 +124,9 @@ def main(actx_class, snapshot_pattern="wave-mpi-{step:04d}-{rank:04d}.pkl", from grudge.dt_utils import characteristic_lengthscales nodal_dt = characteristic_lengthscales(actx, dcoll) / wave_speed - dt = actx.to_numpy(current_cfl * op.nodal_min(dcoll, "vol", nodal_dt))[()] + dt = actx.to_numpy(current_cfl + * op.nodal_min(dcoll, + "vol", nodal_dt))[()] # type: ignore[index] t_final = 1 @@ -161,7 +148,8 @@ def main(actx_class, snapshot_pattern="wave-mpi-{step:04d}-{rank:04d}.pkl", if old_order != order: old_dcoll = create_discretization_collection( actx, local_mesh, order=old_order) - from meshmode.discretization.connection import make_same_mesh_connection + from meshmode.discretization.connection import \ + make_same_mesh_connection connection = make_same_mesh_connection(actx, dcoll.discr_from_dd("vol"), old_dcoll.discr_from_dd("vol")) fields = connection(restart_fields) @@ -247,7 +235,7 @@ def rhs(t, w): logmgr.close() final_soln = actx.to_numpy(op.norm(dcoll, fields[0], 2)) - assert np.abs(final_soln - 0.04409852463947439) < 1e-14 + assert np.abs(final_soln - 0.04409852463947439) < 1e-14 # type: ignore[operator] if __name__ == "__main__": @@ -264,9 +252,11 @@ def rhs(t, w): args = parser.parse_args() lazy = args.lazy - from grudge.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True) + from mirgecom.array_context import get_reasonable_array_context_class + actx_class = get_reasonable_array_context_class(lazy=lazy, + distributed=True, + profiling=args.profiling) - main(actx_class, use_profiling=args.profiling, use_logmgr=args.log, lazy=lazy) + main(actx_class, use_logmgr=args.log) # vim: foldmethod=marker diff --git a/examples/wave.py b/examples/wave.py index e1105bdf9..8631b71af 100644 --- a/examples/wave.py +++ b/examples/wave.py @@ -22,29 +22,20 @@ THE SOFTWARE. """ +import grudge.op as op import numpy as np -import numpy.linalg as la # noqa -import pyopencl as cl -import pyopencl.array as cla # noqa - -from pytools.obj_array import flat_obj_array - from grudge.shortcuts import make_visualizer -import grudge.op as op +from logpyle import IntervalTimer, set_dt +from pytools.obj_array import flat_obj_array from mirgecom.discretization import create_discretization_collection -from mirgecom.wave import wave_operator from mirgecom.integrators import rk4_step -from mirgecom.utils import force_evaluation - -from mirgecom.profiling import PyOpenCLProfilingArrayContext - -from logpyle import IntervalTimer, set_dt - from mirgecom.logging_quantities import (initialize_logmgr, logmgr_add_cl_device_info, logmgr_add_device_memory_usage, logmgr_add_mempool_usage) +from mirgecom.utils import force_evaluation +from mirgecom.wave import wave_operator def bump(actx, nodes, t=0): @@ -66,32 +57,16 @@ def bump(actx, nodes, t=0): / source_width**2)) -def main(actx_class, use_profiling=False, use_logmgr=False, lazy: bool = False): +def main(actx_class, use_logmgr: bool = False) -> None: """Drive the example.""" - cl_ctx = cl.create_some_context() - logmgr = initialize_logmgr(use_logmgr, filename="wave.sqlite", mode="wu") - from mirgecom.simutil import get_reasonable_memory_pool - - if use_profiling: - if lazy: - raise RuntimeError("Cannot run lazy with profiling.") - queue = cl.CommandQueue(cl_ctx, - properties=cl.command_queue_properties.PROFILING_ENABLE) - - alloc = get_reasonable_memory_pool(cl_ctx, queue) - actx = PyOpenCLProfilingArrayContext(queue, allocator=alloc) - else: - queue = cl.CommandQueue(cl_ctx) - alloc = get_reasonable_memory_pool(cl_ctx, queue) - - if lazy: - actx = actx_class(queue, allocator=alloc) - else: - actx = actx_class(queue, allocator=alloc, - force_device_scalars=True) + from mirgecom.array_context import initialize_actx, actx_class_is_profiling + actx = initialize_actx(actx_class, None) + queue = getattr(actx, "queue", None) + alloc = getattr(actx, "allocator", None) + use_profiling = actx_class_is_profiling(actx_class) dim = 2 nel_1d = 16 @@ -111,8 +86,9 @@ def main(actx_class, use_profiling=False, use_logmgr=False, lazy: bool = False): wave_speed = 1.0 from grudge.dt_utils import characteristic_lengthscales nodal_dt = characteristic_lengthscales(actx, dcoll) / wave_speed - dt = actx.to_numpy(current_cfl * op.nodal_min(dcoll, "vol", - nodal_dt))[()] + dt = actx.to_numpy(current_cfl + * op.nodal_min(dcoll, "vol", + nodal_dt))[()] # type: ignore[index] print("%d elements" % mesh.nelements) @@ -157,6 +133,8 @@ def rhs(t, w): if istep % 10 == 0: if use_profiling: + from mirgecom.profiling import PyOpenCLProfilingArrayContext + assert isinstance(actx, PyOpenCLProfilingArrayContext) print(actx.tabulate_profiling_data()) print(istep, t, actx.to_numpy(op.norm(dcoll, fields[0], 2))) vis.write_vtk_file("fld-wave-%04d.vtu" % istep, @@ -187,11 +165,11 @@ def rhs(t, w): help="enable lazy evaluation") args = parser.parse_args() - from grudge.array_context import get_reasonable_array_context_class + from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class(lazy=args.lazy, - distributed=False) + distributed=False, + profiling=args.profiling) - main(actx_class, use_profiling=args.profiling, - use_logmgr=args.log, lazy=args.lazy) + main(actx_class, use_logmgr=args.log) # vim: foldmethod=marker diff --git a/mirgecom/array_context.py b/mirgecom/array_context.py new file mode 100644 index 000000000..5ab71a186 --- /dev/null +++ b/mirgecom/array_context.py @@ -0,0 +1,116 @@ +"""Provide some utilities for handling ArrayContexts. + +.. autofunction:: get_reasonable_array_context_class +.. autofunction:: actx_class_is_lazy +.. autofunction:: actx_class_is_eager +.. autofunction:: actx_class_is_profiling +.. autofunction:: initialize_actx +""" + +__copyright__ = """ +Copyright (C) 2023 University of Illinois Board of Trustees +""" + +__license__ = """ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +""" + +from typing import Type, Optional, TYPE_CHECKING + +import pyopencl as cl +from arraycontext import ArrayContext +import sys + +if TYPE_CHECKING or getattr(sys, "_BUILDING_SPHINX_DOCS", False): + # pylint: disable=no-name-in-module + from mpi4py.MPI import Comm + + +def get_reasonable_array_context_class(*, lazy: bool, distributed: bool, + profiling: bool) -> Type[ArrayContext]: + """Return a :class:`~arraycontext.ArrayContext` with the given constraints.""" + if lazy and profiling: + raise ValueError("Can't specify both lazy and profiling") + + if profiling: + from mirgecom.profiling import PyOpenCLProfilingArrayContext + return PyOpenCLProfilingArrayContext + + from grudge.array_context import \ + get_reasonable_array_context_class as grudge_get_reasonable_actx_class + + return grudge_get_reasonable_actx_class(lazy=lazy, distributed=distributed) + + +def actx_class_is_lazy(actx_class: Type[ArrayContext]) -> bool: + """Return True if *actx_class* is lazy.""" + from arraycontext import PytatoPyOpenCLArrayContext + return issubclass(actx_class, PytatoPyOpenCLArrayContext) + + +def actx_class_is_eager(actx_class: Type[ArrayContext]) -> bool: + """Return True if *actx_class* is eager.""" + from arraycontext import PyOpenCLArrayContext + return issubclass(actx_class, PyOpenCLArrayContext) + + +def actx_class_is_profiling(actx_class: Type[ArrayContext]) -> bool: + """Return True if *actx_class* has profiling enabled.""" + from mirgecom.profiling import PyOpenCLProfilingArrayContext + return issubclass(actx_class, PyOpenCLProfilingArrayContext) + + +def initialize_actx(actx_class: Type[ArrayContext], comm: Optional["Comm"]) \ + -> ArrayContext: + """Initialize a new :class:`~arraycontext.ArrayContext` based on *actx_class*.""" + from arraycontext import PyOpenCLArrayContext, PytatoPyOpenCLArrayContext + from grudge.array_context import (MPIPyOpenCLArrayContext, + MPIPytatoArrayContext) + + cl_ctx = cl.create_some_context() + if actx_class_is_profiling(actx_class): + queue = cl.CommandQueue(cl_ctx, + properties=cl.command_queue_properties.PROFILING_ENABLE) + else: + queue = cl.CommandQueue(cl_ctx) + + from mirgecom.simutil import get_reasonable_memory_pool + alloc = get_reasonable_memory_pool(cl_ctx, queue) + + if actx_class_is_lazy(actx_class): + assert issubclass(actx_class, PytatoPyOpenCLArrayContext) + if comm: + assert issubclass(actx_class, MPIPytatoArrayContext) + actx: ArrayContext = actx_class(mpi_communicator=comm, queue=queue, + mpi_base_tag=12000, + allocator=alloc) # type: ignore[call-arg] + else: + assert not issubclass(actx_class, MPIPytatoArrayContext) + actx = actx_class(queue, allocator=alloc) + else: + assert issubclass(actx_class, PyOpenCLArrayContext) + if comm: + assert issubclass(actx_class, MPIPyOpenCLArrayContext) + actx = actx_class(mpi_communicator=comm, queue=queue, allocator=alloc, + force_device_scalars=True) # type: ignore[call-arg] + else: + assert not issubclass(actx_class, MPIPyOpenCLArrayContext) + actx = actx_class(queue, allocator=alloc, force_device_scalars=True) + + return actx diff --git a/mirgecom/simutil.py b/mirgecom/simutil.py index fe7c9cd74..62c927a46 100644 --- a/mirgecom/simutil.py +++ b/mirgecom/simutil.py @@ -63,23 +63,27 @@ THE SOFTWARE. """ import logging -import numpy as np +import sys from functools import partial +from typing import TYPE_CHECKING, Dict, List, Optional import grudge.op as op -# from grudge.op import nodal_min, elementwise_min -from arraycontext import map_array_container, flatten -from meshmode.dof_array import DOFArray -from mirgecom.viscous import get_viscous_timestep - -from typing import List, Dict, Optional +import numpy as np +import pyopencl as cl +from arraycontext import flatten, map_array_container from grudge.discretization import DiscretizationCollection, PartID from grudge.dof_desc import DD_VOLUME_ALL +from meshmode.dof_array import DOFArray + from mirgecom.utils import normalize_boundaries -import pyopencl as cl +from mirgecom.viscous import get_viscous_timestep logger = logging.getLogger(__name__) +if TYPE_CHECKING or getattr(sys, "_BUILDING_SPHINX_DOCS", False): + # pylint: disable=no-name-in-module + from mpi4py.MPI import Comm + def get_number_of_tetrahedron_nodes(dim, order, include_faces=False): """Get number of nodes (modes) in *dim* Tetrahedron of *order*.""" @@ -103,7 +107,7 @@ def check_step(step, interval): - Zero means 'always visualize'. Useful for checking whether the current step is an output step, - or anyting else that occurs on fixed intervals. + or anything else that occurs on fixed intervals. """ if interval == 0: return True @@ -206,7 +210,7 @@ def get_sim_timestep( def write_visfile(dcoll, io_fields, visualizer, vizname, step=0, t=0, overwrite=False, vis_timer=None, - comm=None): + comm: Optional["Comm"] = None): """Write parallel VTK output for the fields specified in *io_fields*. This routine writes a parallel-compatible unstructured VTK visualization @@ -242,7 +246,8 @@ def write_visfile(dcoll, io_fields, visualizer, vizname, collection. This will stop working in Fall 2022.) """ from contextlib import nullcontext - from mirgecom.io import make_rank_fname, make_par_fname + + from mirgecom.io import make_par_fname, make_rank_fname if comm is None: # None is OK for serial writes! comm = dcoll.mpi_communicator @@ -900,7 +905,8 @@ def partition_generator_func(mesh, tag_to_elements, num_ranks): part_id_to_part_index = { part_id: part_index for part_index, part_id in enumerate(part_id_to_elements.keys())} - from meshmode.mesh.processing import _compute_global_elem_to_part_elem + from meshmode.mesh.processing import \ + _compute_global_elem_to_part_elem global_elem_to_part_elem = _compute_global_elem_to_part_elem( mesh.nelements, part_id_to_elements, part_id_to_part_index, mesh.element_id_dtype) @@ -979,7 +985,7 @@ def extract_volumes(mesh, tag_to_elements, selected_tags, boundary_tag): # partition_mesh creates a partition boundary for "_out"; replace with a # normal boundary new_facial_adjacency_groups = [] - from meshmode.mesh import InterPartAdjacencyGroup, BoundaryAdjacencyGroup + from meshmode.mesh import BoundaryAdjacencyGroup, InterPartAdjacencyGroup for grp_list in in_mesh.facial_adjacency_groups: new_grp_list = [] for fagrp in grp_list: @@ -1038,8 +1044,8 @@ def boundary_report(dcoll, boundaries, outfile_name, *, dd=DD_VOLUME_ALL, nnodes = sum([grp.ndofs for grp in boundary_discr.groups]) local_report.write(f"{bdtag}: {nnodes}\n") - from meshmode.mesh import BTAG_PARTITION from meshmode.distributed import get_connected_parts + from meshmode.mesh import BTAG_PARTITION connected_part_ids = get_connected_parts(dcoll.discr_from_dd(dd).mesh) local_report.write(f"num_nbr_parts: {len(connected_part_ids)}\n") local_report.write(f"connected_part_ids: {connected_part_ids}\n") @@ -1083,8 +1089,8 @@ def get_reasonable_memory_pool(ctx: cl.Context, queue: cl.CommandQueue, By default, it prefers SVM allocations over CL buffers, and memory pools over direct allocations. """ - from pyopencl.characterize import has_coarse_grain_buffer_svm import pyopencl.tools as cl_tools + from pyopencl.characterize import has_coarse_grain_buffer_svm if force_buffer and force_non_pool: logger.info(f"Using non-pooled CL buffer allocations on {queue.device}.") @@ -1158,9 +1164,10 @@ def compare_files_vtu( False: If it fails the files contain data outside the given tolerance. """ - import vtk import xml.etree.ElementTree as Et + import vtk + # read files: if file_type == "vtu": reader1 = vtk.vtkXMLUnstructuredGridReader() # pylint: disable=no-member