fhelium.backend.implementation
Register and resolve operation implementations contributed by Backend components.
Implementation classes declare the operations they support and a stable name. The registry stores supplied implementation objects, rejects duplicate identities, and resolves operation-class and name selections.
FusionImplementation
class View source
FusionImplementation()Bases: OperationImplementation, Protocol
Describe region support supplied by one joint-execution implementation.
Implementations may provide new_fusion_matcher() -> FusionMatcher to analyze successive candidates incrementally during one scheduling window. Other implementations use match_fusion for each complete candidate.
match_fusion
method
def match_fusion(operations: Sequence[Operation]) -> int | None: ...Return a computational-op count for an eligible fusion candidate.
Zero denotes plumbing; None denotes an unsupported or ineligible candidate. Unknown facts may remain unresolved until execution binding. The count records computational operations.
FusionMatcher
class View source
FusionMatcher()Bases: Protocol
Maintain candidate facts while a scheduler reads an unchanged SSA graph.
probe
method
def probe(operation: Operation) -> int | None: ...Match an extension without committing it to the current region.
append
method
def append(operation: Operation) -> None: ...Commit a selected extension, even if this implementation rejects it.
reset
method
def reset() -> None: ...Discard region facts before considering a new region.
ImplementationRegistry
class View source
ImplementationRegistry(implementations: Sequence[ImplementationT]=(), *, category: str)Store implementations by supported operation class and stable name.
Backend assembly supplies the implementation objects and their declarations. Resolution selects among those registered candidates.
operation_types
property
operation_types: tuple[type[Operation], ...]Return operation classes in first declaration order.
implementations
property
implementations: tuple[ImplementationT, ...]Return implementation contributions in construction order.
available
method
def available(operation_type: type[Operation]) -> tuple[str, ...]: ...Return implementation names in declaration order.
supports
method
def supports(operation_type: type[Operation], *, name: str | None=None) -> bool: ...Return whether at least one matching implementation is registered.
resolve
method
def resolve(operation_type: type[Operation], *, requested: str | None) -> ImplementationT: ...Resolve one named implementation, refusing ambiguous defaults.
OperationImplementation
class View source
OperationImplementation()Bases: Protocol
Execute one or more registered operations on Tensor payloads.
name
property
name: stroperation_types
property
operation_types: tuple[type[Operation], ...]supports_in_place
property
supports_in_place: boolresource_requirements
method
def resource_requirements(invocation: OperationInvocation) -> tuple[ResourceRequirement, ...]: ...execute
method
def execute(invocation: OperationInvocation, inputs: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], /, *, in_place: bool) -> tuple[torch.Tensor, ...]: ...OperationImplementationRegistry
class View source
OperationImplementationRegistry(implementations: Sequence[OperationImplementation]=(), *, operation_specs: OperationSpecRegistry=DEFAULT_OPERATION_SPECS)Resolve implementations by operation class and identity.
operation_types
property
operation_types: tuple[type[Operation], ...]implementations
property
implementations: tuple[OperationImplementation, ...]Return implementation contributions in construction order.
with_implementations
method
def with_implementations(implementations: Sequence[OperationImplementation]) -> OperationImplementationRegistry: ...Return this registry extended by caller-supplied contributions.
available
method
def available(operation_type: type[Operation]) -> tuple[str, ...]: ...supports
method
def supports(operation: Operation, *, implementation: str | None=None) -> bool: ...resolve
method
def resolve(operation: Operation, *, requested: str | None, in_place: bool=False) -> OperationImplementation: ...resolve_type
method
def resolve_type(operation_type: type[Operation], *, requested: str | None, in_place: bool=False) -> OperationImplementation: ...effect
method
def effect(operation_type: type[Operation]) -> OperationEffect: ...Return the registered effect of one operation class.
OperationInvocation
class View source
OperationInvocation(operation_type: type[Operation], operand_count: int, result_count: int, attributes: Mapping[str, object] = field(default_factory=dict), operand_prime_ids: tuple[tuple[int, ...] | None, ...] = (), operand_bases: tuple[str | None, ...] = (), operand_components: tuple[int | None, ...] = (), result_prime_ids: tuple[tuple[int, ...] | None, ...] = ())Describe an operation class, operand/result counts, attributes, and represented value metadata.
Attributes
| Name | Type | Default/value |
|---|---|---|
operation_type | type[Operation] | |
operand_count | int | |
result_count | int | |
attributes | Mapping[str, object] | field(default_factory=dict) |
operand_prime_ids | tuple[tuple[int, ...] | None, ...] | () |
operand_bases | tuple[str | None, ...] | () |
operand_components | tuple[int | None, ...] | () |
result_prime_ids | tuple[tuple[int, ...] | None, ...] | () |
PreparingOperationImplementation
class View source
PreparingOperationImplementation()Bases: OperationImplementation, Protocol
Prepare one represented operation for direct Tensor execution.
Code-generating implementations consume the operation and its regions once during Backend resolution. The returned implementation executes the complete operation without interpreting its nested operations at runtime.
prepare_operation
method
def prepare_operation(operation: Operation) -> OperationImplementation: ...RegionCallable
data View source
RegionCallable = Callable[[tuple[torch.Tensor, ...]], tuple[torch.Tensor, ...]]RegionOperationImplementation
class View source
RegionOperationImplementation()Bases: OperationImplementation, Protocol
Execute an operation whose regions contain callable Tensor programs.
execute_regions
method
def execute_regions(invocation: OperationInvocation, inputs: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], regions: tuple[RegionCallable, ...], /, *, in_place: bool) -> tuple[torch.Tensor, ...]: ...operation_invocation
function View source
def operation_invocation(operation: Operation) -> OperationInvocation: ...Convert one linked IR operation to its runtime invocation descriptor.
requested_implementation
function View source
def requested_implementation(operation: Operation, caller_selection: str | None=None) -> str | None: ...Return the implementation recorded in IR or selected by the caller.
An assignment written by a Compile pass is a hard constraint. A caller may select an unassigned operation, but it may not contradict the Program.