fhelium.backend.rns.crt
CRT lifts defined by supplied coefficient and modular-reduction Tensors.
CRT_OPERANDS
constant View source
CRT_OPERANDS = ('source_parameters', 'target_parameters', 'matrix', 'target_reciprocals', 'source_normalizers', 'source_reciprocals')crt_basis_extension_tables
function View source
def crt_basis_extension_tables(context: RnsContext, source_prime_ids: tuple[int, ...], target_prime_ids: tuple[int, ...], *, method: Literal['raw', 'normalized']) -> dict[str, torch.Tensor]: ...Construct the selected lift's matrix in target Montgomery form.
Let D=product(q_i), D_i=D/q_i and u_i=D_i^{-1} mod q_i. Raw lift evaluates sum(a_i D_i u_i); normalized lift evaluates sum((a_i u_i mod q_i) D_i). Both reduce to a_i on source prime rows. Target matrix entries include one factor R, so the output is in Montgomery form. The two lifts need not choose the canonical integer representative, and their evaluation-key error differs.
crt_basis_extend
function View source
def crt_basis_extend(source: torch.Tensor, tensors: Mapping[str, torch.Tensor], *, out: torch.Tensor | None=None) -> torch.Tensor: ...Evaluate the supplied CRT matrix, optionally normalizing source rows.
Source is coefficient/standard [batch, source row, coefficient], with residues in [0, 2q_i); each row is canonicalized before evaluation. Matrix entry (i,j) is a canonical Montgomery coefficient in [0, p_j). Nonempty source_normalizers in [0, q_i) apply a_i*u_i mod q_i before the matrix. Reciprocals are floor(264 / modulus) for their corresponding parameter rows. CUDA int32 execution requires primes below 230. Output is canonical Montgomery [*batch, target row, coefficient]. Inputs and numerical tables remain read-only. An out buffer has the same shape, dtype and device and must be disjoint from every read operand. The portable route requires separate storage; the CUDA route also permits proven disjoint views within shared storage.
NativeCrtBasisExtensionImplementation
class View source
NativeCrtBasisExtensionImplementation(name: str = 'native-crt-basis-extension', operation_types: tuple[type[Operation], ...] = (rns.CrtBasisExtendOp,), supports_in_place: bool = False)Execute a raw or source-normalized CRT matrix over live Tensor operands.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'native-crt-basis-extension' |
operation_types | tuple[type[Operation], ...] | (rns.CrtBasisExtendOp,) |
supports_in_place | bool | False |
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, ...]: ...