Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from devito.logger import debug, warning
from devito.parameters import configuration
from devito.tools import (
as_list, change_directory, filter_ordered, make_tempdir, memoized_func
Signer, as_list, change_directory, filter_ordered, make_tempdir, memoized_func
)

__all__ = ['compiler_registry', 'sniff_mpi_distro']
Expand Down Expand Up @@ -148,7 +148,7 @@ def call_capture_output(cmd):
return _call_capture_output(cmd)


class Compiler(GCCToolchain):
class Compiler(GCCToolchain, Signer):
"""
Base class for all compiler classes.

Expand Down Expand Up @@ -457,6 +457,9 @@ def __getstate__(self):
# The superclass would otherwise only return a subset of attributes
return self.__dict__

def _signature_items(self):
return (str(self._cmdline([])), self.src_ext, self.so_ext)

def add_include_dirs(self, dirs):
self.include_dirs = filter_ordered(self.include_dirs + as_list(dirs))

Expand Down
2 changes: 1 addition & 1 deletion devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ def arguments(self, **kwargs):
@cached_property
def _soname(self):
"""A unique name for the shared object resulting from JIT compilation."""
return Signer._digest(self, configuration)
return Signer._digest(self, configuration, self._compiler)

@cached_property
def _printer(self):
Expand Down
37 changes: 37 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,43 @@ def test_compiler_uniqueness(self):
assert op0._compiler is not op2._compiler
assert op1._compiler is not op2._compiler

@pytest.mark.parametrize('rpath', [False, True])
def test_jit_library_dirs(self, rpath, tmp_path):
grid = Grid(shape=(3, 3, 3))
u = TimeFunction(name='u', grid=grid)
eq = Eq(u.forward, u + 1)

operators = []
for name in ('lib0', 'lib1', 'lib1'):
op = Operator(eq, name='library_paths')
op._compiler.add_library_dirs([str(tmp_path/name)], rpath=rpath)
operators.append(op)

op0, op1, op2 = operators
assert str(op0) == str(op1) == str(op2)
assert op0._soname != op1._soname
assert op1._soname == op2._soname

@pytest.mark.parametrize('envvar, flags', [
('CFLAGS', ('-O1 -O2', '-O2 -O1')),
('LDFLAGS', ('-Wl,-rpath,/lib0 -Wl,-rpath,/lib1',
'-Wl,-rpath,/lib1 -Wl,-rpath,/lib0'))
])
def test_jit_compiler_flags(self, envvar, flags, monkeypatch):
grid = Grid(shape=(3, 3, 3))
u = TimeFunction(name='u', grid=grid)
eq = Eq(u.forward, u + 1)

operators = []
for value in (*flags, flags[-1]):
monkeypatch.setenv(envvar, value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done without use of monkeypatch? We have switchenv for this right?

operators.append(Operator(eq, name='compiler_flags', compiler='custom'))

op0, op1, op2 = operators
assert str(op0) == str(op1) == str(op2)
assert op0._soname != op1._soname
assert op1._soname == op2._soname


class TestCodeGen:

Expand Down
Loading