fhelium.backend.triton
Triton code generation for component-aware modular arithmetic and transforms.
Implementations are selected through Backend registries. Importing this package neither imports Triton nor changes native defaults. Generated arithmetic uses integer Montgomery reduction and preserves the native lazy residue ranges.
TritonFusionImplementation
class View source
TritonFusionImplementation(name: str = 'triton-rns-fused', include_ntt: bool = False, 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 compact radix-2 transform anchors; implementation names do not determine support. Match checks consume known Program facts, while missing layout/resource facts are checked when binding execution. Device compilation is lazy.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'triton-rns-fused' |
include_ntt | bool | False |
operation_types | tuple[type[Operation], ...] | (fusion.FusedOp,) |
supports_in_place | bool | False |
select_ntt_schedule
method
def select_ntt_schedule(**facts): ...Offer compact schedules when this region implementation admits NTT.
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, ...]: ...