Skip to content

Commit f45a2da

Browse files
committed
compiler: fix corner case cxx config
1 parent da838a3 commit f45a2da

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

devito/ir/iet/visitors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,10 @@ def visit_PointerCast(self, o):
423423
if o.flat is None:
424424
shape = ''.join(f"[{self.ccode(i)}]" for i in o.castshape)
425425
rshape = f'(*){shape}'
426-
lvalue = c.Value(cstr, f'(*{self._restrict_keyword} {v}){shape}')
426+
if shape:
427+
lvalue = c.Value(cstr, f'(*{self._restrict_keyword} {v}){shape}')
428+
else:
429+
lvalue = c.Value(cstr, f'*{self._restrict_keyword} {v}')
427430
else:
428431
rshape = '*'
429432
lvalue = c.Value(cstr, f'*{v}')

devito/operator/operator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,10 @@ def parse_kwargs(**kwargs):
13371337

13381338
if not opt or isinstance(opt, str):
13391339
mode, options = opt, {}
1340+
# Legacy Operator(..., opt='openmp', ...) support
1341+
if mode == 'openmp':
1342+
mode = 'noop'
1343+
options = {'openmp': True}
13401344
elif isinstance(opt, tuple):
13411345
if len(opt) == 0:
13421346
mode, options = 'noop', {}
@@ -1353,7 +1357,7 @@ def parse_kwargs(**kwargs):
13531357
# `opt`, deprecated kwargs
13541358
kwopenmp = kwargs.get('openmp', options.get('openmp'))
13551359
if kwopenmp is None:
1356-
openmp = kwargs.get('language', configuration['language']) == 'openmp'
1360+
openmp = 'openmp' in kwargs.get('language', configuration['language'])
13571361
else:
13581362
openmp = kwopenmp
13591363

@@ -1399,7 +1403,11 @@ def parse_kwargs(**kwargs):
13991403
kwargs['language'] = language
14001404
elif kwopenmp is not None:
14011405
# Handle deprecated `openmp` kwarg for backward compatibility
1402-
kwargs['language'] = 'openmp' if openmp else 'C'
1406+
if configuration['language'] in ['C', 'CXX']:
1407+
lang = configuration['language']
1408+
kwargs['language'] = f'{lang}openmp' if openmp else lang
1409+
else:
1410+
kwargs['language'] = 'openmp' if openmp else 'C'
14031411
else:
14041412
kwargs['language'] = configuration['language']
14051413

devito/passes/iet/languages/CXX.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CXXPrinter(BasePrinter, CXX11CodePrinter):
9393
_func_literals = {}
9494
_func_prefix = {np.float32: 'f', np.float64: 'f'}
9595
_restrict_keyword = '__restrict'
96-
_includes = ['stdlib.h', 'cmath', 'sys/time.h']
96+
_includes = ['cstdlib', 'cmath', 'sys/time.h']
9797

9898
# These cannot go through _print_xxx because they are classes not
9999
# instances

tests/test_cinterface.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from devito import Eq, Grid, Operator, TimeFunction
3+
from devito import Eq, Grid, Operator, TimeFunction, configuration
44
from devito.types import Timer
55

66

@@ -15,11 +15,13 @@ def test_basic():
1515
op = Operator(eq, name=name)
1616

1717
# Trigger the generation of a .c and a .h files
18+
cpp = configuration['compiler']._cpp or 'CXX' in configuration['language']
1819
ccode, hcode = op.cinterface(force=True)
20+
ec, eh = ('cpp', 'h') if cpp else ('c', 'h')
1921

2022
dirname = op._compiler.get_jit_dir()
21-
assert os.path.isfile(os.path.join(dirname, "%s.c" % name))
22-
assert os.path.isfile(os.path.join(dirname, "%s.h" % name))
23+
assert os.path.isfile(os.path.join(dirname, f"{name}.{ec}"))
24+
assert os.path.isfile(os.path.join(dirname, f"{name}.{eh}"))
2325

2426
ccode = str(ccode)
2527
hcode = str(hcode)

0 commit comments

Comments
 (0)