Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions backends/arm/tosa/dialect/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@


def register_tosa_dialect_op(op_schema, func) -> Callable:
"""Register a TOSA dialect operator with the backend op library.

Args:
op_schema (str): Operator schema without namespace or overload name.
func (Callable): Fake implementation used for registration.

Returns:
Callable: Backend dialect operator handle exposed via ``exir_ops`` and
marked ``not_callable`` for runtime use.

"""
if tosa_lib.ns not in _BACKEND_OP_LIB:
_BACKEND_OP_LIB.append(tosa_lib.ns)

Expand Down Expand Up @@ -43,6 +54,7 @@ def register_tosa_dialect_op(op_schema, func) -> Callable:
# the op doesn't need to be callable. This can be changed in the future if needed to support
# execution of TOSA ops directly.
def not_callable():
"""Raise when the dialect op handle is invoked at runtime."""
raise RuntimeError("TOSA dialect op is not callable")

op.__equvalent_callable__ = not_callable
Expand All @@ -51,11 +63,22 @@ def not_callable():


class TosaValueError(ValueError):
"""Error type that annotates failures with the originating TOSA op."""

def __init__(self, message="A TOSA value error occurred", *args, op=None):
"""Initialise the error with optional operator metadata.

Args:
message (str): Human-readable error message.
*args: Additional arguments forwarded to ``ValueError``.
op: Optional operator identifier included in the string output.

"""
super().__init__(message, *args)
self.op = op

def __str__(self):
"""Return the base message, appending the operator when provided."""
base_message = super().__str__()
if self.op is not None:
return f"{base_message} (TOSA op: {self.op})"
Expand Down
Loading