afe.backends.backend_checker ============================ .. py:module:: afe.backends.backend_checker .. autoapi-nested-parse:: This file contains classes for how to implement a checker class for each IR and how to execute checkers. There are 2 classes: 1. ExprCheckInfo - A class that acts as an interface for each check function. Developer has to make sure a check function takes a CheckerInterface object as its input arguments. When implementing an IR checker, arguments needed to perform all the check functions must be present in a CheckerInterface object. The CheckerInterface instance should be created for each operator and the backend checker's check() method should be called to determine if an operator is supported by a certain backend. 2. BaseChecker - An abstract class that is the base class for checkers. Developer should inherit this class and implement a new checker for each of supported backends. When implementing a new checker developer needs to implement a checker function for each supported operator and call it from the checker's check() method. The checker function which is to be called is determined by the CheckerInterface's 'name' attribute. The checker function should determine if the backend supports an operator using CheckerInterface's 'attrs' and 'input_shapes'. Example: class MLACheckers(BaseChecker): _checkers_name: str = "MLA Checkers" _backend = Backend.MLA _predicate = paccept # Accept everything Attributes ---------- .. autoapisummary:: afe.backends.backend_checker.CheckerAttr afe.backends.backend_checker.CheckerInputShapes afe.backends.backend_checker.Predicate afe.backends.backend_checker.paccept Classes ------- .. autoapisummary:: afe.backends.backend_checker.Rejections afe.backends.backend_checker.Decision afe.backends.backend_checker.Accept afe.backends.backend_checker.Reject afe.backends.backend_checker.ExprCheckInfo afe.backends.backend_checker.BaseChecker Functions --------- .. autoapisummary:: afe.backends.backend_checker.decision_from_bool afe.backends.backend_checker.pany afe.backends.backend_checker.pall Module Contents --------------- .. py:data:: CheckerAttr .. py:data:: CheckerInputShapes .. py:class:: Rejections Holds reasons why operators were rejected by a backend checker. This is used by tests that verify checker decisions. error_codes[i] is the list of error codes produced for the i_th operator that was examined. The list is empty if the operator was accepted. .. py:attribute:: error_codes :type: List[List[int]] .. py:class:: Decision A decision from the checker about one expression. This is an algebraic data type. .. py:class:: Accept A decision to accept an expression, that is, assign it to the selected backend. .. py:class:: Reject A decision to reject an expression, that is, not assign it to the selected backend. The error codes give the reason it is rejected. .. py:attribute:: error_codes :type: List[int] .. py:function:: decision_from_bool(b: bool, error_code: int) -> Decision Make a Decision from a boolean value. :param b: Whether to return Accept or Reject. :param error_code: Which error code to include if Reject is returned. Error codes should match the numbers in unsupported_code_codebook. :return: Decision made from b and error_code. .. py:class:: ExprCheckInfo Properties of one Relay IR expression that are relevant to backend assignment. An ExprCheckInfo is passed to a backend checker for deciding whether the expression can run on that backend. :param name: Name of the expression's operator. :param attrs: A list of Relay operator attributes. If the expression is a composite operator, the list has one item for each call in the composite operator's body. Otherwise, it has a single item, which is the expression's attribute. :param input_shapes: Shapes of the expression's input tensors. :param is_constant: List of boolean values providing information whether certain input is a constant. :param: idx: The expression's index in the graph's topological order. .. py:attribute:: name :type: str .. py:attribute:: attrs :type: List[CheckerAttr] .. py:attribute:: input_shapes :type: CheckerInputShapes .. py:attribute:: is_constant :type: List[bool] .. py:attribute:: idx :type: int .. py:data:: Predicate .. py:function:: pany(ps: Sequence[Predicate]) -> Predicate Make a predicate that returns Accept if any predicate in the list returns Accept. When Reject is returned, it contains the concatenation of all predicates' error codes. .. py:function:: pall(ps: Sequence[Predicate]) -> Predicate Make a predicate that returns Accept if all predicates in the list return Accept. When Reject is returned, it contains the concatenation of all predicates' error codes. All predicates in the list are evaluated. .. py:data:: paccept .. py:class:: BaseChecker A way to decide whether a given expression can be executed on a selected backend. This class should be implemented by subclassing and overriding the class variables. It is not meant to be instantiated. :param _checkers_name: str. Name of the checker's factory class. :param _backend: The type of the Backend. :param _predicate: Predicate that decides whether an operator can execute on the backend. .. py:method:: get_backend() -> afe.backends.Backend :classmethod: Return the backend for which this checker class makes decisions. .. py:method:: check(args: ExprCheckInfo) -> Decision :classmethod: Examine properties of an expression to decide whether the expression can be assigned to this checker's associated backend.