fhelium.engine.ntt
Engine-owned NTT plans, parameter tables, and execution backends.
CompactPowerOfTwoRadixNttBackend
class View source
CompactPowerOfTwoRadixNttBackend(*, policy: CompactFixedRadixPolicy, ntt_tables: CompactPowerOfTwoRadixTables, rns_params: torch.Tensor)Execute radix-4/8/16 digits with radix-specific CUDA butterflies.
forward_montgomery_
method
def forward_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...forward_to_montgomery_
method
def forward_to_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...forward_to_montgomery
method
def forward_to_montgomery(operand: torch.Tensor, parameter_row_start: int) -> torch.Tensor: ...inverse_montgomery_
method
def inverse_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_standard_lazy_
method
def inverse_to_standard_lazy_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_standard_
method
def inverse_to_standard_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_centered_
method
def inverse_to_centered_(operand: torch.Tensor, parameter_row_start: int) -> None: ...CompactPowerOfTwoRadixTables
class View source
CompactPowerOfTwoRadixTables(forward_outer_twiddles: torch.Tensor, inverse_outer_twiddles: torch.Tensor, forward_radix_root_powers: torch.Tensor, inverse_radix_root_powers: torch.Tensor)Packed outer twists and roots for strict fixed-radix digits.
Outer shapes are [limb, N - 1] and root shapes are [limb, radix] in canonical QP row order. Conversion mutates each integral table from standard to Montgomery residues in place.
Attributes
| Name | Type | Default/value |
|---|---|---|
forward_outer_twiddles | torch.Tensor | |
inverse_outer_twiddles | torch.Tensor | |
forward_radix_root_powers | torch.Tensor | |
inverse_radix_root_powers | torch.Tensor |
convert_twiddles_to_montgomery_
method
def convert_twiddles_to_montgomery_(rns_params: torch.Tensor) -> None: ...CompactRadix2NttBackend
class View source
CompactRadix2NttBackend(*, policy: CompactRadix2Policy, ntt_tables: CompactRadix2Tables, rns_params: torch.Tensor)Compute butterfly indices in CUDA from canonical compact twiddles.
forward_montgomery_
method
def forward_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...forward_to_montgomery_
method
def forward_to_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...forward_to_montgomery
method
def forward_to_montgomery(operand: torch.Tensor, parameter_row_start: int) -> torch.Tensor: ...inverse_montgomery_
method
def inverse_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_standard_lazy_
method
def inverse_to_standard_lazy_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_standard_
method
def inverse_to_standard_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_centered_
method
def inverse_to_centered_(operand: torch.Tensor, parameter_row_start: int) -> None: ...CompactRadix2Tables
class View source
CompactRadix2Tables(forward_twiddles: torch.Tensor, inverse_twiddles: torch.Tensor)Canonical [limb, N] twiddle rows for production kernels.
Rows align exactly with canonical QP parameter columns. Conversion mutates each integral table from standard to Montgomery residues in place.
Attributes
| Name | Type | Default/value |
|---|---|---|
forward_twiddles | torch.Tensor | |
inverse_twiddles | torch.Tensor |
convert_twiddles_to_montgomery_
method
def convert_twiddles_to_montgomery_(rns_params: torch.Tensor) -> None: ...IndexedRadix2NttBackend
class View source
IndexedRadix2NttBackend(*, policy: IndexedRadix2Policy, ntt_tables: IndexedRadix2Tables, rns_params: torch.Tensor)Execute the indexed radix-2 schedule on CPU or CUDA.
forward_montgomery_
method
def forward_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...forward_to_montgomery_
method
def forward_to_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...forward_to_montgomery
method
def forward_to_montgomery(operand: torch.Tensor, parameter_row_start: int) -> torch.Tensor: ...inverse_montgomery_
method
def inverse_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_standard_lazy_
method
def inverse_to_standard_lazy_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_standard_
method
def inverse_to_standard_(operand: torch.Tensor, parameter_row_start: int) -> None: ...inverse_to_centered_
method
def inverse_to_centered_(operand: torch.Tensor, parameter_row_start: int) -> None: ...IndexedRadix2Tables
class View source
IndexedRadix2Tables(forward_even_indices: torch.Tensor, forward_odd_indices: torch.Tensor, forward_twiddles: torch.Tensor, inverse_even_indices: torch.Tensor, inverse_odd_indices: torch.Tensor, inverse_twiddles: torch.Tensor)Schedules and stage-expanded twiddles for indexed execution.
Index tensors are torch.int32 on the backend device. Twiddle tensors are integral [limb, stage, butterfly] rows aligned with canonical QP parameter columns; they begin in standard form and are converted in place to Montgomery form without changing shape, dtype, device, or storage.
Attributes
| Name | Type | Default/value |
|---|---|---|
forward_even_indices | torch.Tensor | |
forward_odd_indices | torch.Tensor | |
forward_twiddles | torch.Tensor | |
inverse_even_indices | torch.Tensor | |
inverse_odd_indices | torch.Tensor | |
inverse_twiddles | torch.Tensor |
convert_twiddles_to_montgomery_
method
def convert_twiddles_to_montgomery_(rns_params: torch.Tensor) -> None: ...NttBackend
class View source
NttBackend()Bases: Protocol
Representation-explicit NTT operations consumed by RnsRuntime.
Method names state both the input and output representation. forward consumes coefficient-domain data and produces NTT-domain data; inverse performs the reverse transition. montgomery and standard identify the residue representation. A trailing underscore means that the operand is mutated in place.
parameter_row_start is the zero-based start of the operand's prime-row interval in the backend's complete canonical QP tables. Implementations use it to select the exact per-prime twiddles, roots, and RNS parameters; they must not infer prime identity from operand.size(-2).
The protocol intentionally contains no radix, grouping, or table-layout fields. Those are construction-time properties of a concrete backend, not semantic differences visible to RnsRuntime.
Every operand is a dense integral tensor on one execution device [*batch, limb, coefficient_or_ntt_index] with final extent j is aligned with canonical parameter row parameter_row_start + j and therefore with that row's exact prime
Let logN-bit reversal. The stored NTT order is
The inverse implements the corresponding normalized inverse with inverse_to_standard_ (canonical inverse_to_centered_ (centered representatives). A trailing underscore preserves and mutates operand storage; the functional forward allocates an output that does not alias any input.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str |
forward_montgomery_
method
def forward_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...Map coefficient/Montgomery to NTT/Montgomery in place.
forward_to_montgomery_
method
def forward_to_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...Map coefficient/standard to NTT/Montgomery in place.
forward_to_montgomery
method
def forward_to_montgomery(operand: torch.Tensor, parameter_row_start: int) -> torch.Tensor: ...Return NTT/Montgomery output without mutating or aliasing input.
inverse_montgomery_
method
def inverse_montgomery_(operand: torch.Tensor, parameter_row_start: int) -> None: ...Map NTT/Montgomery to coefficient/Montgomery in place.
inverse_to_standard_lazy_
method
def inverse_to_standard_lazy_(operand: torch.Tensor, parameter_row_start: int) -> None: ...Map in place to lazy coefficient/standard residues in
inverse_to_standard_
method
def inverse_to_standard_(operand: torch.Tensor, parameter_row_start: int) -> None: ...Map in place to coefficient/standard residues in
inverse_to_centered_
method
def inverse_to_centered_(operand: torch.Tensor, parameter_row_start: int) -> None: ...Map in place to centered coefficient/standard residues.
NttTables
data View source
NttTables = IndexedRadix2Tables | CompactRadix2Tables | CompactPowerOfTwoRadixTablescreate_ntt_backend
function View source
def create_ntt_backend(policy: NttBackendPolicy, *, ntt_tables: NttTables, rns_params: torch.Tensor) -> NttBackend: ...Construct an executor only from a matching policy/table pair.
prepare_ntt_tables
function View source
def prepare_ntt_tables(policy: NttBackendPolicy, ckks_config: CkksConfig, *, materialize_parameter_rows: MaterializeParameterRows, device: torch.device) -> NttTables: ...Build a plan and return separately allocated backend table tensors.
Prime rows follow the config's canonical level-zero QP order exactly. Returned tensors use ckks_config.torch_dtype on device and remain in standard representation until RnsRuntime converts them in place.