Skip to content

Commit

Permalink
compiler: Draft operator error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
FabioLuporini committed Mar 12, 2024
1 parent 221a09a commit a5c9062
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions devito/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ class InvalidOperator(DevitoError):
pass


class ExecutionError(DevitoError):
pass


class VisitorException(DevitoError):
pass
7 changes: 5 additions & 2 deletions devito/ir/iet/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,17 +794,19 @@ class CallableBody(MultiTraversable):
Data unbundling for `body`.
frees : list of Calls, optional
Data deallocations for `body`.
errors : list of Nodes, optional
Error handling for `body`.
"""

is_CallableBody = True

_traversable = ['unpacks', 'init', 'standalones', 'allocs', 'stacks',
'casts', 'bundles', 'maps', 'strides', 'objs', 'body',
'unmaps', 'unbundles', 'frees']
'unmaps', 'unbundles', 'frees', 'errors']

def __init__(self, body, init=(), standalones=(), unpacks=(), strides=(),
allocs=(), stacks=(), casts=(), bundles=(), objs=(), maps=(),
unmaps=(), unbundles=(), frees=()):
unmaps=(), unbundles=(), frees=(), errors=()):
# Sanity check
assert not isinstance(body, CallableBody), "CallableBody's cannot be nested"

Expand All @@ -823,6 +825,7 @@ def __init__(self, body, init=(), standalones=(), unpacks=(), strides=(),
self.unmaps = as_tuple(unmaps)
self.unbundles = as_tuple(unbundles)
self.frees = as_tuple(frees)
self.errors = as_tuple(errors)

def __repr__(self):
return ("<CallableBody <unpacks=%d, allocs=%d, casts=%d, maps=%d, "
Expand Down
14 changes: 11 additions & 3 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from devito.arch import compiler_registry, platform_registry
from devito.data import default_allocator
from devito.exceptions import InvalidOperator
from devito.exceptions import InvalidOperator, ExecutionError
from devito.logger import debug, info, perf, warning, is_log_enabled_for
from devito.ir.equations import LoweredEq, lower_exprs
from devito.ir.clusters import ClusterGroup, clusterize
Expand All @@ -21,7 +21,8 @@
from devito.mpi import MPI
from devito.parameters import configuration
from devito.passes import (Graph, lower_index_derivatives, generate_implicit,
generate_macros, minimize_symbols, unevaluate)
generate_macros, minimize_symbols, unevaluate,
error_mapper)
from devito.symbolics import estimate_cost
from devito.tools import (DAG, OrderedSet, Signer, ReducerMap, as_tuple, flatten,
filter_sorted, frozendict, is_integer, split, timed_pass,
Expand Down Expand Up @@ -647,7 +648,14 @@ def _prepare_arguments(self, autotune=None, **kwargs):
return args

def _postprocess_errors(self, retval):
return
if retval == 0:
return
elif retval == error_mapper['Stability']:
raise ExecutionError("Detected nan/inf in some output Functions")
elif retval == error_mapper['KernelLaunch']:
raise ExecutionError("Kernel launch failed")
else:
raise ExecutionError("An error occurred during execution")

def _postprocess_arguments(self, args, **kwargs):
"""Process runtime arguments upon returning from ``.apply()``."""
Expand Down
1 change: 1 addition & 0 deletions devito/passes/iet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .asynchrony import * # noqa
from .instrument import * # noqa
from .languages import * # noqa
from .errors import * # noqa
19 changes: 19 additions & 0 deletions devito/passes/iet/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from devito.passes.iet.engine import iet_pass

__all__ = ['check_stability', 'error_mapper']


@iet_pass
def check_stability(iet, **kwargs):
"""
Check if the simulation is stable. If not, return to Python as quickly as
possible with an error code.
"""
# TODO
return iet, {}


error_mapper = {
'Stability': 100,
'KernelLaunch': 200,
}

0 comments on commit a5c9062

Please sign in to comment.