Skip to content

Commit 0a4d71f

Browse files
committed
misc: Refactoring and cleanup
1 parent 80fcbcb commit 0a4d71f

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

devito/operator/operator.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ def estimate_memory(self, **kwargs):
875875
"""
876876
Estimate the memory consumed by the Operator without touching or allocating any
877877
data. This interface is designed to mimic `Operator.apply(**kwargs)` and can be
878-
called with the kwargs for a prospective operator execution. With no arguments,
879-
it will simply estimate memory for the default operator parameters. However, if
878+
called with the kwargs for a prospective Operator execution. With no arguments,
879+
it will simply estimate memory for the default Operator parameters. However, if
880880
desired, overrides can be supplied (as per `apply`) and these will be used for
881881
the memory estimate.
882882
@@ -886,7 +886,7 @@ def estimate_memory(self, **kwargs):
886886
the underlying array is only created at the point at which the `data`,
887887
`data_with_halo`, etc, attributes are first accessed. Thus by avoiding accessing
888888
such attributes in the memory estimation script, one can check the nominal memory
889-
usage of proposed operators far larger than will fit in system DRAM.
889+
usage of proposed Operators far larger than will fit in system DRAM.
890890
891891
Note that this estimate will build the Operator in order to factor in memory
892892
allocation for array temporaries and buffers generated during compilation.
@@ -910,7 +910,7 @@ def estimate_memory(self, **kwargs):
910910

911911
memreport = {'host': mem[host_layer], 'device': mem[device_layer]}
912912

913-
# Extra information for enriched operators
913+
# Extra information for enriched Operators
914914
extras = self._enrich_memreport(args)
915915
memreport.update(extras)
916916

@@ -1336,28 +1336,28 @@ def nbytes_avail_mapper(self):
13361336

13371337
@cached_property
13381338
def nbytes_consumed(self):
1339-
"""Memory consumed by all objects in the operator"""
1339+
"""Memory consumed by all objects in the Operator"""
13401340
mem_locations = (
1341-
self.nbytes_consumed_function,
1342-
self.nbytes_consumed_array,
1341+
self.nbytes_consumed_functions,
1342+
self.nbytes_consumed_arrays,
13431343
self.nbytes_consumed_memmapped
13441344
)
13451345
return {layer: sum(loc[layer] for loc in mem_locations) for layer in _layers}
13461346

13471347
@cached_property
13481348
def nbytes_consumed_operator(self):
1349-
"""Memory consumed by objects allocated within the operator"""
1349+
"""Memory consumed by objects allocated within the Operator"""
13501350
mem_locations = (
1351-
self.nbytes_consumed_array,
1351+
self.nbytes_consumed_arrays,
13521352
self.nbytes_consumed_memmapped
13531353
)
13541354
return {layer: sum(loc[layer] for loc in mem_locations) for layer in _layers}
13551355

13561356
@cached_property
1357-
def nbytes_consumed_function(self):
1357+
def nbytes_consumed_functions(self):
13581358
"""
13591359
Memory consumed on both device and host by Functions in the
1360-
corresponding operator.
1360+
corresponding Operator.
13611361
"""
13621362
def get_nbytes(obj):
13631363
if obj.is_regular:
@@ -1374,11 +1374,8 @@ def get_nbytes(obj):
13741374
host = 0
13751375
device = 0
13761376

1377-
# Symbols in the operator which may or may not carry data
1378-
op_symbols = FindSymbols().visit(self.op)
1379-
13801377
# Filter out arrays, aliases and non-AbstractFunction objects
1381-
op_symbols = [i for i in op_symbols if i.is_AbstractFunction
1378+
op_symbols = [i for i in self._op_symbols if i.is_AbstractFunction
13821379
and not i.is_ArrayBasic and not i.alias]
13831380

13841381
for i in op_symbols:
@@ -1401,17 +1398,17 @@ def get_nbytes(obj):
14011398
return {disk_layer: 0, host_layer: host, device_layer: device}
14021399

14031400
@cached_property
1404-
def nbytes_consumed_array(self):
1401+
def nbytes_consumed_arrays(self):
14051402
"""
14061403
Memory consumed on both device and host by C-land Arrays
1407-
in the corresponding operator.
1404+
in the corresponding Operator.
14081405
"""
14091406
host = 0
14101407
device = 0
14111408

14121409
# Temporaries such as Arrays are allocated and deallocated on-the-fly
14131410
# while in C land, so they need to be accounted for as well
1414-
for i in FindSymbols().visit(self.op):
1411+
for i in self._op_symbols:
14151412
if not i.is_Array or not i._mem_heap or i.alias:
14161413
continue
14171414

@@ -1466,11 +1463,8 @@ def nbytes_consumed_memmapped(self):
14661463

14671464
@cached_property
14681465
def nbytes_snapshots(self):
1469-
# Symbols in the operator which may or may not carry data
1470-
op_symbols = FindSymbols().visit(self.op)
1471-
14721466
# Filter to streamed functions
1473-
op_symbols = [i for i in op_symbols if i.is_AbstractFunction
1467+
op_symbols = [i for i in self._op_symbols if i.is_AbstractFunction
14741468
and not i.is_ArrayBasic and not i.alias]
14751469

14761470
disk = 0
@@ -1487,6 +1481,11 @@ def nbytes_snapshots(self):
14871481

14881482
return {disk_layer: disk, host_layer: 0, device_layer: 0}
14891483

1484+
@cached_property
1485+
def _op_symbols(self):
1486+
"""Symbols in the Operator which may or may not carry data"""
1487+
return FindSymbols().visit(self.op)
1488+
14901489

14911490
def parse_kwargs(**kwargs):
14921491
"""

0 commit comments

Comments
 (0)