afe.backends.backend_checker
This file contains classes for how to implement a checker class for each IR and how to execute checkers. There are 2 classes:
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.
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
Classes
Holds reasons why operators were rejected by a backend checker. |
|
A decision from the checker about one expression. |
|
A decision to accept an expression, that is, assign it to the selected backend. |
|
A decision to reject an expression, that is, not assign it to the selected backend. |
|
Properties of one Relay IR expression that are relevant to backend assignment. |
|
A way to decide whether a given expression can be executed on a selected backend. |
Functions
|
Make a Decision from a boolean value. |
|
Make a predicate that returns Accept if any predicate in the list returns Accept. |
|
Make a predicate that returns Accept if all predicates in the list return Accept. |
Module Contents
- class afe.backends.backend_checker.Rejections[source]
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.
- class afe.backends.backend_checker.Decision[source]
A decision from the checker about one expression. This is an algebraic data type.
- class afe.backends.backend_checker.Accept[source]
A decision to accept an expression, that is, assign it to the selected backend.
- class afe.backends.backend_checker.Reject[source]
A decision to reject an expression, that is, not assign it to the selected backend. The error codes give the reason it is rejected.
- afe.backends.backend_checker.decision_from_bool(b: bool, error_code: int) Decision [source]
Make a Decision from a boolean value.
- Parameters:
b – Whether to return Accept or Reject.
error_code – Which error code to include if Reject is returned. Error codes should match the numbers in unsupported_code_codebook.
- Returns:
Decision made from b and error_code.
- class afe.backends.backend_checker.ExprCheckInfo[source]
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.
- Parameters:
name – Name of the expression’s operator.
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.
input_shapes – Shapes of the expression’s input tensors.
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.
- afe.backends.backend_checker.pany(ps: Sequence[Predicate]) Predicate [source]
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.
- afe.backends.backend_checker.pall(ps: Sequence[Predicate]) Predicate [source]
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.
- class afe.backends.backend_checker.BaseChecker[source]
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.
- Parameters:
_checkers_name – str. Name of the checker’s factory class.
_backend – The type of the Backend.
_predicate – Predicate that decides whether an operator can execute on the backend.
- classmethod get_backend() afe.backends.Backend [source]
Return the backend for which this checker class makes decisions.
- classmethod check(args: ExprCheckInfo) Decision [source]
Examine properties of an expression to decide whether the expression can be assigned to this checker’s associated backend.