fhelium/ntt_tables.h
#include <fhelium/ntt_tables.h> · namespace fhelium::ntt
Construction of negacyclic NTT roots, twiddle tables, and schedules for the transforms in fhelium/ntt.h.
For a modulus negacyclic_root, and dtype, with one row per modulus in the order of moduli; convert them to Montgomery form with the rns_params of the same moduli before use. The functions compute on the host and return new CPU Tensors.
| Function | Devices | Summary |
|---|---|---|
negacyclic_root | Any device | Returns |
compact_twiddles | Any device | Returns the bit-reversed powers of |
power_of_two_radix_twiddles | Any device | Returns the tables of the fixed power-of-two radix transform with radix log_n. |
indexed_radix2_plan | Any device | Returns the schedules and stage twiddles of the indexed radix-2 transform. |
subring_indexed_radix2_plan | Any device | Returns the forward indexed radix-2 plan of the subring transform of length |
galois_indices | Any device | Returns the int32 gather indices of shape [N] that apply the Galois automorphism indices[j]. |
prepare_tables | Any device | Forward and inverse NTT schedule operands of the rows of parameters. |
negacyclic_root
function View source
int64_t fhelium::ntt::negacyclic_root(
int64_t modulus,
int64_t log_n);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_ntt_ops.negacyclic_root
fhelium_ntt_ops::negacyclic_root(int modulus, int log_n) -> intReturns
compact_twiddles
function View source
std::tuple<at::Tensor, at::Tensor> fhelium::ntt::compact_twiddles(
at::IntArrayRef moduli,
int64_t log_n,
at::ScalarType dtype,
bool shoup32 = false);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_ntt_ops.compact_twiddles
fhelium_ntt_ops::compact_twiddles(int[] moduli, int log_n, ScalarType dtype, bool shoup32=False) -> (Tensor, Tensor)Returns the bit-reversed powers of
Column [modulus, N]. When shoup32 is true, dtype is int32, every [modulus, N, 2] holding the pair
power_of_two_radix_twiddles
function View source
std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor> fhelium::ntt::power_of_two_radix_twiddles(
at::IntArrayRef moduli,
int64_t log_n,
int64_t radix,
at::ScalarType dtype);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_ntt_ops.power_of_two_radix_twiddles
fhelium_ntt_ops::power_of_two_radix_twiddles(int[] moduli, int log_n, int radix, ScalarType dtype) -> (Tensor, Tensor, Tensor, Tensor)Returns the tables of the fixed power-of-two radix transform with radix log_n.
Each digit of the transform is a twisted cyclic [modulus, N - 1]: for every digit group they hold [modulus, r] hold the powers
indexed_radix2_plan
function View source
std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor> fhelium::ntt::indexed_radix2_plan(
at::IntArrayRef moduli,
int64_t log_n,
at::ScalarType dtype);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_ntt_ops.indexed_radix2_plan
fhelium_ntt_ops::indexed_radix2_plan(int[] moduli, int log_n, ScalarType dtype) -> (Tensor, Tensor, Tensor, Tensor)Returns the schedules and stage twiddles of the indexed radix-2 transform.
The forward transform is decimation in frequency: stage [2, log_n, N/2]: even then odd positions), the forward twiddles (shape [modulus, log_n, N/2]), the inverse indices, and the inverse twiddles; twiddles are gathered from the compact_twiddles tables.
subring_indexed_radix2_plan
function View source
std::tuple<at::Tensor, at::Tensor, at::Tensor> fhelium::ntt::subring_indexed_radix2_plan(
at::IntArrayRef moduli,
int64_t log_n,
int64_t log_extent,
at::ScalarType dtype);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_ntt_ops.subring_indexed_radix2_plan
fhelium_ntt_ops::subring_indexed_radix2_plan(int[] moduli, int log_n, int log_extent, ScalarType dtype) -> (Tensor, Tensor, Tensor)Returns the forward indexed radix-2 plan of the subring transform of length
The results are the even and odd indices (int32, shape [log_extent, U/2]) and the stage twiddles (shape [modulus, log_extent, U/2]), with the schedule of indexed_radix2_plan for length
galois_indices
function View source
at::Tensor fhelium::ntt::galois_indices(
int64_t log_n,
int64_t galois_element);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_ntt_ops.galois_indices
fhelium_ntt_ops::galois_indices(int log_n, int galois_element) -> TensorReturns the int32 gather indices of shape [N] that apply the Galois automorphism indices[j].
prepare_tables
function View source
std::tuple<std::vector<at::Tensor>, std::vector<at::Tensor>> fhelium::ntt::prepare_tables(
const at::Tensor& parameters,
c10::IntArrayRef moduli,
int64_t log_n,
std::string_view ntt_backend);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_ntt_ops.prepare_tables
fhelium_ntt_ops::prepare_tables(Tensor parameters, int[] moduli, int log_n, str ntt_backend) -> (Tensor[], Tensor[])Forward and inverse NTT schedule operands of the rows of parameters.
parameters is the RNS parameter table of the rows, moduli their primes, and log_n is ntt_backend in slot order (NttTables::schedule) for the forward and the inverse transform, on the device of parameters.