Skip to content

Commit 2362257

Browse files
committed
misc: fix typos and formatting
1 parent 8eec8d8 commit 2362257

File tree

9 files changed

+44
-50
lines changed

9 files changed

+44
-50
lines changed

devito/arch/archinfo.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ def cbk(deviceid=0):
383383
def make_cbk(i):
384384
def cbk(deviceid=0):
385385
return None
386+
return cbk
387+
386388
gpu_info['mem.%s' % i] = make_cbk(i)
387389

388390
gpu_infos['architecture'] = 'Intel'
@@ -452,7 +454,7 @@ def parse_product_arch():
452454
gpu_infos = []
453455
for line in lines:
454456
# Graphics cards are listed as VGA or 3D controllers in lspci
455-
if 'VGA' in line or '3D' in line or 'Display' in line:
457+
if any(i in line for i in ('VGA', '3D', 'Display')):
456458
gpu_info = {}
457459
# Lines produced by lspci command are of the form:
458460
# xxxx:xx:xx.x Device Type: Name

devito/arch/compiler.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,9 @@ class PGICompiler(Compiler):
606606

607607
def __init_finalize__(self, **kwargs):
608608

609-
self.cflags.remove(f'-std={self.std}')
610609
self.cflags.remove('-O3')
611610
self.cflags.remove('-Wall')
612611

613-
self.cflags.append(f'-std={self.std}')
614-
615612
language = kwargs.pop('language', configuration['language'])
616613
platform = kwargs.pop('platform', configuration['platform'])
617614

@@ -659,10 +656,9 @@ class CudaCompiler(Compiler):
659656

660657
def __init_finalize__(self, **kwargs):
661658

662-
self.cflags.remove(f'-std={self.std}')
663659
self.cflags.remove('-Wall')
664660
self.cflags.remove('-fPIC')
665-
self.cflags.extend([f'-std={self.std}', '-Xcompiler', '-fPIC'])
661+
self.cflags.append('-Xcompiler')
666662

667663
if configuration['mpi']:
668664
# We rather use `nvcc` to compile MPI, but for this we have to
@@ -733,11 +729,6 @@ class HipCompiler(Compiler):
733729

734730
def __init_finalize__(self, **kwargs):
735731

736-
self.cflags.remove(f'-std={self.std}')
737-
self.cflags.remove('-Wall')
738-
self.cflags.remove('-fPIC')
739-
self.cflags.extend([f'-std={self.std}', '-fPIC'])
740-
741732
if configuration['mpi']:
742733
# We rather use `hipcc` to compile MPI, but for this we have to
743734
# explicitly pass the flags that an `mpicc` would implicitly use
@@ -843,7 +834,7 @@ def __init_finalize__(self, **kwargs):
843834
language = kwargs.pop('language', configuration['language'])
844835

845836
if language == 'sycl':
846-
warning("Use SyclCompiler to jit-compile sycl")
837+
warning(f"Use SyclCompiler (`sycl`) to jit-compile sycl, not {self.name}")
847838

848839
elif language == 'openmp':
849840
# Earlier versions to OneAPI 2023.2.0 (clang17 underneath), have an
@@ -899,7 +890,7 @@ def __init_finalize__(self, **kwargs):
899890
language = kwargs.pop('language', configuration['language'])
900891

901892
if language != 'sycl':
902-
warning("Expected language sycl with SyclCompiler")
893+
warning(f"Expected language sycl with SyclCompiler, not {language}")
903894

904895
self.cflags.remove(f'-std={self.std}')
905896
self.cflags.append('-fsycl')

devito/core/operator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class BasicOperator(Operator):
7171

7272
SCALAR_MIN_TYPE = np.float16
7373
"""
74-
Minimum datatype for a scalar alias for a common sub-expression or cire temp.
74+
Minimum datatype for a scalar alias for a common sub-expression or CIRE temp.
7575
"""
7676

7777
PAR_COLLAPSE_NCORES = 4

devito/ir/cgen/printer.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class BasePrinter(CodePrinter):
3636
**CodePrinter._default_settings}
3737

3838
_func_prefix = {}
39-
_func_litterals = {}
39+
_func_literals = {}
40+
_prec_literals = {np.float32: 'F', np.complex64: 'F'}
4041

4142
_qualifiers_mapper = {
4243
'is_const': 'const',
@@ -45,14 +46,10 @@ class BasePrinter(CodePrinter):
4546
'_mem_shared': '',
4647
}
4748

48-
_prec_litterals = {np.float32: 'F', np.complex64: 'F'}
49-
5049
_restrict_keyword = 'restrict'
5150

5251
_includes = []
53-
5452
_namespaces = []
55-
5653
_headers = [('_POSIX_C_SOURCE', '200809L')]
5754

5855
@property
@@ -68,16 +65,13 @@ def compiler(self):
6865

6966
def doprint(self, expr, assign_to=None):
7067
"""
71-
The sympy code printer does a lot of extra we do not need as we handle all of
72-
it in the compiler so we directly defaults to `_print`.
68+
The sympy code printer does a lot of extra things we do not need
69+
as we handle all of it in the compiler so we directly default to `_print`.
7370
"""
7471
return self._print(expr)
7572

7673
def _prec(self, expr):
77-
try:
78-
dtype = sympy_dtype(expr, default=self.dtype)
79-
except TypeError:
80-
return self.dtype
74+
dtype = sympy_dtype(expr, default=self.dtype)
8175
if dtype is None or np.issubdtype(dtype, np.integer):
8276
if any(isinstance(i, Float) for i in expr.atoms()):
8377
try:
@@ -91,17 +85,19 @@ def _prec(self, expr):
9185
return dtype or self.dtype
9286

9387
def prec_literal(self, expr):
94-
return self._prec_litterals.get(self._prec(expr), '')
88+
return self._prec_literals.get(self._prec(expr), '')
9589

9690
def func_literal(self, expr):
97-
return self._func_litterals.get(self._prec(expr), '')
91+
return self._func_literals.get(self._prec(expr), '')
9892

9993
def func_prefix(self, expr, mfunc=False):
10094
prefix = self._func_prefix.get(self._prec(expr), '')
10195
if mfunc:
10296
return prefix
97+
elif prefix == 'f':
98+
return ''
10399
else:
104-
return '' if prefix == 'f' else prefix
100+
return prefix
105101

106102
def parenthesize(self, item, level, strict=False):
107103
if isinstance(item, BooleanFunction):
@@ -271,7 +267,7 @@ def _print_Abs(self, expr):
271267
arg = expr.args[0]
272268
# AOMPCC errors with abs, always use fabs
273269
if isinstance(self.compiler, AOMPCompiler) and \
274-
not np.issubdtype(self._prec(expr), np.integer):
270+
not np.issubdtype(self._prec(expr), np.integer):
275271
return f"fabs({self._print(arg)})"
276272
return self._print_fmath_func('abs', expr)
277273

devito/ir/iet/visitors.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ def _gen_struct_decl(self, obj, masked=()):
208208
while issubclass(ctype, ctypes._Pointer):
209209
ctype = ctype._type_
210210

211-
if not issubclass(ctype, ctypes.Structure) or issubclass(ctype, NoDeclStruct):
211+
if not issubclass(ctype, ctypes.Structure) or \
212+
issubclass(ctype, NoDeclStruct):
212213
return None
213214
except TypeError:
214215
# E.g., `ctype` is of type `dtypes_lowering.CustomDtype`

devito/operator/operator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,9 @@ def parse_kwargs(**kwargs):
14311431

14321432
# `allocator`
14331433
kwargs['allocator'] = default_allocator(
1434-
f"{kwargs['compiler'].__class__.__name__}.{kwargs['language']}.{kwargs['platform']}" # noqa
1434+
f"{kwargs['compiler'].__class__.__name__}"
1435+
f".{kwargs['language']}"
1436+
f".{kwargs['platform']}"
14351437
)
14361438

14371439
# Normalize `subs`, if any

devito/passes/clusters/aliases.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(self, sregistry, options, platform):
113113
self.opt_rotate = options['cire-rotate']
114114
self.opt_ftemps = options['cire-ftemps']
115115
self.opt_mingain = options['cire-mingain']
116-
self.opt_mindtype = options['scalar-min-type']
116+
self.opt_min_dtype = options['scalar-min-type']
117117
self.opt_multisubdomain = True
118118

119119
def _aliases_from_clusters(self, clusters, exclude, meta):
@@ -143,7 +143,7 @@ def _aliases_from_clusters(self, clusters, exclude, meta):
143143

144144
# Schedule -> [Clusters]_k
145145
processed, subs = lower_schedule(schedule, meta, self.sregistry,
146-
self.opt_ftemps, self.opt_mindtype)
146+
self.opt_ftemps, self.opt_min_dtype)
147147

148148
# [Clusters]_k -> [Clusters]_k (optimization)
149149
if self.opt_multisubdomain:
@@ -831,7 +831,7 @@ def optimize_schedule_rotations(schedule, sregistry):
831831
return schedule.rebuild(*processed, rmapper=rmapper)
832832

833833

834-
def lower_schedule(schedule, meta, sregistry, ftemps, mindtype):
834+
def lower_schedule(schedule, meta, sregistry, ftemps, min_dtype):
835835
"""
836836
Turn a Schedule into a sequence of Clusters.
837837
"""
@@ -849,8 +849,6 @@ def lower_schedule(schedule, meta, sregistry, ftemps, mindtype):
849849
# This prevents cases such as `floor(a*b)` with `a` and `b` floats
850850
# that would creat a temporary `int r = b` leading to erronous
851851
# numerical results
852-
mindtype = None if writeto else mindtype
853-
dtype = sympy_dtype(pivot, base=meta.dtype, smin=mindtype)
854852

855853
if writeto:
856854
# The Dimensions defining the shape of Array
@@ -882,6 +880,7 @@ def lower_schedule(schedule, meta, sregistry, ftemps, mindtype):
882880
# E.g., `z` -- a non-shifted Dimension
883881
indices.append(i.dim - i.lower)
884882

883+
dtype = sympy_dtype(pivot, base=meta.dtype)
885884
obj = make(name=name, dimensions=dimensions, halo=halo, dtype=dtype)
886885
expression = Eq(obj[indices], uxreplace(pivot, subs))
887886

@@ -890,6 +889,7 @@ def lower_schedule(schedule, meta, sregistry, ftemps, mindtype):
890889
# Degenerate case: scalar expression
891890
assert writeto.size == 0
892891

892+
dtype = sympy_dtype(pivot, base=meta.dtype, smin=min_dtype)
893893
obj = Temp(name=name, dtype=dtype)
894894
expression = Eq(obj, uxreplace(pivot, subs))
895895

devito/passes/iet/languages/C.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CPrinter(BasePrinter, C99CodePrinter):
4242

4343
_default_settings = {**BasePrinter._default_settings,
4444
**C99CodePrinter._default_settings}
45-
_func_litterals = {np.float32: 'f', np.complex64: 'f'}
45+
_func_literals = {np.float32: 'f', np.complex64: 'f'}
4646
_func_prefix = {np.float32: 'f', np.float64: 'f',
4747
np.complex64: 'c', np.complex128: 'c'}
4848
_includes = ['stdlib.h', 'math.h', 'sys/time.h']

devito/passes/iet/languages/CXX.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,54 @@
88
__all__ = ['CXXBB']
99

1010

11-
def std_arith(qualifier=None):
12-
if qualifier:
13-
qual = qualifier if qualifier.endswith(" ") else f"{qualifier} "
11+
def std_arith(prefix=None):
12+
if prefix:
13+
# Method definition prefix, e.g. "__host__"
14+
# Make sure there is a space between the prefix and the method name
15+
prefix = prefix if prefix.endswith(" ") else f"{prefix} "
1416
else:
15-
qual = ""
17+
prefix = ""
1618
return f"""
1719
#include <complex>
1820
1921
template<typename _Tp, typename _Ti>
20-
{qual}std::complex<_Tp> operator * (const _Ti & a, const std::complex<_Tp> & b){{
22+
{prefix}std::complex<_Tp> operator * (const _Ti & a, const std::complex<_Tp> & b){{
2123
return std::complex<_Tp>(b.real() * a, b.imag() * a);
2224
}}
2325
2426
template<typename _Tp, typename _Ti>
25-
{qual}std::complex<_Tp> operator * (const std::complex<_Tp> & b, const _Ti & a){{
27+
{prefix}std::complex<_Tp> operator * (const std::complex<_Tp> & b, const _Ti & a){{
2628
return std::complex<_Tp>(b.real() * a, b.imag() * a);
2729
}}
2830
2931
template<typename _Tp, typename _Ti>
30-
{qual}std::complex<_Tp> operator / (const _Ti & a, const std::complex<_Tp> & b){{
32+
{prefix}std::complex<_Tp> operator / (const _Ti & a, const std::complex<_Tp> & b){{
3133
_Tp denom = b.real() * b.real () + b.imag() * b.imag();
3234
return std::complex<_Tp>(b.real() * a / denom, - b.imag() * a / denom);
3335
}}
3436
3537
template<typename _Tp, typename _Ti>
36-
{qual}std::complex<_Tp> operator / (const std::complex<_Tp> & b, const _Ti & a){{
38+
{prefix}std::complex<_Tp> operator / (const std::complex<_Tp> & b, const _Ti & a){{
3739
return std::complex<_Tp>(b.real() / a, b.imag() / a);
3840
}}
3941
4042
template<typename _Tp, typename _Ti>
41-
{qual}std::complex<_Tp> operator + (const _Ti & a, const std::complex<_Tp> & b){{
43+
{prefix}std::complex<_Tp> operator + (const _Ti & a, const std::complex<_Tp> & b){{
4244
return std::complex<_Tp>(b.real() + a, b.imag());
4345
}}
4446
4547
template<typename _Tp, typename _Ti>
46-
{qual}std::complex<_Tp> operator + (const std::complex<_Tp> & b, const _Ti & a){{
48+
{prefix}std::complex<_Tp> operator + (const std::complex<_Tp> & b, const _Ti & a){{
4749
return std::complex<_Tp>(b.real() + a, b.imag());
4850
}}
4951
5052
template<typename _Tp, typename _Ti>
51-
{qual}std::complex<_Tp> operator - (const _Ti & a, const std::complex<_Tp> & b){{
53+
{prefix}std::complex<_Tp> operator - (const _Ti & a, const std::complex<_Tp> & b){{
5254
return std::complex<_Tp>(a = b.real(), b.imag());
5355
}}
5456
5557
template<typename _Tp, typename _Ti>
56-
{qual}std::complex<_Tp> operator - (const std::complex<_Tp> & b, const _Ti & a){{
58+
{prefix}std::complex<_Tp> operator - (const std::complex<_Tp> & b, const _Ti & a){{
5759
return std::complex<_Tp>(b.real() - a, b.imag());
5860
}}
5961
@@ -88,7 +90,7 @@ class CXXPrinter(BasePrinter, CXX11CodePrinter):
8890
_default_settings = {**BasePrinter._default_settings,
8991
**CXX11CodePrinter._default_settings}
9092
_ns = "std::"
91-
_func_litterals = {}
93+
_func_literals = {}
9294
_func_prefix = {np.float32: 'f', np.float64: 'f'}
9395
_restrict_keyword = '__restrict'
9496
_includes = ['stdlib.h', 'cmath', 'sys/time.h']

0 commit comments

Comments
 (0)