Skip to content

Commit cbe1e2f

Browse files
committed
compiler: load so directly when source is missing (e.g deleted c file)
1 parent cc4fe0d commit cbe1e2f

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

devito/arch/compiler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ def jit_compile(self, soname, code):
386386
# Typically we end up here
387387
# Make a suite of cache directories based on the soname
388388
cache_dir.mkdir(parents=True, exist_ok=True)
389+
# Has the library already been compiled?
390+
try:
391+
self.load(target)
392+
return False, src_file
393+
except OSError:
394+
# The .so file isn't present, we need to compile it
395+
pass
389396
else:
390397
# Warning: dropping `code` on the floor in favor to whatever is written
391398
# within `src_file`

devito/types/dimension.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ def _arg_defaults(self, _min=None, size=None, alias=None):
10431043
else:
10441044
# Given a factor the last time index is factor*(size - 1)
10451045
# The maximum allowed value is then factor*size - 1
1046+
print(d0, factor, size)
10461047
defaults[dim.parent.max_name] = range(d0, d0 + factor*size)
10471048

10481049
return defaults

tests/test_cinterface.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import os
2+
import sys
3+
from contextlib import suppress
24

35
from devito import Eq, Grid, Operator, TimeFunction, configuration
46
from devito.types import Timer
@@ -37,3 +39,31 @@ def test_basic():
3739
assert isinstance(timers, Timer)
3840
assert 'struct profiler\n{' not in ccode
3941
assert 'struct profiler\n{' in hcode
42+
43+
44+
def test_load_without_source():
45+
grid = Grid(shape=(4, 4))
46+
47+
f = TimeFunction(name='f', grid=grid)
48+
49+
eq = Eq(f.forward, f + 1.)
50+
51+
name = "foo"
52+
op = Operator(eq, name=name)
53+
54+
# Make sure the so file is not present
55+
dirname = op._compiler.get_jit_dir()
56+
soname = op._soname
57+
ext = '.dylib' if sys.platform == "darwin" else '.so'
58+
with suppress(FileNotFoundError):
59+
os.remove(f"{os.path.join(dirname, soname)}{ext}")
60+
61+
# Trigger compilation
62+
recompiled, src_file = op._compiler.jit_compile(op._soname, str(op))
63+
assert recompiled
64+
65+
os.remove(src_file)
66+
# Trigger compilation again. It should skip the C part and directly load the .so file
67+
recompiled, src_file = op._compiler.jit_compile(op._soname, str(op))
68+
assert not recompiled
69+
assert not os.path.isfile(src_file)

0 commit comments

Comments
 (0)