fhelium/operation_tables.h
#include <fhelium/operation_tables.h> · namespace detail_tables
Prepared numerical tables of the whole NTT, RNS, and CKKS operations.
Each operation family reads its tables from one struct of Tensor fields. A field that the selected method does not read stays undefined. The function visit_tables enumerates the fields of a struct in a fixed slot order together with their slot names; a Torch operator receives the same struct as one Tensor?[] tables argument in that order, with None for undefined fields. Repeated groups, such as the digits of a key switch, follow the fixed fields, so their count follows from the list length.
fhelium::ckks::table_slot_names lists the slot names of a family. The builders in this header produce the tables from the prime moduli and the RNS parameter table; builders whose result contains NTT tables select those rows from the complete tables of prepare_ntt_tables.
TableSlotName
struct View source
Name of one table slot: the names of the enclosing groups followed by text, an optional decimal number, and suffix. Visitors build names on the stack; str() materializes one only when a caller needs it.
| Member | Description |
|---|
NttTables
struct View source
Forward or inverse NTT tables of one ordered prime-row set.
parameters holds the RNS parameter columns of the rows. schedule holds the policy operands: radix2_indexed uses twiddles and the even and odd butterfly indices; radix2_compact and radix2_compact_shoup32 use twiddles; radix4/8/16_compact use outer twiddles and root powers. The slots are named <basis>_<direction>_0 (parameters) through _3.
| Member | Description |
|---|
CrtTables
struct View source
CRT basis-extension or centered-quotient matrix and its operands; see fhelium::rns::crt_basis_extend. An empty source_normalizers selects the raw lift.
| Member | Description |
|---|
DigitTables
struct View source
Lift of one hybrid key-switch digit to the QP rows. The exact method reads the Garner tables (normalizers, propagation, and the four Montgomery reduction rows for digits of several primes) and extension; the CRT methods read crt. Slots are prefixed digit<i>_.
| Member | Description |
|---|
JointRescaleTables
struct View source
Quotient of QP rows by D·P that a relinearization with rescale fuses into its ModDown. Slots are prefixed joint_; remaining_forward serves NTT output and remaining_inverse coefficient output.
| Member | Description |
|---|
KeySwitchTables
struct View source
Tables of the hybrid key-switching family: ModDown, joint rescale, key switching, rotations, and rotation sums.
The Q rows are the active rows of the operand and the P rows the auxiliary rows of the key. moddown_inverses, p_inverse, moddown_half and moddown_crt divide QP rows by P; joint replaces them for a relinearization or rotation sum with rescale. The sum_ fields complete a rotation sum without rescale by dividing its QP rows by P.
| Member | Description |
|---|
RescaleTables
struct View source
Rational rescale from basis B to B'; see fhelium::rns::rational_rescale.
| Member | Description |
|---|
BasisExtensionTables
struct View source
Centered extension from a source basis to target rows; see fhelium::rns::centered_basis_extend.
| Member | Description |
|---|
TrailingQuotientTables
struct View source
Rounded quotient by trailing rows; see fhelium::rns::rounded_trailing_quotient.
| Member | Description |
|---|
EncapsulationTables
struct View source
Low key switch, centered extension, and guard-prime return quotient of fhelium::ckks::encapsulated_modulus_raise. The return rows are [guard, Q, P_return]; quotient rows are ordered [Q, guard, P_return].
| Member | Description |
|---|
RingTables
struct View source
NTT tables of one basis for encryption, decryption, and key generation. source_product holds the hybrid key factor of fhelium::ckks::create_key_switch_key.
| Member | Description |
|---|
DecryptionTables
struct View source
Phase tables and the centered Q reconstruction of decryption.
| Member | Description |
|---|
SecretConversionTables
struct View source
Re-expression of a secret key in another basis.
| Member | Description |
|---|
GaloisTables
struct View source
Gathers of the Galois automorphism X -> X^g for one rotation step: NTT-domain source indices and coefficient-domain indices with signs. Operations receive them as ordinary operands rather than caching device copies, because a first-use host-to-device copy cannot run during CUDA Graph capture.
| Member | Description |
|---|
RnsBasis
struct View source
Configured primes of one RNS context and their parameter table.
moduli lists every prime in context order; parameters is fhelium::rns::parameter_table(moduli, ...) on the execution device. Its dtype is the residue dtype of every built table.
| Member | Description |
|---|
NttContextTables
struct View source
Complete NTT tables of every prime of an RnsBasis, in the NttTables operand order of ntt_backend. Twiddles are converted to Montgomery form on the parameter device, except the Shoup32 pairs, which keep their standard roots and quotient words.
| Member | Description |
|---|
KeySwitchTableSpec
struct View source
Rows and method of one key-switch table set.
digits lists (start, stop, key_digit) triples of positions in q_prime_ids. With rescale, drop_prime_ids (a subset of Q) is divided out with P and target_prime_ids orders the result rows.
| Member | Description |
|---|
| Function | Devices | Summary |
|---|---|---|
unflatten_galois_tables | Any device | Returns the Galois tables of each step from slots, three per step. |
select_rns_parameters | Any device | Returns the parameter columns of prime_ids: a view for one increasing interval and a gathered copy otherwise. |
select_ntt_tables | Any device | Returns the NTT tables of prime_ids in one direction, selecting rows of the complete tables. Twiddle rows are contiguous; index schedules are shared by every row set. |
build_key_switch_tables | Any device | Builds the RNS tables of one key-switch configuration: parameters, ModDown or joint-rescale quotient tables, and digit lifts. NTT fields stay undefined; fill_key_switch_ntt_tables selects them. |
fill_key_switch_ntt_tables | Any device | Selects the NTT fields of tables that the configuration reads. |
add_rotation_sum_tables | Any device | Adds the rotation-sum quotient by P without rescaling: sum_p_montgomery holds P in Montgomery form over the Q rows, and sum_quotient_parameters, sum_quotient_inverses and sum_quotient_half divide the QP rows by P. A rotation sum with rescaling reads the joint tables instead. |
build_joint_rescale_tables | Any device | Builds the quotient of R(v + Pa) + H_P + P H_D by P·D for Q rows q, auxiliary rows p, and the dropped Q subset drop_prime_ids. target_prime_ids orders the result rows and defaults (when empty) to the remaining Q rows; its rows outside Q form the restored set R. With normalized_crt conversion the crt_ fields replace the exact P remainder. NTT fields stay undefined. |
build_rescale_tables | Any device | Builds the rational rescale tables from source_prime_ids to target_prime_ids. ntt_input adds the inverse of the dropped product on the target rows; supplying ntt also selects the dropped inverse and target forward NTT tables. |
build_basis_extension_tables | Any device | Builds the centered basis-extension tables between two contexts that share dtype and device. |
build_crt_tables | Any device | Builds the CRT lift of source_prime_ids to target_prime_ids, raw or normalized; see fhelium::rns::crt_basis_extension_tables. |
build_centered_quotient_tables | Any device | Builds the centered CRT quotient of source_prime_ids onto target_prime_ids, further divided by the product of divisor_prime_ids. |
build_encapsulation_tables | Any device | Builds the tables of encapsulated_modulus_raise from Q basis source_q_moduli, low auxiliary primes, and the return basis [guard, Q, P]. q_moduli is the full Q chain; target_prime_ids selects the output rows of basis. |
build_ring_tables | Any device | Builds the NTT tables of prime_ids in both directions; source_product stays undefined. |
build_reconstruction_tables | Any device | Builds the centered Q reconstruction of decryption for prime_ids; the ring fields stay undefined. |
build_decryption_tables | Any device | Builds the ring and reconstruction tables of decryption for prime_ids. |
build_galois_tables | Any device | Builds the Galois gathers of X -> X^galois_element on device. |
unflatten_galois_tables
function View source
std::vector<GaloisTables> detail_tables::unflatten_galois_tables(
const TableSlots& slots);2
Devices: Any device
Returns the Galois tables of each step from slots, three per step.
select_rns_parameters
function View source
at::Tensor detail_tables::select_rns_parameters(
const RnsBasis& basis,
c10::IntArrayRef prime_ids);2
3
Devices: Any device
Returns the parameter columns of prime_ids: a view for one increasing interval and a gathered copy otherwise.
select_ntt_tables
function View source
NttTables detail_tables::select_ntt_tables(
const RnsBasis& basis,
const NttContextTables& tables,
c10::IntArrayRef prime_ids,
bool inverse);2
3
4
5
Devices: Any device
Returns the NTT tables of prime_ids in one direction, selecting rows of the complete tables. Twiddle rows are contiguous; index schedules are shared by every row set.
build_key_switch_tables
function View source
KeySwitchTables detail_tables::build_key_switch_tables(
const RnsBasis& basis,
const KeySwitchTableSpec& spec);2
3
Devices: Any device
Builds the RNS tables of one key-switch configuration: parameters, ModDown or joint-rescale quotient tables, and digit lifts. NTT fields stay undefined; fill_key_switch_ntt_tables selects them.
fill_key_switch_ntt_tables
function View source
void detail_tables::fill_key_switch_ntt_tables(
KeySwitchTables& tables,
const RnsBasis& basis,
const NttContextTables& ntt,
const KeySwitchTableSpec& spec);2
3
4
5
Devices: Any device
Selects the NTT fields of tables that the configuration reads.
add_rotation_sum_tables
function View source
void detail_tables::add_rotation_sum_tables(
KeySwitchTables& tables,
const RnsBasis& basis,
const KeySwitchTableSpec& spec,
std::string_view rounding);2
3
4
5
Devices: Any device
Adds the rotation-sum quotient by P without rescaling: sum_p_montgomery holds P in Montgomery form over the Q rows, and sum_quotient_parameters, sum_quotient_inverses and sum_quotient_half divide the QP rows by P. A rotation sum with rescaling reads the joint tables instead.
build_joint_rescale_tables
function View source
JointRescaleTables detail_tables::build_joint_rescale_tables(
const RnsBasis& basis,
c10::IntArrayRef q_prime_ids,
c10::IntArrayRef p_prime_ids,
c10::IntArrayRef drop_prime_ids,
c10::IntArrayRef target_prime_ids,
std::string_view moddown_rounding,
std::string_view rescale_rounding,
std::string_view basis_conversion);2
3
4
5
6
7
8
9
Devices: Any device
Builds the quotient of R(v + Pa) + H_P + P H_D by P·D for Q rows q, auxiliary rows p, and the dropped Q subset drop_prime_ids. target_prime_ids orders the result rows and defaults (when empty) to the remaining Q rows; its rows outside Q form the restored set R. With normalized_crt conversion the crt_ fields replace the exact P remainder. NTT fields stay undefined.
build_rescale_tables
function View source
RescaleTables detail_tables::build_rescale_tables(
const RnsBasis& basis,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids,
std::string_view rounding,
bool ntt_input,
const NttContextTables* ntt);2
3
4
5
6
7
Devices: Any device
Builds the rational rescale tables from source_prime_ids to target_prime_ids. ntt_input adds the inverse of the dropped product on the target rows; supplying ntt also selects the dropped inverse and target forward NTT tables.
build_basis_extension_tables
function View source
BasisExtensionTables detail_tables::build_basis_extension_tables(
const RnsBasis& source,
const RnsBasis& target,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids);2
3
4
5
Devices: Any device
Builds the centered basis-extension tables between two contexts that share dtype and device.
build_crt_tables
function View source
CrtTables detail_tables::build_crt_tables(
const RnsBasis& basis,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids,
bool normalized);2
3
4
5
Devices: Any device
Builds the CRT lift of source_prime_ids to target_prime_ids, raw or normalized; see fhelium::rns::crt_basis_extension_tables.
build_centered_quotient_tables
function View source
CrtTables detail_tables::build_centered_quotient_tables(
const RnsBasis& basis,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids,
c10::IntArrayRef divisor_prime_ids);2
3
4
5
Devices: Any device
Builds the centered CRT quotient of source_prime_ids onto target_prime_ids, further divided by the product of divisor_prime_ids.
build_encapsulation_tables
function View source
EncapsulationTables detail_tables::build_encapsulation_tables(
const RnsBasis& basis,
std::string_view ntt_backend,
double scale,
c10::IntArrayRef source_q_moduli,
c10::IntArrayRef low_p_moduli,
int64_t return_prime,
c10::IntArrayRef return_p_moduli,
c10::IntArrayRef q_moduli,
c10::IntArrayRef target_prime_ids,
std::string_view rounding);2
3
4
5
6
7
8
9
10
11
Devices: Any device
Builds the tables of encapsulated_modulus_raise from Q basis source_q_moduli, low auxiliary primes, and the return basis [guard, Q, P]. q_moduli is the full Q chain; target_prime_ids selects the output rows of basis.
build_ring_tables
function View source
RingTables detail_tables::build_ring_tables(
const RnsBasis& basis,
const NttContextTables& ntt,
c10::IntArrayRef prime_ids);2
3
4
Devices: Any device
Builds the NTT tables of prime_ids in both directions; source_product stays undefined.
build_reconstruction_tables
function View source
DecryptionTables detail_tables::build_reconstruction_tables(
const RnsBasis& basis,
c10::IntArrayRef prime_ids);2
3
Devices: Any device
Builds the centered Q reconstruction of decryption for prime_ids; the ring fields stay undefined.
build_decryption_tables
function View source
DecryptionTables detail_tables::build_decryption_tables(
const RnsBasis& basis,
const NttContextTables& ntt,
c10::IntArrayRef prime_ids);2
3
4
Devices: Any device
Builds the ring and reconstruction tables of decryption for prime_ids.
build_galois_tables
function View source
GaloisTables detail_tables::build_galois_tables(
int64_t log_n,
int64_t galois_element,
const at::Device& device);2
3
4
Devices: Any device
Builds the Galois gathers of X -> X^galois_element on device.