Skip to content

Commit

Permalink
api: Use ALLOC_ALIGNED unless in develop-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Dec 11, 2023
1 parent d6f565f commit f9759ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
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
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 f9759ae

Please sign in to comment.