Skip to content

Commit

Permalink
Merge branch 'devitocodes:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoeLeibowitz authored Oct 16, 2024
2 parents 7ad60cc + 7795225 commit 469e464
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/examples-mpi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jobs:
- name: Checkout devito
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Setup MPI
uses: mpi4py/setup-mpi@v1
with:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ jobs:
environment-file: environment-dev.yml
auto-activate-base: false

- name: Install dependencies
run: |
pip install -e .[tests,extras]
- name: Tests in examples
run: |
py.test --cov --cov-config=.coveragerc --cov-report=xml examples/
Expand Down
16 changes: 9 additions & 7 deletions devito/arch/archinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ def numa_domains(self):
def threads_per_core(self):
return self.cores_logical // self.cores_physical

@property
def cores_physical_per_numa_domain(self):
return self.cores_physical // self.numa_domains

@property
def memtotal(self):
"""Physical memory size in bytes, or None if unknown."""
Expand Down Expand Up @@ -734,10 +738,6 @@ def numa_domains(self):
warning("NUMA domain count autodetection failed")
return 1

@property
def cores_physical_per_numa_domain(self):
return self.cores_physical // self.numa_domains

@cached_property
def memtotal(self):
return psutil.virtual_memory().total
Expand Down Expand Up @@ -804,13 +804,15 @@ def _detect_isa(self):

class Device(Platform):

def __init__(self, name, cores_logical=1, cores_physical=1, isa='cpp',
def __init__(self, name, cores_logical=None, cores_physical=None, isa='cpp',
max_threads_per_block=1024, max_threads_dimx=1024,
max_threads_dimy=1024, max_threads_dimz=64):
super().__init__(name)

self.cores_logical = cores_logical
self.cores_physical = cores_physical
cpu_info = get_cpu_info()

self.cores_logical = cores_logical or cpu_info['logical']
self.cores_physical = cores_physical or cpu_info['physical']
self.isa = isa

self.max_threads_per_block = max_threads_per_block
Expand Down
60 changes: 35 additions & 25 deletions devito/finite_differences/derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,35 +219,45 @@ def _process_weights(cls, **kwargs):
return as_tuple(weights)

def __call__(self, x0=None, fd_order=None, side=None, method=None, weights=None):
side = side or self._side
method = method or self._method
weights = weights if weights is not None else self._weights

x0 = self._process_x0(self.dims, x0=x0)
_x0 = frozendict({**self.x0, **x0})

_fd_order = dict(self.fd_order.getters)
try:
_fd_order.update(fd_order or {})
except TypeError:
assert self.ndims == 1
_fd_order.update({self.dims[0]: fd_order or self.fd_order[0]})
except AttributeError:
raise TypeError("fd_order incompatible with dimensions")
rkw = {}
if side is not None:
rkw['side'] = side
if method is not None:
rkw['method'] = method
if weights is not None:
rkw['weights'] = weights

if x0 is not None:
x0 = self._process_x0(self.dims, x0=x0)
rkw['x0'] = frozendict({**self.x0, **x0})

if fd_order is not None:
try:
_fd_order = dict(fd_order)
except TypeError:
assert self.ndims == 1
_fd_order = {self.dims[0]: fd_order}
except AttributeError:
raise TypeError("fd_order incompatible with dimensions")

if isinstance(self.expr, Derivative):
# In case this was called on a perfect cross-derivative `u.dxdy`
# we need to propagate the call to the nested derivative
x0s = self._filter_dims(self.expr._filter_dims(_x0), neg=True)
expr = self.expr(x0=x0s, fd_order=self.expr._filter_dims(_fd_order),
side=side, method=method)
else:
expr = self.expr

_fd_order = self._filter_dims(_fd_order, as_tuple=True)

return self._rebuild(fd_order=_fd_order, x0=_x0, side=side, method=method,
weights=weights, expr=expr)
rkwe = dict(rkw)
rkwe.pop('weights', None)
if 'x0' in rkwe:
rkwe['x0'] = self._filter_dims(self.expr._filter_dims(rkw['x0']),
neg=True)
if fd_order is not None:
fdo = self.expr._filter_dims(_fd_order)
if fdo:
rkwe['fd_order'] = fdo
rkw['expr'] = self.expr(**rkwe)

if fd_order is not None:
rkw['fd_order'] = self._filter_dims(_fd_order, as_tuple=True)

return self._rebuild(**rkw)

def _rebuild(self, *args, **kwargs):
kwargs['preprocessed'] = True
Expand Down
4 changes: 4 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ channels:
- defaults
- conda-forge
dependencies:
- python<3.13
- pip>=21.1.2
- pip:
- -r requirements.txt
- -r requirements-optional.txt
- -r requirements-testing.txt
- -e .
18 changes: 18 additions & 0 deletions tests/test_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,24 @@ def test_cross_newnest(self):

assert f.dxdy == f.dx.dy

def test_nested_call(self):
grid = Grid((11, 11))
x, y = grid.dimensions
f = Function(name="f", grid=grid, space_order=8)

deriv = Derivative(f, x, y, deriv_order=(0, 0), fd_order=(2, 2),
x0={x: x-x.spacing/2, y: y+y.spacing/2}).dy(x0=y-y.spacing/2)

derivc = Derivative(f.dy(x0=y-y.spacing/2), x, y, deriv_order=(0, 0),
fd_order=(2, 2), x0={x: x-x.spacing/2, y: y+y.spacing/2})

assert deriv.expr.fd_order == (2, 2)
assert deriv.expr.deriv_order == (0, 0)
assert deriv.expr.x0 == {x: x-x.spacing/2, y: y+y.spacing/2}

# Should be commutative
assert simplify(deriv.evaluate - derivc.evaluate) == 0


class TestTwoStageEvaluation:

Expand Down
11 changes: 10 additions & 1 deletion tests/test_gpu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SubDimension, SubDomain, SubDomainSet, TimeFunction,
Operator, configuration, switchconfig, TensorTimeFunction,
Buffer)
from devito.arch import get_gpu_info
from devito.arch import get_gpu_info, get_cpu_info, Device, Cpu64
from devito.exceptions import InvalidArgument
from devito.ir import (Conditional, Expression, Section, FindNodes, FindSymbols,
retrieve_iteration_tree)
Expand Down Expand Up @@ -47,6 +47,15 @@ def custom_compiler(self):
op.apply(time_M=10)
assert np.all(u.data[1] == 11)

def test_host_threads(self):
plat = configuration['platform']

assert isinstance(plat, Device)

nth = plat.cores_physical
assert nth == get_cpu_info()['physical']
assert nth == Cpu64("test").cores_physical


class TestCodeGeneration:

Expand Down

0 comments on commit 469e464

Please sign in to comment.