From f602d083f1cfcfdfd912c1ac8eaef14ac944d423 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Wed, 9 Aug 2023 16:11:14 -0500 Subject: [PATCH] add NumpyArrayContext support (#947) Co-authored-by: Mike Campbell --- .github/workflows/ci.yaml | 4 +-- examples/ablation-workshop-mpi.py | 8 ++---- examples/autoignition-mpi.py | 8 ++---- examples/combozzle-mpi.py | 8 ++---- examples/compare_lazy_solution.sh | 7 ++++- examples/doublemach-mpi.py | 11 ++++---- examples/doublemach_physical_av-mpi.py | 11 ++++---- examples/heat-source-mpi.py | 8 ++---- examples/hotplate-mpi.py | 8 ++---- examples/lump-mpi.py | 8 ++---- examples/mixture-mpi.py | 8 ++---- examples/multiple-volumes-mpi.py | 8 ++---- examples/nsmix-mpi.py | 10 ++----- examples/poiseuille-local_dt-mpi.py | 9 ++---- examples/poiseuille-mpi.py | 9 ++---- examples/pulse-mpi.py | 8 ++---- examples/scalar-advdiff-mpi.py | 11 ++++---- examples/scalar-lump-mpi.py | 8 ++---- examples/sod-mpi.py | 8 ++---- examples/thermally-coupled-mpi.py | 8 ++---- examples/vortex-mpi.py | 8 ++---- examples/wave-mpi.py | 8 ++++-- examples/wave.py | 5 +++- mirgecom/array_context.py | 38 +++++++++++++++++++++++++- mirgecom/logging_quantities.py | 11 ++++---- 25 files changed, 123 insertions(+), 115 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a7993ccb4..28b316b0f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,7 +6,7 @@ on: branches: main schedule: - cron: '5 0 * * *' - + # Cancel in progress CI runs when a new run targeting the same PR or branch/tag is triggered. # https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre concurrency: @@ -117,7 +117,7 @@ jobs: run: | . .ci-support/install.sh - - name: Test lazy accuracy + - name: Test lazy/numpy accuracy to eager run: | MINIFORGE_INSTALL_DIR=.miniforge3 . "$MINIFORGE_INSTALL_DIR/bin/activate" testing diff --git a/examples/ablation-workshop-mpi.py b/examples/ablation-workshop-mpi.py index 0b758b0bd..7d259d55b 100644 --- a/examples/ablation-workshop-mpi.py +++ b/examples/ablation-workshop-mpi.py @@ -745,6 +745,8 @@ def my_post_step(step, t, dt, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("-r", "--restart_file", type=ascii, dest="restart_file", nargs="?", action="store", help="simulation restart file") @@ -752,14 +754,10 @@ def my_post_step(step, t, dt, state): args = parser.parse_args() from warnings import warn warn("Automatically turning off DV logging. MIRGE-Com Issue(578)") - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/autoignition-mpi.py b/examples/autoignition-mpi.py index 79516c32a..2de268441 100644 --- a/examples/autoignition-mpi.py +++ b/examples/autoignition-mpi.py @@ -666,21 +666,19 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() from warnings import warn warn("Automatically turning off DV logging. MIRGE-Com Issue(578)") log_dependent = False - lazy = args.lazy viscous_terms_on = args.navierstokes - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/combozzle-mpi.py b/examples/combozzle-mpi.py index 5d9df97bb..604047045 100644 --- a/examples/combozzle-mpi.py +++ b/examples/combozzle-mpi.py @@ -1249,21 +1249,19 @@ def dummy_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() from warnings import warn warn("Automatically turning off DV logging. MIRGE-Com Issue(578)") - lazy = args.lazy log_dependent = False force_eval = not args.no_force - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/compare_lazy_solution.sh b/examples/compare_lazy_solution.sh index c1b522535..c3de9395f 100755 --- a/examples/compare_lazy_solution.sh +++ b/examples/compare_lazy_solution.sh @@ -24,10 +24,15 @@ if [[ "$SIM" == *"-mpi.py" ]]; then MPIARGS=" -m mpi4py " fi casename_base=$(echo ${SIM/%.py}) + python ${MPIARGS} ${SIM} --casename ${casename_base}-eager python ${MPIARGS} ${SIM} --casename ${casename_base}-lazy --lazy +python ${MPIARGS} ${SIM} --casename ${casename_base}-numpy --numpy + for vizfile in $(ls ${casename_base}-eager-*.vtu) do - lazy_vizfile=$(echo ${vizfile/eager/lazy}) + lazy_vizfile=$(echo ${vizfile/eager/lazy}) python ${BINDIR}/mirgecompare.py ${TOL} ${vizfile} ${lazy_vizfile} + numpy_vizfile=$(echo ${vizfile/eager/numpy}) + python ${BINDIR}/mirgecompare.py ${TOL} ${vizfile} ${numpy_vizfile} done diff --git a/examples/doublemach-mpi.py b/examples/doublemach-mpi.py index e7454a167..0cdafdf81 100644 --- a/examples/doublemach-mpi.py +++ b/examples/doublemach-mpi.py @@ -441,17 +441,16 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True, - profiling=args.profiling) + actx_class = get_reasonable_array_context_class(lazy=args.lazy, distributed=True, + profiling=args.profiling, + numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/doublemach_physical_av-mpi.py b/examples/doublemach_physical_av-mpi.py index 8c462ed23..f82299471 100644 --- a/examples/doublemach_physical_av-mpi.py +++ b/examples/doublemach_physical_av-mpi.py @@ -712,18 +712,17 @@ def _my_rhs_phys_visc_div_av(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, + actx_class = get_reasonable_array_context_class(lazy=args.lazy, distributed=True, - profiling=args.profiling) + profiling=args.profiling, + numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/heat-source-mpi.py b/examples/heat-source-mpi.py index 18ecf36c6..53beb954e 100644 --- a/examples/heat-source-mpi.py +++ b/examples/heat-source-mpi.py @@ -186,17 +186,15 @@ def rhs(t, u): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/hotplate-mpi.py b/examples/hotplate-mpi.py index fc3e86c8c..a11adb9ed 100644 --- a/examples/hotplate-mpi.py +++ b/examples/hotplate-mpi.py @@ -437,17 +437,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/lump-mpi.py b/examples/lump-mpi.py index 6129a6e32..63c7ee68c 100644 --- a/examples/lump-mpi.py +++ b/examples/lump-mpi.py @@ -364,17 +364,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/mixture-mpi.py b/examples/mixture-mpi.py index 61e2abc84..65b415a5c 100644 --- a/examples/mixture-mpi.py +++ b/examples/mixture-mpi.py @@ -441,20 +441,18 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() from warnings import warn warn("Automatically turning off DV logging. MIRGE-Com Issue(578)") log_dependent = False - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/multiple-volumes-mpi.py b/examples/multiple-volumes-mpi.py index 55648ba3c..db5bdd2b9 100644 --- a/examples/multiple-volumes-mpi.py +++ b/examples/multiple-volumes-mpi.py @@ -388,17 +388,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/nsmix-mpi.py b/examples/nsmix-mpi.py index 971661b66..fa79a9973 100644 --- a/examples/nsmix-mpi.py +++ b/examples/nsmix-mpi.py @@ -617,23 +617,19 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy from warnings import warn warn("Automatically turning off DV logging. MIRGE-Com Issue(578)") log_dependent = False - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") - from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/poiseuille-local_dt-mpi.py b/examples/poiseuille-local_dt-mpi.py index 2159093a4..3499f7f0e 100644 --- a/examples/poiseuille-local_dt-mpi.py +++ b/examples/poiseuille-local_dt-mpi.py @@ -478,18 +478,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/poiseuille-mpi.py b/examples/poiseuille-mpi.py index a400eb3e7..7d850b963 100644 --- a/examples/poiseuille-mpi.py +++ b/examples/poiseuille-mpi.py @@ -451,18 +451,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") - from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/pulse-mpi.py b/examples/pulse-mpi.py index 15b77ad1d..7953e005a 100644 --- a/examples/pulse-mpi.py +++ b/examples/pulse-mpi.py @@ -373,17 +373,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/scalar-advdiff-mpi.py b/examples/scalar-advdiff-mpi.py index abf3db45f..b18c260d8 100644 --- a/examples/scalar-advdiff-mpi.py +++ b/examples/scalar-advdiff-mpi.py @@ -403,17 +403,16 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, distributed=True, - profiling=args.profiling) + actx_class = get_reasonable_array_context_class(lazy=args.lazy, distributed=True, + profiling=args.profiling, + numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/scalar-lump-mpi.py b/examples/scalar-lump-mpi.py index 8c14feb9c..912c0cf3a 100644 --- a/examples/scalar-lump-mpi.py +++ b/examples/scalar-lump-mpi.py @@ -376,17 +376,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/sod-mpi.py b/examples/sod-mpi.py index acebeaea8..34902eb9e 100644 --- a/examples/sod-mpi.py +++ b/examples/sod-mpi.py @@ -364,17 +364,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/thermally-coupled-mpi.py b/examples/thermally-coupled-mpi.py index a51eab839..024fae806 100644 --- a/examples/thermally-coupled-mpi.py +++ b/examples/thermally-coupled-mpi.py @@ -576,17 +576,15 @@ def my_rhs_and_gradients(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - if args.profiling: - if args.lazy: - raise ValueError("Can't use lazy and profiling together.") - 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) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/vortex-mpi.py b/examples/vortex-mpi.py index 3bbc69a02..c2f86b9e9 100644 --- a/examples/vortex-mpi.py +++ b/examples/vortex-mpi.py @@ -388,17 +388,15 @@ def my_rhs(t, state): help="turn on logging") parser.add_argument("--leap", action="store_true", help="use leap timestepper") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") parser.add_argument("--restart_file", help="root name of restart file") parser.add_argument("--casename", help="casename to use for i/o") args = parser.parse_args() - lazy = args.lazy - if args.profiling: - if lazy: - raise ValueError("Can't use lazy and profiling together.") from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class( - lazy=lazy, distributed=True, profiling=args.profiling) + lazy=args.lazy, distributed=True, profiling=args.profiling, numpy=args.numpy) logging.basicConfig(format="%(message)s", level=logging.INFO) if args.casename: diff --git a/examples/wave-mpi.py b/examples/wave-mpi.py index 5c6aecfae..cdd817232 100644 --- a/examples/wave-mpi.py +++ b/examples/wave-mpi.py @@ -249,13 +249,15 @@ def rhs(t, w): help="enable logging") parser.add_argument("--lazy", action="store_true", help="switch to a lazy computation mode") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") args = parser.parse_args() - lazy = args.lazy from mirgecom.array_context import get_reasonable_array_context_class - actx_class = get_reasonable_array_context_class(lazy=lazy, + actx_class = get_reasonable_array_context_class(lazy=args.lazy, distributed=True, - profiling=args.profiling) + profiling=args.profiling, + numpy=args.numpy) main(actx_class, use_logmgr=args.log) diff --git a/examples/wave.py b/examples/wave.py index 8631b71af..9f765ecd1 100644 --- a/examples/wave.py +++ b/examples/wave.py @@ -163,12 +163,15 @@ def rhs(t, w): help="enable logging") parser.add_argument("--lazy", action="store_true", help="enable lazy evaluation") + parser.add_argument("--numpy", action="store_true", + help="use numpy-based eager actx.") args = parser.parse_args() from mirgecom.array_context import get_reasonable_array_context_class actx_class = get_reasonable_array_context_class(lazy=args.lazy, distributed=False, - profiling=args.profiling) + profiling=args.profiling, + numpy=args.numpy) main(actx_class, use_logmgr=args.log) diff --git a/mirgecom/array_context.py b/mirgecom/array_context.py index 5ab71a186..84cdcf4b9 100644 --- a/mirgecom/array_context.py +++ b/mirgecom/array_context.py @@ -4,6 +4,7 @@ .. autofunction:: actx_class_is_lazy .. autofunction:: actx_class_is_eager .. autofunction:: actx_class_is_profiling +.. autofunction:: actx_class_is_numpy .. autofunction:: initialize_actx """ @@ -43,11 +44,27 @@ def get_reasonable_array_context_class(*, lazy: bool, distributed: bool, - profiling: bool) -> Type[ArrayContext]: + profiling: bool, numpy: bool = False) -> 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 numpy: + if profiling: + raise ValueError("Can't specify both numpy and profiling") + if lazy: + raise ValueError("Can't specify both numpy and lazy") + + from warnings import warn + warn("The NumpyArrayContext is still under development") + + if distributed: + from grudge.array_context import MPINumpyArrayContext + return MPINumpyArrayContext + else: + from grudge.array_context import NumpyArrayContext + return NumpyArrayContext + if profiling: from mirgecom.profiling import PyOpenCLProfilingArrayContext return PyOpenCLProfilingArrayContext @@ -76,6 +93,18 @@ def actx_class_is_profiling(actx_class: Type[ArrayContext]) -> bool: return issubclass(actx_class, PyOpenCLProfilingArrayContext) +def actx_class_is_numpy(actx_class: Type[ArrayContext]) -> bool: + """Return True if *actx_class* is numpy-based.""" + try: + from grudge.array_context import NumpyArrayContext + if issubclass(actx_class, NumpyArrayContext): + return True + else: + return False + except ImportError: + return False + + def initialize_actx(actx_class: Type[ArrayContext], comm: Optional["Comm"]) \ -> ArrayContext: """Initialize a new :class:`~arraycontext.ArrayContext` based on *actx_class*.""" @@ -83,6 +112,13 @@ def initialize_actx(actx_class: Type[ArrayContext], comm: Optional["Comm"]) \ from grudge.array_context import (MPIPyOpenCLArrayContext, MPIPytatoArrayContext) + # Special handling for NumpyArrayContext since it needs no CL context + if actx_class_is_numpy(actx_class): + if comm: + return actx_class(mpi_communicator=comm) # type: ignore[call-arg] + else: + return actx_class() + cl_ctx = cl.create_some_context() if actx_class_is_profiling(actx_class): queue = cl.CommandQueue(cl_ctx, diff --git a/mirgecom/logging_quantities.py b/mirgecom/logging_quantities.py index 3e6c5346e..0f26c6542 100644 --- a/mirgecom/logging_quantities.py +++ b/mirgecom/logging_quantities.py @@ -92,10 +92,11 @@ def initialize_logmgr(enable_logmgr: bool, def logmgr_add_cl_device_info(logmgr: LogManager, queue: cl.CommandQueue) -> None: """Add information about the OpenCL device to the log.""" - dev = queue.device - logmgr.set_constant("cl_device_name", str(dev)) - logmgr.set_constant("cl_device_version", dev.version) - logmgr.set_constant("cl_platform_version", dev.platform.version) + if queue: + dev = queue.device + logmgr.set_constant("cl_device_name", str(dev)) + logmgr.set_constant("cl_device_version", dev.version) + logmgr.set_constant("cl_platform_version", dev.platform.version) def logmgr_add_device_name(logmgr: LogManager, queue: cl.CommandQueue): # noqa: D401 @@ -110,7 +111,7 @@ def logmgr_add_device_name(logmgr: LogManager, queue: cl.CommandQueue): # noqa: def logmgr_add_device_memory_usage(logmgr: LogManager, queue: cl.CommandQueue) \ -> None: """Add the OpenCL device memory usage to the log.""" - if not (queue.device.type & cl.device_type.GPU): + if not queue or not (queue.device.type & cl.device_type.GPU): return logmgr.add_quantity(DeviceMemoryUsage())