fhelium.backend.triton
Triton code generation for component-aware modular arithmetic and transforms.
Backend registries select the generated implementations. Modular arithmetic uses integer Montgomery reduction and preserves native lazy residue ranges.
TritonFusionImplementation
class View source
TritonFusionImplementation(name: str = 'triton-rns-fused', include_ntt: bool = False, max_ntt_endpoints: int | None = None, operation_types: tuple[type[Operation], ...] = (fusion.FusedOp,), supports_in_place: bool = False)Generate indexed integer expression kernels from visible fusion regions.
Component extraction and packing become expression selection and output indexing. Arithmetic chains retain intermediates in registers and preserve every external result and identity-view alias. include_ntt admits transform dependencies; their execution plans compose generated endpoints, native stage ranges or complete transforms according to the selected algorithm. Match checks consume known Program facts, while missing layout/resource facts are checked when binding execution. Device compilation is lazy.
max_ntt_endpoints bounds transform endpoints per generated kernel while preserving their stage order. None selects eight endpoints on HIP to limit compiler IR growth and leaves CUDA endpoint merging unbounded.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'triton-rns-fused' |
include_ntt | bool | False |
max_ntt_endpoints | int | None | None |
operation_types | tuple[type[Operation], ...] | (fusion.FusedOp,) |
supports_in_place | bool | False |
select_ntt_schedule
method
def select_ntt_schedule(**facts): ...Select an NTT schedule independently of endpoint decomposition.
new_fusion_matcher
method
def new_fusion_matcher() -> FusionMatcher: ...Create candidate analysis scoped to a read-only scheduling window.
match_fusion
method
def match_fusion(operations: Sequence[Operation]) -> int | None: ...Match Program facts against this implementation's RNS/NTT support.
resource_requirements
method
def resource_requirements(invocation: OperationInvocation) -> tuple[ResourceRequirement, ...]: ...prepare_operation
method
def prepare_operation(operation: Operation) -> PreparedFusion: ...execute
method
def execute(invocation: OperationInvocation, inputs: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], /, *, in_place: bool) -> tuple[torch.Tensor, ...]: ...TritonRnsImplementation
class View source
TritonRnsImplementation(name: str = 'triton-rns-pointwise', operation_types: tuple[type[Operation], ...] = ARITHMETIC_OPS, supports_in_place: bool = False, plans: dict[tuple[object, ...], PointwisePlan] = field(default_factory=dict))Execute individual modular arithmetic operations using the expression generator.
Inputs use the native lazy interval [0,2q); Montgomery products preserve the native R32 canonical and R62 lazy representatives. Selection requires CUDA.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'triton-rns-pointwise' |
operation_types | tuple[type[Operation], ...] | ARITHMETIC_OPS |
supports_in_place | bool | False |
plans | dict[tuple[object, ...], PointwisePlan] | field(default_factory=dict) |
resource_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, ...]: ...