fhelium/ckks.h
#include <fhelium/ckks.h> · namespace fhelium::ckks
CKKS ciphertext arithmetic on RNS residue Tensors: ciphertext products, plaintext addition, Galois automorphisms, and key-switching steps.
A residue operand has shape [*batch, limb, index], where limb rns_params (fhelium/rns_parameters.h) and the final axis holds *batch as one axis without copying; the only broadcast is a plaintext batch extent of one. All Tensors of one call share one integral dtype and one device. Each function states the domain (coefficient or NTT) and representation (standard or Montgomery) it consumes and produces;
Functions without a trailing underscore allocate their result. A trailing underscore marks a function that mutates its first Tensor argument, or both accumulators, in place. Tables and parameters are read-only.
| Function | Devices | Summary |
|---|---|---|
multiply_two_component_ntt_montgomery | Any device | Multiplies two two-component ciphertexts without relinearization. |
multiply_two_component_ntt_montgomery_out | CPU, CUDA, HIP | Out form of multiply_two_component_ntt_montgomery. out has shape [3, *batch, limb, N] with the operand dtype and device and is disjoint from both operands. |
add_prepared_plaintext_component | Any device | Adds a prepared plaintext to one ciphertext component. |
add_prepared_plaintext_component_ | Any device | In-place form of add_prepared_plaintext_component; the sum replaces ciphertext_component. |
add_prepared_plaintext_component_out | CPU, CUDA, HIP | Out form of add_prepared_plaintext_component. out has the shape, dtype and device of ciphertext_component, is that component or disjoint from it, and is disjoint from the plaintext operands; the in-place form passes the component as out. The other plaintext additions follow the same output requirements. |
add_cyclic_compressed_plaintext_component | Any device | Adds a plaintext whose coefficients repeat cyclically. |
add_cyclic_compressed_plaintext_component_ | Any device | In-place form of add_cyclic_compressed_plaintext_component. |
add_cyclic_compressed_plaintext_component_out | CPU, CUDA, HIP | Out form of add_cyclic_compressed_plaintext_component. |
add_contiguous_compressed_plaintext_component | Any device | Adds a plaintext whose coefficients repeat in contiguous runs. |
add_contiguous_compressed_plaintext_component_ | Any device | In-place form of add_contiguous_compressed_plaintext_component. |
add_contiguous_compressed_plaintext_component_out | CPU, CUDA, HIP | Out form of add_contiguous_compressed_plaintext_component. |
add_strided_plaintext_component | Any device | Adds a plaintext given on a coefficient stride, with one value per limb at the remaining coefficients. |
add_strided_plaintext_component_ | Any device | In-place form of add_strided_plaintext_component. |
add_strided_plaintext_component_out | CPU, CUDA, HIP | Out form of add_strided_plaintext_component. |
apply_coefficient_galois_automorphism | Any device | Applies a Galois automorphism |
apply_coefficient_galois_automorphism_out | CPU, CUDA, HIP | Output form of apply_coefficient_galois_automorphism; out has the shape, dtype and device of residues and does not overlap it. |
apply_ntt_galois_automorphism | Any device | Applies a Galois automorphism to NTT-domain residues by a permutation. |
apply_ntt_galois_automorphism_out | CPU, CUDA, HIP | Output form of apply_ntt_galois_automorphism; out has the shape, dtype and device of residues_ntt and does not overlap it. |
add_ntt_galois_automorphism_ | CPU, CUDA, HIP | Adds a Galois automorphism of NTT-domain residues to target, in place. |
keyswitch_moddown_qp_to_q | Any device | Divides a QP-basis value by |
keyswitch_moddown_qp_to_q_out | CPU, CUDA, HIP | Output form of keyswitch_moddown_qp_to_q; out has the shape, dtype and device of q_residues and overlaps neither residue input. GPU backends write the mixed-radix digits of the P rows to p_scratch, which has the shape, dtype and device of p_residues and may be p_residues itself; without it they allocate the digits per call. |
keyswitch_accumulate_digit_products_ | CPU, CUDA, HIP | Accumulates the product of one extended digit with one key-switching-key digit. |
keyswitch_accumulate_products_ | CUDA, HIP | Writes the key-switching products of one set of extended digits for each of several keys. |
multiply_two_component_ntt_montgomery
function View source
at::Tensor fhelium::ckks::multiply_two_component_ntt_montgomery(
const at::Tensor& lhs_components,
const at::Tensor& rhs_components,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.multiply_two_component_ntt_montgomery
fhelium_ckks_ops::multiply_two_component_ntt_montgomery(Tensor lhs_components, Tensor rhs_components, Tensor rns_params) -> TensorMultiplies two two-component ciphertexts without relinearization.
lhs_components and rhs_components have shape [2, *batch, limb, N] with NTT-domain Montgomery residues. The result has shape [3, *batch, limb, N] with
multiply_two_component_ntt_montgomery_out
function View source
void fhelium::ckks::multiply_two_component_ntt_montgomery_out(
const at::Tensor& lhs_components,
const at::Tensor& rhs_components,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.multiply_two_component_ntt_montgomery_out
fhelium_ckks_ops::multiply_two_component_ntt_montgomery_out(Tensor lhs_components, Tensor rhs_components, Tensor rns_params, Tensor(a!) out) -> ()Out form of multiply_two_component_ntt_montgomery. out has shape [3, *batch, limb, N] with the operand dtype and device and is disjoint from both operands.
add_prepared_plaintext_component
function View source
at::Tensor fhelium::ckks::add_prepared_plaintext_component(
const at::Tensor& ciphertext_component,
const at::Tensor& prepared_plaintext,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_prepared_plaintext_component
fhelium_ckks_ops::add_prepared_plaintext_component(Tensor ciphertext_component, Tensor prepared_plaintext, Tensor rns_params) -> TensorAdds a prepared plaintext to one ciphertext component.
ciphertext_component holds coefficient-domain standard residues prepared_plaintext holds coefficient-domain Montgomery residues
add_prepared_plaintext_component_
function View source
void fhelium::ckks::add_prepared_plaintext_component_(
at::Tensor& ciphertext_component,
const at::Tensor& prepared_plaintext,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_prepared_plaintext_component_
fhelium_ckks_ops::add_prepared_plaintext_component_(Tensor(a!) ciphertext_component, Tensor prepared_plaintext, Tensor rns_params) -> ()In-place form of add_prepared_plaintext_component; the sum replaces ciphertext_component.
add_prepared_plaintext_component_out
function View source
void fhelium::ckks::add_prepared_plaintext_component_out(
const at::Tensor& ciphertext_component,
const at::Tensor& prepared_plaintext,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.add_prepared_plaintext_component_out
fhelium_ckks_ops::add_prepared_plaintext_component_out(Tensor ciphertext_component, Tensor prepared_plaintext, Tensor rns_params, Tensor(a!) out) -> ()Out form of add_prepared_plaintext_component. out has the shape, dtype and device of ciphertext_component, is that component or disjoint from it, and is disjoint from the plaintext operands; the in-place form passes the component as out. The other plaintext additions follow the same output requirements.
add_cyclic_compressed_plaintext_component
function View source
at::Tensor fhelium::ckks::add_cyclic_compressed_plaintext_component(
const at::Tensor& ciphertext_component,
const at::Tensor& compressed_plaintext,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_cyclic_compressed_plaintext_component
fhelium_ckks_ops::add_cyclic_compressed_plaintext_component(Tensor ciphertext_component, Tensor compressed_plaintext, Tensor rns_params) -> TensorAdds a plaintext whose coefficients repeat cyclically.
compressed_plaintext has final extent add_prepared_plaintext_component.
add_cyclic_compressed_plaintext_component_
function View source
void fhelium::ckks::add_cyclic_compressed_plaintext_component_(
at::Tensor& ciphertext_component,
const at::Tensor& compressed_plaintext,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_cyclic_compressed_plaintext_component_
fhelium_ckks_ops::add_cyclic_compressed_plaintext_component_(Tensor(a!) ciphertext_component, Tensor compressed_plaintext, Tensor rns_params) -> ()In-place form of add_cyclic_compressed_plaintext_component.
add_cyclic_compressed_plaintext_component_out
function View source
void fhelium::ckks::add_cyclic_compressed_plaintext_component_out(
const at::Tensor& ciphertext_component,
const at::Tensor& compressed_plaintext,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.add_cyclic_compressed_plaintext_component_out
fhelium_ckks_ops::add_cyclic_compressed_plaintext_component_out(Tensor ciphertext_component, Tensor compressed_plaintext, Tensor rns_params, Tensor(a!) out) -> ()Out form of add_cyclic_compressed_plaintext_component.
add_contiguous_compressed_plaintext_component
function View source
at::Tensor fhelium::ckks::add_contiguous_compressed_plaintext_component(
const at::Tensor& ciphertext_component,
const at::Tensor& compressed_plaintext,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_contiguous_compressed_plaintext_component
fhelium_ckks_ops::add_contiguous_compressed_plaintext_component(Tensor ciphertext_component, Tensor compressed_plaintext, Tensor rns_params) -> TensorAdds a plaintext whose coefficients repeat in contiguous runs.
compressed_plaintext has final extent add_prepared_plaintext_component.
add_contiguous_compressed_plaintext_component_
function View source
void fhelium::ckks::add_contiguous_compressed_plaintext_component_(
at::Tensor& ciphertext_component,
const at::Tensor& compressed_plaintext,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_contiguous_compressed_plaintext_component_
fhelium_ckks_ops::add_contiguous_compressed_plaintext_component_(Tensor(a!) ciphertext_component, Tensor compressed_plaintext, Tensor rns_params) -> ()In-place form of add_contiguous_compressed_plaintext_component.
add_contiguous_compressed_plaintext_component_out
function View source
void fhelium::ckks::add_contiguous_compressed_plaintext_component_out(
const at::Tensor& ciphertext_component,
const at::Tensor& compressed_plaintext,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.add_contiguous_compressed_plaintext_component_out
fhelium_ckks_ops::add_contiguous_compressed_plaintext_component_out(Tensor ciphertext_component, Tensor compressed_plaintext, Tensor rns_params, Tensor(a!) out) -> ()Out form of add_contiguous_compressed_plaintext_component.
add_strided_plaintext_component
function View source
at::Tensor fhelium::ckks::add_strided_plaintext_component(
const at::Tensor& ciphertext_component,
const at::Tensor& strided_plaintext,
const at::Tensor& implicit_plaintext,
const at::Tensor& rns_params);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_strided_plaintext_component
fhelium_ckks_ops::add_strided_plaintext_component(Tensor ciphertext_component, Tensor strided_plaintext, Tensor implicit_plaintext, Tensor rns_params) -> TensorAdds a plaintext given on a coefficient stride, with one value per limb at the remaining coefficients.
strided_plaintext has final extent implicit_plaintext holds one Montgomery residue per plaintext batch element and limb, as a contiguous Tensor of shape [plaintext_batch, limb] or its flattened vector. Coefficient strided_plaintext when add_prepared_plaintext_component.
add_strided_plaintext_component_
function View source
void fhelium::ckks::add_strided_plaintext_component_(
at::Tensor& ciphertext_component,
const at::Tensor& strided_plaintext,
const at::Tensor& implicit_plaintext,
const at::Tensor& rns_params);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.add_strided_plaintext_component_
fhelium_ckks_ops::add_strided_plaintext_component_(Tensor(a!) ciphertext_component, Tensor strided_plaintext, Tensor implicit_plaintext, Tensor rns_params) -> ()In-place form of add_strided_plaintext_component.
add_strided_plaintext_component_out
function View source
void fhelium::ckks::add_strided_plaintext_component_out(
const at::Tensor& ciphertext_component,
const at::Tensor& strided_plaintext,
const at::Tensor& implicit_plaintext,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
6
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.add_strided_plaintext_component_out
fhelium_ckks_ops::add_strided_plaintext_component_out(Tensor ciphertext_component, Tensor strided_plaintext, Tensor implicit_plaintext, Tensor rns_params, Tensor(a!) out) -> ()Out form of add_strided_plaintext_component.
apply_coefficient_galois_automorphism
function View source
at::Tensor fhelium::ckks::apply_coefficient_galois_automorphism(
const at::Tensor& residues,
const at::Tensor& source_indices,
const at::Tensor& source_sign,
const at::Tensor& twice_modulus);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.apply_coefficient_galois_automorphism
fhelium_ckks_ops::apply_coefficient_galois_automorphism(Tensor residues, Tensor source_indices, Tensor source_sign, Tensor twice_modulus) -> TensorApplies a Galois automorphism
source_indices (int32) and source_sign (int8, source_indices[k] and source_sign[k]. twice_modulus holds residues.
apply_coefficient_galois_automorphism_out
function View source
void fhelium::ckks::apply_coefficient_galois_automorphism_out(
const at::Tensor& residues,
const at::Tensor& source_indices,
const at::Tensor& source_sign,
const at::Tensor& twice_modulus,
at::Tensor& out);2
3
4
5
6
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.apply_coefficient_galois_automorphism_out
fhelium_ckks_ops::apply_coefficient_galois_automorphism_out(Tensor residues, Tensor source_indices, Tensor source_sign, Tensor twice_modulus, Tensor(a!) out) -> ()Output form of apply_coefficient_galois_automorphism; out has the shape, dtype and device of residues and does not overlap it.
apply_ntt_galois_automorphism
function View source
at::Tensor fhelium::ckks::apply_ntt_galois_automorphism(
const at::Tensor& residues_ntt,
const at::Tensor& source_indices);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.apply_ntt_galois_automorphism
fhelium_ckks_ops::apply_ntt_galois_automorphism(Tensor residues_ntt, Tensor source_indices) -> TensorApplies a Galois automorphism to NTT-domain residues by a permutation.
Output evaluation source_indices[k] for the int32 permutation vector source_indices of length
apply_ntt_galois_automorphism_out
function View source
void fhelium::ckks::apply_ntt_galois_automorphism_out(
const at::Tensor& residues_ntt,
const at::Tensor& source_indices,
at::Tensor& out);2
3
4
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.apply_ntt_galois_automorphism_out
fhelium_ckks_ops::apply_ntt_galois_automorphism_out(Tensor residues_ntt, Tensor source_indices, Tensor(a!) out) -> ()Output form of apply_ntt_galois_automorphism; out has the shape, dtype and device of residues_ntt and does not overlap it.
add_ntt_galois_automorphism_
function View source
void fhelium::ckks::add_ntt_galois_automorphism_(
at::Tensor& target,
const at::Tensor& residues_ntt,
const at::Tensor& source_indices,
const at::Tensor& rns_params);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.add_ntt_galois_automorphism_
fhelium_ckks_ops::add_ntt_galois_automorphism_(Tensor(a!) target, Tensor residues_ntt, Tensor source_indices, Tensor rns_params) -> ()Adds a Galois automorphism of NTT-domain residues to target, in place.
With apply_ntt_galois_automorphism, each target evaluation target and residues_ntt share shape, dtype and device and do not alias; rns_params describes their rows.
keyswitch_moddown_qp_to_q
function View source
at::Tensor fhelium::ckks::keyswitch_moddown_qp_to_q(
const at::Tensor& q_residues,
const at::Tensor& p_residues,
const at::Tensor& moddown_p_drop_inverses_montgomery,
const at::Tensor& rns_params,
const std::optional<at::Tensor>& moddown_half = std::nullopt,
c10::string_view rounding = "nearest");2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_ckks_ops.keyswitch_moddown_qp_to_q
fhelium_ckks_ops::keyswitch_moddown_qp_to_q(Tensor q_residues, Tensor p_residues, Tensor moddown_p_drop_inverses_montgomery, Tensor rns_params, Tensor? moddown_half=None, str rounding=\"nearest\") -> TensorDivides a QP-basis value by
q_residues ([*batch, Q, N]) and p_residues ([*batch, P, N]) hold coefficient-domain standard residues in rns_params describe the Q primes followed by the P primes. With rounding = "nearest" and rounding = "floor", as newly allocated coefficient-domain standard residues in moddown_p_drop_inverses_montgomery holds moddown_half, the residues of
keyswitch_moddown_qp_to_q_out
function View source
void fhelium::ckks::keyswitch_moddown_qp_to_q_out(
const at::Tensor& q_residues,
const at::Tensor& p_residues,
const at::Tensor& moddown_p_drop_inverses_montgomery,
const at::Tensor& rns_params,
const std::optional<at::Tensor>& moddown_half,
c10::string_view rounding,
at::Tensor& out,
const std::optional<at::Tensor>& p_scratch = std::nullopt);2
3
4
5
6
7
8
9
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.keyswitch_moddown_qp_to_q_out
fhelium_ckks_ops::keyswitch_moddown_qp_to_q_out(Tensor q_residues, Tensor p_residues, Tensor moddown_p_drop_inverses_montgomery, Tensor rns_params, Tensor? moddown_half, str rounding, Tensor(a!) out, Tensor(b!)? p_scratch=None) -> ()Output form of keyswitch_moddown_qp_to_q; out has the shape, dtype and device of q_residues and overlaps neither residue input. GPU backends write the mixed-radix digits of the P rows to p_scratch, which has the shape, dtype and device of p_residues and may be p_residues itself; without it they allocate the digits per call.
keyswitch_accumulate_digit_products_
function View source
void fhelium::ckks::keyswitch_accumulate_digit_products_(
at::Tensor& accumulator0_qp,
at::Tensor& accumulator1_qp,
const at::Tensor& extended_digit_ntt_qp,
const at::Tensor& key_switch_key_digit,
const at::Tensor& rns_params,
int64_t key_digit_row_start,
int64_t key_p_row_start = -1,
const std::optional<at::Tensor>& source_indices = std::nullopt,
const std::optional<at::Tensor>& key_seed = std::nullopt,
int64_t key_rounds = 0);2
3
4
5
6
7
8
9
10
11
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.keyswitch_accumulate_digit_products_
fhelium_ckks_ops::keyswitch_accumulate_digit_products_(Tensor(a!) accumulator0_qp, Tensor(b!) accumulator1_qp, Tensor extended_digit_ntt_qp, Tensor key_switch_key_digit, Tensor rns_params, int key_digit_row_start, int key_p_row_start=-1, Tensor? source_indices=None, Tensor? key_seed=None, int key_rounds=0) -> ()Accumulates the product of one extended digit with one key-switching-key digit.
extended_digit_ntt_qp and both accumulators have shape [*batch, rows, N] with NTT-domain Montgomery residues. key_switch_key_digit has shape [2, key_rows, N]. With key_digit_row_start + r and auxiliary row key_p_row_start + r - q, where the auxiliary rows are the trailing key_rows - key_p_row_start key rows. A negative key_p_row_start reads every digit row from key_digit_row_start + r. For each component source_indices when supplied and the identity otherwise. Supplying source_indices applies an NTT-domain Galois automorphism to the digit within the same pass. A seeded key digit has shape [1, key_rows, N] holding key_seed is its int64 seed row [6]; fhelium::random::expand_seeded_key at stored row key_rounds, generated within the product.
keyswitch_accumulate_products_
function View source
void fhelium::ckks::keyswitch_accumulate_products_(
at::TensorList accumulators0_qp,
at::TensorList accumulators1_qp,
at::TensorList extended_digits_ntt_qp,
at::TensorList key_switch_keys,
const at::Tensor& rns_params,
int64_t key_digit_row_start,
int64_t key_p_row_start = -1,
at::TensorList source_indices = {},
at::TensorList key_seeds = {},
int64_t key_rounds = 0);2
3
4
5
6
7
8
9
10
11
Devices: CUDA, HIP
Torch operator: torch.ops.fhelium_ckks_ops.keyswitch_accumulate_products_
fhelium_ckks_ops::keyswitch_accumulate_products_(Tensor(a!)[] accumulators0_qp, Tensor(b!)[] accumulators1_qp, Tensor[] extended_digits_ntt_qp, Tensor[] key_switch_keys, Tensor rns_params, int key_digit_row_start, int key_p_row_start, Tensor[] source_indices, Tensor[] key_seeds, int key_rounds) -> ()Writes the key-switching products of one set of extended digits for each of several keys.
extended_digits_ntt_qp lists between 1 and 16 digits key_switch_keys has shape [digit, 2, key_rows, N]; all entries share one layout. For each rotation accumulators0_qp[r] and accumulators1_qp[r] with keyswitch_accumulate_digit_products_ calls for every digit source_indices uses [digit, 1, key_rows, N], and entry key_seeds holds the int64 seed rows [digit, 6] of key keyswitch_accumulate_digit_products_. An empty key_seeds reads dense keys.