Skip to content

Commit

Permalink
compiler: Add AbstractFunction.is_persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Dec 23, 2024
1 parent d26ee15 commit 76651c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion devito/builtins/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def wrapper(*args, **kwargs):

for i in args:
try:
if i.is_transient:
if not i.is_persistent:
raise ValueError(f"Cannot apply `{func.__name__}` to transient "
f"function `{i.name}` on backend `{platform}`")
except AttributeError:
Expand Down
18 changes: 14 additions & 4 deletions devito/types/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,10 @@ def __init_finalize__(self, *args, **kwargs):
assert self._space in ['local', 'mapped', 'host']

# If True, the AbstractFunction is treated by the compiler as a "transient
# field", meaning that its content is only useful within an Operator
# execution, but the final data is not expected to be read back in
# Python-land by the user. This allows the compiler/run-time to apply
# certain optimizations, such as avoiding memory copies
# field", meaning that its content cannot be accessed by the user in
# Python-land. This allows the compiler/run-time to apply certain
# optimizations, such as avoiding memory copies across different Operator
# executions
self._is_transient = kwargs.get('is_transient', False)

# Averaging mode for off the grid evaluation
Expand Down Expand Up @@ -1274,6 +1274,16 @@ def is_const(self):
def is_transient(self):
return self._is_transient

@property
def is_persistent(self):
"""
True if the AbstractFunction is persistent, i.e., its data is guaranteed
to exist across multiple Operator invocations, False otherwise.
By default, transient AbstractFunctions are not persistent. However,
subclasses may override this behavior.
"""
return not self.is_transient

@cached_property
def properties(self):
return frozendict([(i, getattr(self, i)) for i in self.__properties__])
Expand Down

0 comments on commit 76651c8

Please sign in to comment.