fhelium/rns_operations.h
#include <fhelium/rns_operations.h> · namespace fhelium::rns
Whole RNS operations over prepared tables: hybrid-digit ModUp, centered basis extension, ModDown by the auxiliary product, joint ModDown and rescale, rounded trailing quotients, and rational rescale.
Each function reads its prepared tables from one struct of fhelium/operation_tables.h and lists the fields it reads. Residue operands have shape [*batch, limb, N]. Parameter tables follow the layout of fhelium/rns_parameters.h. NTT steps use the policy names and schedules of fhelium/ntt_operations.h. digits lists hybrid digits as flattened (start, stop, key_digit) triples, where [start, stop) are source rows. rounding is nearest or floor. Inputs and tables are read-only, and results own their storage unless a function states otherwise. Each operation has an _out form that writes its result into a caller-supplied Tensor with the result's shape, dtype, and device that does not overlap the operands.
| Function | Devices | Summary |
|---|---|---|
hybrid_modup_digit | Any device | Lifts hybrid digit digit_index of coefficient standard residues over the active Q rows to QP Montgomery residues. |
hybrid_modup_digit_out | Any device | Out form of hybrid_modup_digit. |
centered_basis_extend | Any device | Returns the residues of the centered CRT representative of source in the target basis. |
centered_basis_extend_out | Any device | Out form of centered_basis_extend. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least centered_basis_extend_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call. |
centered_basis_extend_workspace_bytes | Any device | Workspace bytes of centered_basis_extend_out for these operands; reads only their sizes, dtypes and devices. |
rounded_trailing_quotient | Any device | Returns drop_count rows of source, after the optional row_order gather, are the divisor rows with product |
rounded_trailing_quotient_out | Any device | Out form of rounded_trailing_quotient. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least rounded_trailing_quotient_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call. |
rounded_trailing_quotient_workspace_bytes | Any device | Workspace bytes of rounded_trailing_quotient_out for these operands; reads only their sizes, dtypes and devices. |
moddown_qp_to_q | Any device | Returns p_count rows are the auxiliary primes. |
moddown_qp_to_q_out | Any device | Out form of moddown_qp_to_q. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least moddown_qp_to_q_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call. |
moddown_qp_to_q_workspace_bytes | Any device | Workspace bytes of moddown_qp_to_q_out for these operands; reads only their sizes, dtypes and devices. |
moddown_ntt_qp_to_q | Any device | Returns |
moddown_ntt_qp_to_q_out | Any device | Out form of moddown_ntt_qp_to_q. |
moddown_add_rescale | Any device | Computes |
moddown_add_rescale_out | Any device | Out form of moddown_add_rescale. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least moddown_add_rescale_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call. |
moddown_add_rescale_workspace_bytes | Any device | Workspace bytes of moddown_add_rescale_out for these operands; reads only their sizes, dtypes and devices. |
rational_rescale | Any device | Rescales a value from basis |
rational_rescale_out | Any device | Out form of rational_rescale. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least rational_rescale_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call. |
rational_rescale_workspace_bytes | Any device | Workspace bytes of rational_rescale_out for these operands; reads only their sizes, dtypes and devices. |
hybrid_modup_digit
function View source
at::Tensor fhelium::rns::hybrid_modup_digit(
const at::Tensor& source,
const KeySwitchTables& tables,
int64_t digit_index,
c10::IntArrayRef digits);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.hybrid_modup_digit
fhelium_rns_ops::hybrid_modup_digit(Tensor source, Tensor?[] tables, int digit_index, int[] digits) -> TensorLifts hybrid digit digit_index of coefficient standard residues over the active Q rows to QP Montgomery residues.
For digit rows qp_parameters and multiplied by qp_parameters and the normalizers, propagation, reduction, and extension fields of digits[digit_index]. The result has the qp_parameters row count.
hybrid_modup_digit_out
function View source
void fhelium::rns::hybrid_modup_digit_out(
const at::Tensor& source,
const KeySwitchTables& tables,
int64_t digit_index,
c10::IntArrayRef digits,
at::Tensor& out);2
3
4
5
6
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.hybrid_modup_digit_out
fhelium_rns_ops::hybrid_modup_digit_out(Tensor source, Tensor?[] tables, int digit_index, int[] digits, Tensor(a!) out) -> ()Out form of hybrid_modup_digit.
centered_basis_extend
function View source
at::Tensor fhelium::rns::centered_basis_extend(
const at::Tensor& source,
const BasisExtensionTables& tables);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.centered_basis_extend
fhelium_rns_ops::centered_basis_extend(Tensor source, Tensor?[] tables) -> TensorReturns the residues of the centered CRT representative of source in the target basis.
With source, the result holds tables.
centered_basis_extend_out
function View source
void fhelium::rns::centered_basis_extend_out(
const at::Tensor& source,
const BasisExtensionTables& tables,
at::Tensor& out,
const at::Tensor& workspace = at::Tensor());2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.centered_basis_extend_out
fhelium_rns_ops::centered_basis_extend_out(Tensor source, Tensor?[] tables, Tensor(a!) out, Tensor(b!)? workspace=None) -> ()Out form of centered_basis_extend. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least centered_basis_extend_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call.
centered_basis_extend_workspace_bytes
function View source
int64_t fhelium::rns::centered_basis_extend_workspace_bytes(
const at::Tensor& source,
const BasisExtensionTables& tables);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.centered_basis_extend_workspace_bytes
fhelium_rns_ops::centered_basis_extend_workspace_bytes(Tensor source, Tensor?[] tables) -> intWorkspace bytes of centered_basis_extend_out for these operands; reads only their sizes, dtypes and devices.
rounded_trailing_quotient
function View source
at::Tensor fhelium::rns::rounded_trailing_quotient(
const at::Tensor& source,
const TrailingQuotientTables& tables,
int64_t drop_count,
std::string_view rounding);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rounded_trailing_quotient
fhelium_rns_ops::rounded_trailing_quotient(Tensor source, Tensor?[] tables, int drop_count, str rounding) -> TensorReturns drop_count rows of source, after the optional row_order gather, are the divisor rows with product
half) for nearest rounding and inverses, parameters, and the optional half and row_order.
rounded_trailing_quotient_out
function View source
void fhelium::rns::rounded_trailing_quotient_out(
const at::Tensor& source,
const TrailingQuotientTables& tables,
int64_t drop_count,
std::string_view rounding,
at::Tensor& out,
const at::Tensor& workspace = at::Tensor());2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rounded_trailing_quotient_out
fhelium_rns_ops::rounded_trailing_quotient_out(Tensor source, Tensor?[] tables, int drop_count, str rounding, Tensor(a!) out, Tensor(b!)? workspace=None) -> ()Out form of rounded_trailing_quotient. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least rounded_trailing_quotient_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call.
rounded_trailing_quotient_workspace_bytes
function View source
int64_t fhelium::rns::rounded_trailing_quotient_workspace_bytes(
const at::Tensor& source,
const TrailingQuotientTables& tables,
int64_t drop_count,
std::string_view rounding);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rounded_trailing_quotient_workspace_bytes
fhelium_rns_ops::rounded_trailing_quotient_workspace_bytes(Tensor source, Tensor?[] tables, int drop_count, str rounding) -> intWorkspace bytes of rounded_trailing_quotient_out for these operands; reads only their sizes, dtypes and devices.
moddown_qp_to_q
function View source
at::Tensor fhelium::rns::moddown_qp_to_q(
const at::Tensor& source,
const KeySwitchTables& tables,
int64_t p_count,
std::string_view rounding);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_qp_to_q
fhelium_rns_ops::moddown_qp_to_q(Tensor source, Tensor?[] tables, int p_count, str rounding) -> TensorReturns p_count rows are the auxiliary primes.
Reads moddown_inverses, qp_parameters, and moddown_half for nearest rounding. When moddown_crt holds the centered quotient tables, the operands of fhelium::rns::crt_basis_extend with source P, target Q, and standard-form matrix entries p_inverse (q_parameters, and rounding does not apply.
moddown_qp_to_q_out
function View source
void fhelium::rns::moddown_qp_to_q_out(
const at::Tensor& source,
const KeySwitchTables& tables,
int64_t p_count,
std::string_view rounding,
at::Tensor& out,
const at::Tensor& workspace = at::Tensor());2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_qp_to_q_out
fhelium_rns_ops::moddown_qp_to_q_out(Tensor source, Tensor?[] tables, int p_count, str rounding, Tensor(a!) out, Tensor(b!)? workspace=None) -> ()Out form of moddown_qp_to_q. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least moddown_qp_to_q_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call.
moddown_qp_to_q_workspace_bytes
function View source
int64_t fhelium::rns::moddown_qp_to_q_workspace_bytes(
const at::Tensor& source,
const KeySwitchTables& tables,
int64_t p_count,
std::string_view rounding);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_qp_to_q_workspace_bytes
fhelium_rns_ops::moddown_qp_to_q_workspace_bytes(Tensor source, Tensor?[] tables, int p_count, str rounding) -> intWorkspace bytes of moddown_qp_to_q_out for these operands; reads only their sizes, dtypes and devices.
moddown_ntt_qp_to_q
function View source
at::Tensor fhelium::rns::moddown_ntt_qp_to_q(
const at::Tensor& source,
const std::optional<at::Tensor>& coefficient_c0,
const KeySwitchTables& tables,
std::string_view ntt_backend,
int64_t p_count,
std::string_view rounding);2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_ntt_qp_to_q
fhelium_rns_ops::moddown_ntt_qp_to_q(Tensor source, Tensor? coefficient_c0, Tensor?[] tables, str ntt_backend, int p_count, str rounding) -> TensorReturns
When coefficient_c0 is supplied, it is added to the coefficient correction of component zero before the forward transform. The result holds NTT Montgomery Q residues in the lazy range. Reads qp_parameters, q_parameters, moddown_inverses, p_inverse, the optional moddown_half, p_inverse_ntt, and q_forward. The centered quotient tables moddown_crt select the remainder of moddown_qp_to_q.
moddown_ntt_qp_to_q_out
function View source
void fhelium::rns::moddown_ntt_qp_to_q_out(
const at::Tensor& source,
const std::optional<at::Tensor>& coefficient_c0,
const KeySwitchTables& tables,
std::string_view ntt_backend,
int64_t p_count,
std::string_view rounding,
at::Tensor& out);2
3
4
5
6
7
8
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_ntt_qp_to_q_out
fhelium_rns_ops::moddown_ntt_qp_to_q_out(Tensor source, Tensor? coefficient_c0, Tensor?[] tables, str ntt_backend, int p_count, str rounding, Tensor(a!) out) -> ()Out form of moddown_ntt_qp_to_q.
moddown_add_rescale
function View source
at::Tensor fhelium::rns::moddown_add_rescale(
const at::Tensor& products,
const at::Tensor& base,
const KeySwitchTables& tables,
std::string_view ntt_backend,
int64_t q_count,
int64_t joint_drop_count,
bool joint_drop_is_prefix,
std::string_view output_domain);2
3
4
5
6
7
8
9
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_add_rescale
fhelium_rns_ops::moddown_add_rescale(Tensor products, Tensor base, Tensor?[] tables, str ntt_backend, int q_count, int joint_drop_count, bool joint_drop_is_prefix, str output_domain) -> TensorComputes
products are NTT Montgomery QP key products base the NTT Montgomery Q components products selects the matching prefix of base. q_count is the active Q row count, joint_drop_count the dropped row count, and joint_drop_is_prefix whether the dropped rows lead the Q rows; otherwise joint.drop_positions and joint.remaining_positions select them. The result is coefficient standard or NTT Montgomery residues according to output_domain (coefficient or ntt). Reads q_parameters and the joint fields p_times_base, dropped_offset, dropped_parameters, remaining_offset, remaining_parameters, inverses, ordered_parameters, product_inverse, dropped_inverse, and remaining_forward or remaining_inverse. When a restored prime set joint.restore holds the Montgomery multipliers of joint.product_parameters, joint.p_times_base holds joint.remaining_* tables describe joint.target_keep_positions places the surviving Q rows in joint.crt_t is defined, the quotient by joint.crt_d into the D rows, joint.crt_t into joint.crt_p_inverse), and the following quotient by joint.crt_inverses, joint.crt_ordered_parameters, nearest when joint.crt_half is defined).
moddown_add_rescale_out
function View source
void fhelium::rns::moddown_add_rescale_out(
const at::Tensor& products,
const at::Tensor& base,
const KeySwitchTables& tables,
std::string_view ntt_backend,
int64_t q_count,
int64_t joint_drop_count,
bool joint_drop_is_prefix,
std::string_view output_domain,
at::Tensor& out,
const at::Tensor& workspace = at::Tensor());2
3
4
5
6
7
8
9
10
11
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_add_rescale_out
fhelium_rns_ops::moddown_add_rescale_out(Tensor products, Tensor base, Tensor?[] tables, str ntt_backend, int q_count, int joint_drop_count, bool joint_drop_is_prefix, str output_domain, Tensor(a!) out, Tensor(b!)? workspace=None) -> ()Out form of moddown_add_rescale. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least moddown_add_rescale_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call.
moddown_add_rescale_workspace_bytes
function View source
int64_t fhelium::rns::moddown_add_rescale_workspace_bytes(
const at::Tensor& products,
const at::Tensor& base,
const KeySwitchTables& tables,
std::string_view ntt_backend,
int64_t q_count,
int64_t joint_drop_count,
bool joint_drop_is_prefix,
std::string_view output_domain);2
3
4
5
6
7
8
9
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.moddown_add_rescale_workspace_bytes
fhelium_rns_ops::moddown_add_rescale_workspace_bytes(Tensor products, Tensor base, Tensor?[] tables, str ntt_backend, int q_count, int joint_drop_count, bool joint_drop_is_prefix, str output_domain) -> intWorkspace bytes of moddown_add_rescale_out for these operands; reads only their sizes, dtypes and devices.
rational_rescale
function View source
at::Tensor fhelium::rns::rational_rescale(
const at::Tensor& source,
const RescaleTables& tables,
std::string_view input_domain,
std::string_view ntt_backend);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rational_rescale
fhelium_rns_ops::rational_rescale(Tensor source, Tensor?[] tables, str input_domain, str ntt_backend) -> TensorRescales a value from basis
source holds coefficient standard residues or, for input_domain = "ntt", NTT Montgomery residues of source_parameters. The result over the rows of target_parameters is
Reads source_parameters, target_parameters, dropped_parameters, ordered_parameters (target rows followed by D rows), drop_positions and keep_positions (rows of inverses (the trailing-quotient inverses of the ordered rows), dropped_offset and target_offset (residues of restore (Montgomery multipliers of target_keep_positions (rows of target_keep_positions, the kept rows are the rows of product_inverse (dropped_inverse, and target_forward.
rational_rescale_out
function View source
void fhelium::rns::rational_rescale_out(
const at::Tensor& source,
const RescaleTables& tables,
std::string_view input_domain,
std::string_view ntt_backend,
at::Tensor& out,
const at::Tensor& workspace = at::Tensor());2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rational_rescale_out
fhelium_rns_ops::rational_rescale_out(Tensor source, Tensor?[] tables, str input_domain, str ntt_backend, Tensor(a!) out, Tensor(b!)? workspace=None) -> ()Out form of rational_rescale. A defined workspace holds the temporaries: a contiguous uint8 Tensor of at least rational_rescale_workspace_bytes bytes on the operand device with a 256-byte aligned base. With an undefined workspace, the temporaries are allocated per call.
rational_rescale_workspace_bytes
function View source
int64_t fhelium::rns::rational_rescale_workspace_bytes(
const at::Tensor& source,
const RescaleTables& tables,
std::string_view input_domain,
std::string_view ntt_backend);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rational_rescale_workspace_bytes
fhelium_rns_ops::rational_rescale_workspace_bytes(Tensor source, Tensor?[] tables, str input_domain, str ntt_backend) -> intWorkspace bytes of rational_rescale_out for these operands; reads only their sizes, dtypes and devices.