From d6f565f166d4ba2ee45d9526931459113f497e85 Mon Sep 17 00:00:00 2001 From: Fabio Luporini Date: Mon, 11 Dec 2023 08:51:54 +0000 Subject: [PATCH 1/3] api: Default to develop-mode=off --- devito/__init__.py | 7 ++++--- tests/test_autotuner.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/devito/__init__.py b/devito/__init__.py index 8f2f843ab1..f75e94ce79 100644 --- a/devito/__init__.py +++ b/devito/__init__.py @@ -122,9 +122,10 @@ def autotune_callback(val): # noqa impacts_jit=False) # In develop-mode: -# - Some optimizations may not be applied to the generated code. -# - The compiler performs more type and value checking -configuration.add('develop-mode', True, [False, True]) +# - The ALLOC_GUARD data allocator is used. This will trigger segfaults as soon +# as an out-of-bounds memory access is performed +# - Some autoi-tuning optimizations are disabled +configuration.add('develop-mode', False, [False, True]) # Setup optimization level configuration.add('opt', 'advanced', list(operator_registry._accepted), deprecate='dle') diff --git a/tests/test_autotuner.py b/tests/test_autotuner.py index 90f5837e9f..496afa3666 100644 --- a/tests/test_autotuner.py +++ b/tests/test_autotuner.py @@ -7,7 +7,7 @@ from devito.core.autotuning import options # noqa -@switchconfig(log_level='DEBUG') +@switchconfig(log_level='DEBUG', develop_mode=True) @pytest.mark.parametrize("shape,expected", [ ((30, 30), 13), ((30, 30, 30), 17) @@ -113,6 +113,7 @@ def test_blocking_only(): assert 'nthreads' not in op._state['autotuning'][0]['tuned'] +@switchconfig(develop_mode=True) def test_mixed_blocking_nthreads(): grid = Grid(shape=(96, 96, 96)) f = TimeFunction(name='f', grid=grid) @@ -126,6 +127,7 @@ def test_mixed_blocking_nthreads(): assert 'nthreads' in op._state['autotuning'][0]['tuned'] +@switchconfig(develop_mode=True) @pytest.mark.parametrize('openmp, expected', [ (False, 2), (True, 3) ]) @@ -145,6 +147,7 @@ def test_mixed_blocking_w_skewing(openmp, expected): assert 'nthreads' not in op._state['autotuning'][0]['tuned'] +@switchconfig(develop_mode=True) @pytest.mark.parametrize('opt', ['advanced', ('blocking', {'skewing': True})]) def test_tti_aggressive(opt): from test_dse import TestTTI @@ -223,6 +226,7 @@ def test_at_w_mpi(): assert np.all(f.data_ro_domain[1, 7] == 5) +@switchconfig(develop_mode=True) def test_multiple_blocking(): """ Test that if there are more than one blocked Iteration nests, then @@ -287,7 +291,7 @@ def test_hierarchical_blocking(opt_options): assert len(op._state['autotuning'][1]['tuned']) == 4 -@switchconfig(platform='cpu64-dummy') # To fix the core count +@switchconfig(platform='cpu64-dummy', develop_mode=True) # `cpu64-dummy `to fix ncores @pytest.mark.parametrize('opt_options', [{'skewing': False}, {'skewing': True}]) def test_multiple_threads(opt_options): """ @@ -307,7 +311,7 @@ def test_multiple_threads(opt_options): @skipif('cpu64-arm') -@switchconfig(platform='knl7210') # To trigger nested parallelism +@switchconfig(platform='knl7210', develop_mode=True) # `knl7210` for nested parallelsim def test_nested_nthreads(): grid = Grid(shape=(96, 96, 96)) f = TimeFunction(name='f', grid=grid) @@ -323,6 +327,7 @@ def test_nested_nthreads(): assert 'nthreads_nested' not in op._state['autotuning'][0]['tuned'] +@switchconfig(develop_mode=True) def test_few_timesteps(): grid = Grid(shape=(16, 16, 16)) From f9759ae3c8f4412ce346e04b73ed6cebf58ff994 Mon Sep 17 00:00:00 2001 From: Fabio Luporini Date: Mon, 11 Dec 2023 09:16:38 +0000 Subject: [PATCH 2/3] api: Use ALLOC_ALIGNED unless in develop-mode --- devito/data/allocators.py | 19 +++++++++---------- devito/data/data.py | 8 ++++---- tests/test_data.py | 5 +++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/devito/data/allocators.py b/devito/data/allocators.py index d940a006bf..95fa95a2a9 100644 --- a/devito/data/allocators.py +++ b/devito/data/allocators.py @@ -13,7 +13,7 @@ from devito.parameters import configuration from devito.tools import dtype_to_ctype -__all__ = ['ALLOC_FLAT', 'ALLOC_NUMA_LOCAL', 'ALLOC_NUMA_ANY', +__all__ = ['ALLOC_ALIGNED', 'ALLOC_NUMA_LOCAL', 'ALLOC_NUMA_ANY', 'ALLOC_KNL_MCDRAM', 'ALLOC_KNL_DRAM', 'ALLOC_GUARD', 'default_allocator'] @@ -368,7 +368,7 @@ def alloc(self, shape, dtype): ALLOC_GUARD = GuardAllocator(1048576) -ALLOC_FLAT = PosixAllocator() +ALLOC_ALIGNED = PosixAllocator() ALLOC_KNL_DRAM = NumaAllocator(0) ALLOC_KNL_MCDRAM = NumaAllocator(1) ALLOC_NUMA_ANY = NumaAllocator('any') @@ -403,8 +403,8 @@ def default_allocator(name=None): * ALLOC_GUARD: Only used in so-called "develop mode", to trigger SIGSEGV as soon as OOB accesses are performed. - * ALLOC_FLAT: Align memory to page boundaries using the posix function - `posix_memalign`. + * ALLOC_ALIGNED: Align memory to page boundaries using the function + `posix_memalign`. * ALLOC_NUMA_LOCAL: Allocate memory in the "closest" NUMA node. This only makes sense on a NUMA architecture. Falls back to allocation in an arbitrary NUMA node if there isn't @@ -424,10 +424,9 @@ def default_allocator(name=None): if configuration['develop-mode']: return ALLOC_GUARD - elif NumaAllocator.available(): - if configuration['platform'].name == 'knl' and infer_knl_mode() == 'flat': - return ALLOC_KNL_MCDRAM - else: - return ALLOC_NUMA_LOCAL + elif (NumaAllocator.available() and + configuration['platform'].name == 'knl' and + infer_knl_mode() == 'flat'): + return ALLOC_KNL_MCDRAM else: - return ALLOC_FLAT + return ALLOC_ALIGNED diff --git a/devito/data/data.py b/devito/data/data.py index 78859cdb7e..ef3bad7091 100644 --- a/devito/data/data.py +++ b/devito/data/data.py @@ -3,7 +3,7 @@ import numpy as np -from devito.data.allocators import ALLOC_FLAT +from devito.data.allocators import ALLOC_ALIGNED from devito.data.utils import * from devito.logger import warning from devito.parameters import configuration @@ -28,7 +28,7 @@ class Data(np.ndarray): modulo : tuple of bool, optional If the i-th entry is True, then the i-th array dimension uses modulo indexing. allocator : MemoryAllocator, optional - Used to allocate memory. Defaults to ``ALLOC_FLAT``. + Used to allocate memory. Defaults to `ALLOC_ALIGNED`. distributor : Distributor, optional The distributor from which the original decomposition was produced. Note that the decomposition Parameter above may be different to distributor.decomposition. @@ -44,8 +44,8 @@ class Data(np.ndarray): `Data`. """ - def __new__(cls, shape, dtype, decomposition=None, modulo=None, allocator=ALLOC_FLAT, - distributor=None): + def __new__(cls, shape, dtype, decomposition=None, modulo=None, + allocator=ALLOC_ALIGNED, distributor=None): assert len(shape) == len(modulo) ndarray, memfree_args = allocator.alloc(shape, dtype) obj = ndarray.view(cls) diff --git a/tests/test_data.py b/tests/test_data.py index 0a03e7a4c6..d8988f21a1 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -2,7 +2,8 @@ import numpy as np from devito import (Grid, Function, TimeFunction, SparseTimeFunction, Dimension, # noqa - Eq, Operator, ALLOC_GUARD, ALLOC_FLAT, configuration, switchconfig) + Eq, Operator, ALLOC_GUARD, ALLOC_ALIGNED, configuration, + switchconfig) from devito.data import LEFT, RIGHT, Decomposition, loc_data_idx, convert_index from devito.tools import as_tuple from devito.types import Scalar @@ -1494,7 +1495,7 @@ def test_oob_noguard(): """ # A tiny grid grid = Grid(shape=(4, 4)) - u = Function(name='u', grid=grid, space_order=0, allocator=ALLOC_FLAT) + u = Function(name='u', grid=grid, space_order=0, allocator=ALLOC_ALIGNED) Operator(Eq(u[2000, 0], 1.0)).apply() From afc0612db9b30aeb47ef377e0c118bfd3d4e7d42 Mon Sep 17 00:00:00 2001 From: Fabio Luporini Date: Tue, 12 Dec 2023 09:57:25 +0000 Subject: [PATCH 3/3] examples: Fix for deterministic output --- examples/compiler/01_data_regions.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/compiler/01_data_regions.ipynb b/examples/compiler/01_data_regions.ipynb index a2b9016dbd..c0cf5a5330 100644 --- a/examples/compiler/01_data_regions.ipynb +++ b/examples/compiler/01_data_regions.ipynb @@ -491,6 +491,7 @@ ], "source": [ "u_pad = TimeFunction(name='u_pad', grid=grid, space_order=2, padding=(0,2,2))\n", + "u_pad._data_allocated[:] = 0\n", "u_pad.data_with_halo[:] = 1\n", "u_pad.data[:] = 2\n", "equation = Eq(u_pad.forward, u_pad + 2)\n",