From 3f9fe0da518c4ce35f14ed2eaea47cc5a6cc442d Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Tue, 4 Mar 2025 10:07:06 +0200 Subject: [PATCH] feat: remove uses of force_device_scalars --- examples/advection/surface.py | 8 +++----- examples/advection/var-velocity.py | 8 +++----- examples/advection/weak.py | 8 +++----- examples/euler/acoustic_pulse.py | 12 +++--------- examples/euler/vortex.py | 12 +++--------- examples/geometry.py | 16 +++++----------- examples/maxwell/cavities.py | 8 +++----- examples/wave/var-propagation-speed.py | 8 +++----- examples/wave/wave-min-mpi.py | 9 +++------ examples/wave/wave-op-mpi.py | 16 +++++++--------- examples/wave/wave-op-var-velocity.py | 8 +++----- test/test_mpi_communication.py | 2 +- 12 files changed, 40 insertions(+), 75 deletions(-) diff --git a/examples/advection/surface.py b/examples/advection/surface.py index 8eca7ab..19d009f 100644 --- a/examples/advection/surface.py +++ b/examples/advection/surface.py @@ -104,11 +104,9 @@ class Plotter: def main(ctx_factory, dim=2, order=4, use_quad=False, visualize=False): cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = PyOpenCLArrayContext(queue, allocator=allocator) # {{{ parameters diff --git a/examples/advection/var-velocity.py b/examples/advection/var-velocity.py index 753bf26..96a1d29 100644 --- a/examples/advection/var-velocity.py +++ b/examples/advection/var-velocity.py @@ -99,11 +99,9 @@ def main(ctx_factory, dim=2, order=4, use_quad=False, visualize=False, flux_type="upwind"): cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = PyOpenCLArrayContext(queue, allocator=allocator) # {{{ parameters diff --git a/examples/advection/weak.py b/examples/advection/weak.py index 72a2932..ef1ef54 100644 --- a/examples/advection/weak.py +++ b/examples/advection/weak.py @@ -99,11 +99,9 @@ class Plotter: def main(ctx_factory, dim=2, order=4, visualize=False): cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = PyOpenCLArrayContext(queue, allocator=allocator) # {{{ parameters diff --git a/examples/euler/acoustic_pulse.py b/examples/euler/acoustic_pulse.py index c44a632..c8fbf93 100644 --- a/examples/euler/acoustic_pulse.py +++ b/examples/euler/acoustic_pulse.py @@ -212,17 +212,11 @@ def main(ctx_factory, order=3, final_time=1, resolution=16, cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) if lazy: - actx = PytatoPyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - ) + actx = PytatoPyOpenCLArrayContext(queue, allocator=allocator) else: - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + actx = PyOpenCLArrayContext(queue, allocator=allocator) run_acoustic_pulse( actx, diff --git a/examples/euler/vortex.py b/examples/euler/vortex.py index 974981e..2c5f40c 100644 --- a/examples/euler/vortex.py +++ b/examples/euler/vortex.py @@ -162,17 +162,11 @@ def main(ctx_factory, order=3, final_time=5, resolution=8, cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) if lazy: - actx = PytatoPyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - ) + actx = PytatoPyOpenCLArrayContext(queue, allocator=allocator) else: - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + actx = PyOpenCLArrayContext(queue, allocator=allocator) if lf_stabilization: flux_type = "lf" diff --git a/examples/geometry.py b/examples/geometry.py index 5d84391..33e463b 100644 --- a/examples/geometry.py +++ b/examples/geometry.py @@ -25,26 +25,20 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ - -import numpy as np # noqa import pyopencl as cl import pyopencl.tools as cl_tools +from grudge import geometry, shortcuts from grudge.array_context import PyOpenCLArrayContext - -from grudge import shortcuts -from grudge import geometry from grudge.discretization import make_discretization_collection -def main(write_output=True): +def main(write_output: bool = True) -> None: cl_ctx = cl.create_some_context() queue = cl.CommandQueue(cl_ctx) - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = PyOpenCLArrayContext(queue, allocator=allocator) from meshmode.mesh import BTAG_ALL from meshmode.mesh.generation import generate_warped_rect_mesh diff --git a/examples/maxwell/cavities.py b/examples/maxwell/cavities.py index c05272b..ced99dd 100644 --- a/examples/maxwell/cavities.py +++ b/examples/maxwell/cavities.py @@ -44,11 +44,9 @@ logger = logging.getLogger(__name__) def main(ctx_factory, dim=3, order=4, visualize=False): cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = PyOpenCLArrayContext(queue, allocator=allocator) from meshmode.mesh.generation import generate_regular_rect_mesh mesh = generate_regular_rect_mesh( diff --git a/examples/wave/var-propagation-speed.py b/examples/wave/var-propagation-speed.py index 572fc65..2a42b02 100644 --- a/examples/wave/var-propagation-speed.py +++ b/examples/wave/var-propagation-speed.py @@ -44,11 +44,9 @@ logger = logging.getLogger(__name__) def main(ctx_factory, dim=2, order=4, visualize=False): cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = PyOpenCLArrayContext(queue, allocator=allocator) from meshmode.mesh.generation import generate_regular_rect_mesh mesh = generate_regular_rect_mesh( diff --git a/examples/wave/wave-min-mpi.py b/examples/wave/wave-min-mpi.py index acdc47e..0b68de6 100644 --- a/examples/wave/wave-min-mpi.py +++ b/examples/wave/wave-min-mpi.py @@ -52,12 +52,9 @@ def main(dim=2, order=4, visualize=True): cl_ctx = cl.create_some_context() queue = cl.CommandQueue(cl_ctx) - actx = MPIPyOpenCLArrayContext( - comm, - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = MPIPyOpenCLArrayContext(comm, queue, allocator=allocator) from meshmode.distributed import get_partition_by_pymetis, membership_list_to_map from meshmode.mesh.processing import partition_mesh diff --git a/examples/wave/wave-op-mpi.py b/examples/wave/wave-op-mpi.py index ea47e20..ffe6233 100644 --- a/examples/wave/wave-op-mpi.py +++ b/examples/wave/wave-op-mpi.py @@ -28,13 +28,12 @@ import logging from dataclasses import dataclass import numpy as np -import numpy.linalg as la # noqa import pyopencl as cl import pyopencl.tools as cl_tools from arraycontext import dataclass_array_container, with_container_arithmetic from meshmode.dof_array import DOFArray -from meshmode.mesh import BTAG_ALL, BTAG_NONE # noqa +from meshmode.mesh import BTAG_ALL from pytools.obj_array import flat_obj_array, make_obj_array import grudge.geometry as geo @@ -186,16 +185,15 @@ def main(ctx_factory, dim=2, order=3, if numpy: actx = actx_class(comm) - elif lazy: - cl_ctx = ctx_factory() - queue = cl.CommandQueue(cl_ctx) - actx = actx_class(comm, queue, mpi_base_tag=15000) else: cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - actx = actx_class(comm, queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + if lazy: + actx = actx_class(comm, queue, allocator=allocator, mpi_base_tag=15000) + else: + actx = actx_class(comm, queue, allocator=allocator) from meshmode.distributed import get_partition_by_pymetis, membership_list_to_map from meshmode.mesh.processing import partition_mesh diff --git a/examples/wave/wave-op-var-velocity.py b/examples/wave/wave-op-var-velocity.py index 0009939..7bbf748 100644 --- a/examples/wave/wave-op-var-velocity.py +++ b/examples/wave/wave-op-var-velocity.py @@ -151,11 +151,9 @@ def bump(actx, dcoll, t=0, width=0.05, center=None): def main(ctx_factory, dim=2, order=3, visualize=False): cl_ctx = ctx_factory() queue = cl.CommandQueue(cl_ctx) - actx = PyOpenCLArrayContext( - queue, - allocator=cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)), - force_device_scalars=True, - ) + + allocator = cl_tools.MemoryPool(cl_tools.ImmediateAllocator(queue)) + actx = PyOpenCLArrayContext(queue, allocator=allocator) nel_1d = 16 from meshmode.mesh.generation import generate_regular_rect_mesh diff --git a/test/test_mpi_communication.py b/test/test_mpi_communication.py index 342c526..69b4d5c 100644 --- a/test/test_mpi_communication.py +++ b/test/test_mpi_communication.py @@ -86,7 +86,7 @@ def run_test_with_mpi_inner(): if actx_class is MPIPytatoArrayContext: actx = actx_class(comm, queue, mpi_base_tag=15000) elif actx_class is MPIPyOpenCLArrayContext: - actx = actx_class(comm, queue, force_device_scalars=True) + actx = actx_class(comm, queue) else: raise ValueError("unknown actx_class") -- GitLab