Skip to content

Commit

Permalink
Merge pull request #2280 from devitocodes/develop-mode-off
Browse files Browse the repository at this point in the history
misc: Switch off develop-mode
  • Loading branch information
mloubout authored Dec 13, 2023
2 parents 7d73a60 + afc0612 commit ceb6d8c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
7 changes: 4 additions & 3 deletions devito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
19 changes: 9 additions & 10 deletions devito/data/allocators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions devito/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/compiler/01_data_regions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 8 additions & 3 deletions tests/test_autotuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
])
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)
Expand All @@ -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))

Expand Down
5 changes: 3 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand Down

0 comments on commit ceb6d8c

Please sign in to comment.