fhelium/rns.h
#include <fhelium/rns.h> · namespace fhelium::rns
Modular arithmetic, representation conversion, and basis conversion on RNS residue Tensors.
A residue operand has shape [*batch, limb, index]. Limb rns_params (row layout in fhelium/rns_parameters.h), and the final axis holds polynomial coefficients or NTT evaluations. Arithmetic functions preserve that domain. Implementations view *batch as one axis without copying, and they broadcast neither the limb axis nor the final axis. All Tensors of one call have one integral dtype (int32 or int64 residues) and one device.
A standard residue represents rns_params. Residues are stored in one of three ranges: reduced
Functions without a trailing underscore return newly allocated Tensors that do not alias an input. A trailing underscore marks a function that mutates its first Tensor argument in place and keeps its storage. An _out_ function writes into the caller-owned out or output Tensor without resizing it; that Tensor needs the shape of the functional result, the input dtype and device, disjoint element addresses, and no overlap with any input or table. All other Tensor arguments are read-only.
| Function | Devices | Summary |
|---|---|---|
montgomery_mul | CPU, CUDA, HIP | Multiplies two residue Tensors elementwise in Montgomery form. |
montgomery_mul_out | CPU, CUDA, HIP | Out form of montgomery_mul; writes the product into out, which has the shape of lhs. |
montgomery_weighted_sum | Any device | Evaluates the weighted sum |
montgomery_weighted_sum_out | CPU, CUDA, HIP | Out form of montgomery_weighted_sum; out has the shape, dtype and device of ciphertexts[0] and is disjoint from every term. |
montgomery_weighted_sums | Any device | Evaluates group_count weighted sums that share one list of ciphertext terms. |
montgomery_weighted_sums_out | CPU, CUDA, HIP | Output form of montgomery_weighted_sums; out is contiguous with shape [component, group, *rest] of the ciphertext terms and their dtype and device. |
montgomery_mul_cyclic_compressed | Any device | Multiplies by a compressed right operand whose values repeat cyclically along the final axis. |
montgomery_mul_contiguous_compressed | Any device | Multiplies by a compressed right operand whose values repeat in contiguous runs along the final axis. |
montgomery_mul_cyclic_compressed_out | CPU, CUDA, HIP | Out form of montgomery_mul_cyclic_compressed. out has the shape, dtype and device of lhs, is lhs itself or disjoint from it, and is disjoint from compressed_rhs. |
montgomery_mul_contiguous_compressed_out | CPU, CUDA, HIP | Out form of montgomery_mul_contiguous_compressed, with the output requirements of montgomery_mul_cyclic_compressed_out. |
montgomery_mul_row_scalars_ | CPU, CUDA, HIP | Multiplies every limb row by one Montgomery scalar in place. |
to_montgomery_ | CPU, CUDA, HIP | Converts standard residues to Montgomery form in place. |
from_montgomery_ | CPU, CUDA, HIP | Converts Montgomery residues to standard residues in place. |
add_lazy | Any device | Adds two residue Tensors modulo |
add_lazy_out | CPU, CUDA, HIP | Out form of add_lazy; writes the sum into out, which has the shape of lhs. |
add_lazy_with_twice_modulus | Any device | Adds two residue Tensors modulo |
add_lazy_with_twice_modulus_out | CPU, CUDA, HIP | Out form of add_lazy_with_twice_modulus; out has the shape of lhs and is lhs itself or disjoint from it. |
sub_lazy | Any device | Subtracts two residue Tensors modulo |
sub_lazy_out | CPU, CUDA, HIP | Out form of sub_lazy; out has the shape of lhs and is lhs itself or disjoint from it. |
add_standard | Any device | Adds two standard residue Tensors and returns reduced residues. |
add_standard_ | Any device | In-place form of add_standard; the sum replaces lhs. |
add_standard_out | CPU, CUDA, HIP | Out form of add_standard; out has the shape of lhs and is lhs itself or disjoint from it. |
sum_standard_batch | Any device | Sums standard residues over one batch axis. |
sum_standard_batch_out | CPU, CUDA, HIP | Out form of sum_standard_batch; out has the shape of source without axis dim and is disjoint from source. |
sub_standard | Any device | Subtracts two standard residue Tensors and returns reduced residues. |
sub_standard_ | Any device | In-place form of sub_standard; the difference replaces lhs. |
sub_standard_out | CPU, CUDA, HIP | Out form of sub_standard; out has the shape of lhs and is lhs itself or disjoint from it. |
negate_standard | Any device | Negates standard residues: returns |
negate_standard_ | Any device | In-place form of negate_standard. |
negate_standard_out | CPU, CUDA, HIP | Out form of negate_standard; out has the shape of source and is source itself or disjoint from it. |
montgomery_mul_row_scalars_standard | Any device | Multiplies every limb row by one Montgomery scalar and returns reduced residues. |
montgomery_mul_row_scalars_standard_out | CPU, CUDA, HIP | Out form of montgomery_mul_row_scalars_standard: writes the product to out, a Tensor with the shape, dtype and device of residues that is residues itself or disjoint from it. |
reduce_to_standard_ | CPU, CUDA, HIP | Reduces lazy residues to the reduced range in place. |
center_residues_ | CPU, CUDA, HIP | Maps reduced residues to centered representatives in place. |
shift_residues_positive_ | CPU, CUDA, HIP | Adds |
lift_integer_coefficients | CPU, CUDA, HIP | Lifts signed integer coefficients to standard residues for every limb. |
crt_basis_extend_out | Any device | Output form of crt_basis_extend; the result is written to output. |
crt_basis_extend | Any device | Extends standard residues to a target basis by a supplied CRT lift matrix. |
mixed_radix_modup_tiled | CUDA | Extends source residues to a target basis through mixed-radix digits in one fused pass. |
mixed_radix_modup_tiled_out | CUDA | Output form of mixed_radix_modup_tiled; the result is written to out. |
mixed_radix_decompose | CPU, CUDA, HIP | Decomposes residues into mixed-radix digits by Garner's algorithm. |
mixed_radix_basis_extend_to_montgomery | CPU, CUDA, HIP | Evaluates mixed-radix digits modulo target primes in Montgomery form. |
mixed_radix_decompose_out | CPU, CUDA, HIP | Output form of mixed_radix_decompose; the digits are written to out. |
mixed_radix_basis_extend_to_montgomery_out | CPU, CUDA, HIP | Output form of mixed_radix_basis_extend_to_montgomery; the result is written to out. |
montgomery_mul
function View source
at::Tensor fhelium::rns::montgomery_mul(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params);2
3
4
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul
fhelium_rns_ops::montgomery_mul(Tensor lhs, Tensor rhs, Tensor rns_params) -> TensorMultiplies two residue Tensors elementwise in Montgomery form.
Computes rhs has the shape of lhs or a batch extent of one, which is broadcast over the batch of lhs. The result has the shape of lhs.
montgomery_mul_out
function View source
void fhelium::rns::montgomery_mul_out(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_out
fhelium_rns_ops::montgomery_mul_out(Tensor lhs, Tensor rhs, Tensor rns_params, Tensor(a!) out) -> ()Out form of montgomery_mul; writes the product into out, which has the shape of lhs.
montgomery_weighted_sum
function View source
at::Tensor fhelium::rns::montgomery_weighted_sum(
at::TensorList ciphertexts,
at::TensorList plaintexts,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.montgomery_weighted_sum
fhelium_rns_ops::montgomery_weighted_sum(Tensor[] ciphertexts, Tensor[] plaintexts, Tensor rns_params) -> TensorEvaluates the weighted sum
ciphertexts and plaintexts are non-empty lists of equal length. Every ciphertext has shape [component, *batch, limb, index], and every plaintext has shape [*batch, limb, index] and is broadcast over the component axis. For every component, batch element, limb, and index, the function computes ciphertexts[0]. Implementations may fuse the term loop.
montgomery_weighted_sum_out
function View source
void fhelium::rns::montgomery_weighted_sum_out(
at::TensorList ciphertexts,
at::TensorList plaintexts,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_weighted_sum_out
fhelium_rns_ops::montgomery_weighted_sum_out(Tensor[] ciphertexts, Tensor[] plaintexts, Tensor rns_params, Tensor(a!) out) -> ()Out form of montgomery_weighted_sum; out has the shape, dtype and device of ciphertexts[0] and is disjoint from every term.
montgomery_weighted_sums
function View source
at::Tensor fhelium::rns::montgomery_weighted_sums(
at::TensorList ciphertexts,
at::TensorList plaintexts,
int64_t group_count,
const at::Tensor& rns_params);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.montgomery_weighted_sums
fhelium_rns_ops::montgomery_weighted_sums(Tensor[] ciphertexts, Tensor[] plaintexts, int group_count, Tensor rns_params) -> TensorEvaluates group_count weighted sums that share one list of ciphertext terms.
plaintexts is a row-major matrix of group_count groups with one plaintext per ciphertext: group plaintexts[g * T + t] for term [component, group, *batch, limb, index] with out[:, g] = montgomery_weighted_sum(ciphertexts, plaintexts[g*T : (g+1)*T]). Groups are evaluated in matrix order.
montgomery_weighted_sums_out
function View source
void fhelium::rns::montgomery_weighted_sums_out(
at::TensorList ciphertexts,
at::TensorList plaintexts,
int64_t group_count,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
6
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_weighted_sums_out
fhelium_rns_ops::montgomery_weighted_sums_out(Tensor[] ciphertexts, Tensor[] plaintexts, int group_count, Tensor rns_params, Tensor(a!) out) -> ()Output form of montgomery_weighted_sums; out is contiguous with shape [component, group, *rest] of the ciphertext terms and their dtype and device.
montgomery_mul_cyclic_compressed
function View source
at::Tensor fhelium::rns::montgomery_mul_cyclic_compressed(
const at::Tensor& lhs,
const at::Tensor& compressed_rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_cyclic_compressed
fhelium_rns_ops::montgomery_mul_cyclic_compressed(Tensor lhs, Tensor compressed_rhs, Tensor rns_params) -> TensorMultiplies by a compressed right operand whose values repeat cyclically along the final axis.
compressed_rhs has shape [*compressed_batch, limb, U], where lhs. Index lhs is multiplied by index compressed_rhs, as montgomery_mul would with the expanded operand. The compressed batch extent, after *batch is collapsed, is one or equal to that of lhs.
montgomery_mul_contiguous_compressed
function View source
at::Tensor fhelium::rns::montgomery_mul_contiguous_compressed(
const at::Tensor& lhs,
const at::Tensor& compressed_rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_contiguous_compressed
fhelium_rns_ops::montgomery_mul_contiguous_compressed(Tensor lhs, Tensor compressed_rhs, Tensor rns_params) -> TensorMultiplies by a compressed right operand whose values repeat in contiguous runs along the final axis.
compressed_rhs has shape [*compressed_batch, limb, U], where lhs. Index lhs is multiplied by index compressed_rhs, as montgomery_mul would with the expanded operand. The compressed batch extent, after *batch is collapsed, is one or equal to that of lhs.
montgomery_mul_cyclic_compressed_out
function View source
void fhelium::rns::montgomery_mul_cyclic_compressed_out(
const at::Tensor& lhs,
const at::Tensor& compressed_rhs,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_cyclic_compressed_out
fhelium_rns_ops::montgomery_mul_cyclic_compressed_out(Tensor lhs, Tensor compressed_rhs, Tensor rns_params, Tensor(a!) out) -> ()Out form of montgomery_mul_cyclic_compressed. out has the shape, dtype and device of lhs, is lhs itself or disjoint from it, and is disjoint from compressed_rhs.
montgomery_mul_contiguous_compressed_out
function View source
void fhelium::rns::montgomery_mul_contiguous_compressed_out(
const at::Tensor& lhs,
const at::Tensor& compressed_rhs,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_contiguous_compressed_out
fhelium_rns_ops::montgomery_mul_contiguous_compressed_out(Tensor lhs, Tensor compressed_rhs, Tensor rns_params, Tensor(a!) out) -> ()Out form of montgomery_mul_contiguous_compressed, with the output requirements of montgomery_mul_cyclic_compressed_out.
montgomery_mul_row_scalars_
function View source
void fhelium::rns::montgomery_mul_row_scalars_(
at::Tensor& residues,
const at::Tensor& row_scalars,
const at::Tensor& rns_params);2
3
4
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_row_scalars_
fhelium_rns_ops::montgomery_mul_row_scalars_(Tensor(a!) residues, Tensor row_scalars, Tensor rns_params) -> ()Multiplies every limb row by one Montgomery scalar in place.
row_scalars is a vector with one entry per limb. Each residue of limb
to_montgomery_
function View source
void fhelium::rns::to_montgomery_(
at::Tensor& standard_residues,
const at::Tensor& rns_params);2
3
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.to_montgomery_
fhelium_rns_ops::to_montgomery_(Tensor(a!) standard_residues, Tensor rns_params) -> ()Converts standard residues to Montgomery form in place.
Each residue RNS_PARAM_R2 row. The result is in the lazy range.
from_montgomery_
function View source
void fhelium::rns::from_montgomery_(
at::Tensor& montgomery_residues,
const at::Tensor& rns_params);2
3
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.from_montgomery_
fhelium_rns_ops::from_montgomery_(Tensor(a!) montgomery_residues, Tensor rns_params) -> ()Converts Montgomery residues to standard residues in place.
Each residue
add_lazy
function View source
at::Tensor fhelium::rns::add_lazy(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.add_lazy
fhelium_rns_ops::add_lazy(Tensor lhs, Tensor rhs, Tensor rns_params) -> TensorAdds two residue Tensors modulo
Computes rhs has the shape of lhs or a batch extent of one.
add_lazy_out
function View source
void fhelium::rns::add_lazy_out(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.add_lazy_out
fhelium_rns_ops::add_lazy_out(Tensor lhs, Tensor rhs, Tensor rns_params, Tensor(a!) out) -> ()Out form of add_lazy; writes the sum into out, which has the shape of lhs.
add_lazy_with_twice_modulus
function View source
at::Tensor fhelium::rns::add_lazy_with_twice_modulus(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& twice_modulus);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.add_lazy_with_twice_modulus
fhelium_rns_ops::add_lazy_with_twice_modulus(Tensor lhs, Tensor rhs, Tensor twice_modulus) -> TensorAdds two residue Tensors modulo
Equivalent to add_lazy with twice_modulus[j] rns_params.
add_lazy_with_twice_modulus_out
function View source
void fhelium::rns::add_lazy_with_twice_modulus_out(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& twice_modulus,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.add_lazy_with_twice_modulus_out
fhelium_rns_ops::add_lazy_with_twice_modulus_out(Tensor lhs, Tensor rhs, Tensor twice_modulus, Tensor(a!) out) -> ()Out form of add_lazy_with_twice_modulus; out has the shape of lhs and is lhs itself or disjoint from it.
sub_lazy
function View source
at::Tensor fhelium::rns::sub_lazy(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.sub_lazy
fhelium_rns_ops::sub_lazy(Tensor lhs, Tensor rhs, Tensor rns_params) -> TensorSubtracts two residue Tensors modulo
Computes rhs has the shape of lhs or a batch extent of one.
sub_lazy_out
function View source
void fhelium::rns::sub_lazy_out(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.sub_lazy_out
fhelium_rns_ops::sub_lazy_out(Tensor lhs, Tensor rhs, Tensor rns_params, Tensor(a!) out) -> ()Out form of sub_lazy; out has the shape of lhs and is lhs itself or disjoint from it.
add_standard
function View source
at::Tensor fhelium::rns::add_standard(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.add_standard
fhelium_rns_ops::add_standard(Tensor lhs, Tensor rhs, Tensor rns_params) -> TensorAdds two standard residue Tensors and returns reduced residues.
Computes rhs has the shape of lhs or a batch extent of one; limb and final axes are never broadcast.
add_standard_
function View source
void fhelium::rns::add_standard_(
at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.add_standard_
fhelium_rns_ops::add_standard_(Tensor(a!) lhs, Tensor rhs, Tensor rns_params) -> ()In-place form of add_standard; the sum replaces lhs.
add_standard_out
function View source
void fhelium::rns::add_standard_out(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.add_standard_out
fhelium_rns_ops::add_standard_out(Tensor lhs, Tensor rhs, Tensor rns_params, Tensor(a!) out) -> ()Out form of add_standard; out has the shape of lhs and is lhs itself or disjoint from it.
sum_standard_batch
function View source
at::Tensor fhelium::rns::sum_standard_batch(
const at::Tensor& source,
int64_t dim,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.sum_standard_batch
fhelium_rns_ops::sum_standard_batch(Tensor source, int dim, Tensor rns_params) -> TensorSums standard residues over one batch axis.
dim selects a batch axis of source, and the result keeps the remaining axes. Each addition is reduced to
sum_standard_batch_out
function View source
void fhelium::rns::sum_standard_batch_out(
const at::Tensor& source,
int64_t dim,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.sum_standard_batch_out
fhelium_rns_ops::sum_standard_batch_out(Tensor source, int dim, Tensor rns_params, Tensor(a!) out) -> ()Out form of sum_standard_batch; out has the shape of source without axis dim and is disjoint from source.
sub_standard
function View source
at::Tensor fhelium::rns::sub_standard(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.sub_standard
fhelium_rns_ops::sub_standard(Tensor lhs, Tensor rhs, Tensor rns_params) -> TensorSubtracts two standard residue Tensors and returns reduced residues.
Computes rhs has the shape of lhs or a batch extent of one.
sub_standard_
function View source
void fhelium::rns::sub_standard_(
at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.sub_standard_
fhelium_rns_ops::sub_standard_(Tensor(a!) lhs, Tensor rhs, Tensor rns_params) -> ()In-place form of sub_standard; the difference replaces lhs.
sub_standard_out
function View source
void fhelium::rns::sub_standard_out(
const at::Tensor& lhs,
const at::Tensor& rhs,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.sub_standard_out
fhelium_rns_ops::sub_standard_out(Tensor lhs, Tensor rhs, Tensor rns_params, Tensor(a!) out) -> ()Out form of sub_standard; out has the shape of lhs and is lhs itself or disjoint from it.
negate_standard
function View source
at::Tensor fhelium::rns::negate_standard(
const at::Tensor& source,
const at::Tensor& rns_params);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.negate_standard
fhelium_rns_ops::negate_standard(Tensor source, Tensor rns_params) -> TensorNegates standard residues: returns
negate_standard_
function View source
void fhelium::rns::negate_standard_(
at::Tensor& source,
const at::Tensor& rns_params);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.negate_standard_
fhelium_rns_ops::negate_standard_(Tensor(a!) source, Tensor rns_params) -> ()In-place form of negate_standard.
negate_standard_out
function View source
void fhelium::rns::negate_standard_out(
const at::Tensor& source,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.negate_standard_out
fhelium_rns_ops::negate_standard_out(Tensor source, Tensor rns_params, Tensor(a!) out) -> ()Out form of negate_standard; out has the shape of source and is source itself or disjoint from it.
montgomery_mul_row_scalars_standard
function View source
at::Tensor fhelium::rns::montgomery_mul_row_scalars_standard(
const at::Tensor& residues,
const at::Tensor& row_scalars,
const at::Tensor& rns_params);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_row_scalars_standard
fhelium_rns_ops::montgomery_mul_row_scalars_standard(Tensor residues, Tensor row_scalars, Tensor rns_params) -> TensorMultiplies every limb row by one Montgomery scalar and returns reduced residues.
Computes row_scalars. With a Montgomery scalar
montgomery_mul_row_scalars_standard_out
function View source
void fhelium::rns::montgomery_mul_row_scalars_standard_out(
const at::Tensor& residues,
const at::Tensor& row_scalars,
const at::Tensor& rns_params,
at::Tensor& out);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.montgomery_mul_row_scalars_standard_out
fhelium_rns_ops::montgomery_mul_row_scalars_standard_out(Tensor residues, Tensor row_scalars, Tensor rns_params, Tensor(a!) out) -> ()Out form of montgomery_mul_row_scalars_standard: writes the product to out, a Tensor with the shape, dtype and device of residues that is residues itself or disjoint from it.
reduce_to_standard_
function View source
void fhelium::rns::reduce_to_standard_(
at::Tensor& lazy_residues,
const at::Tensor& rns_params);2
3
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.reduce_to_standard_
fhelium_rns_ops::reduce_to_standard_(Tensor(a!) lazy_residues, Tensor rns_params) -> ()Reduces lazy residues to the reduced range in place.
Maps each residue in
center_residues_
function View source
void fhelium::rns::center_residues_(
at::Tensor& standard_residues,
const at::Tensor& rns_params);2
3
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.center_residues_
fhelium_rns_ops::center_residues_(Tensor(a!) standard_residues, Tensor rns_params) -> ()Maps reduced residues to centered representatives in place.
A residue
shift_residues_positive_
function View source
void fhelium::rns::shift_residues_positive_(
at::Tensor& centered_residues,
const at::Tensor& rns_params);2
3
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.shift_residues_positive_
fhelium_rns_ops::shift_residues_positive_(Tensor(a!) centered_residues, Tensor rns_params) -> ()Adds
The result of
lift_integer_coefficients
function View source
at::Tensor fhelium::rns::lift_integer_coefficients(
const at::Tensor& coefficients,
const at::Tensor& twice_modulus);2
3
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.lift_integer_coefficients
fhelium_rns_ops::lift_integer_coefficients(Tensor coefficients, Tensor twice_modulus) -> TensorLifts signed integer coefficients to standard residues for every limb.
coefficients (int32 or int64) has shape [*batch, coefficient], and twice_modulus holds twice_modulus, shape [*batch, limb, coefficient] and entry twice_modulus to match the output limbs.
crt_basis_extend_out
function View source
void fhelium::rns::crt_basis_extend_out(
const at::Tensor& source_residues,
const at::Tensor& source_parameters,
const at::Tensor& target_parameters,
const at::Tensor& matrix,
const at::Tensor& target_reciprocals,
const std::optional<at::Tensor>& source_normalizers,
const std::optional<at::Tensor>& source_reciprocals,
const std::optional<at::Tensor>& target_offsets,
at::Tensor& output);2
3
4
5
6
7
8
9
10
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.crt_basis_extend_out
fhelium_rns_ops::crt_basis_extend_out(Tensor source_residues, Tensor source_parameters, Tensor target_parameters, Tensor matrix, Tensor target_reciprocals, Tensor? source_normalizers, Tensor? source_reciprocals, Tensor? target_offsets, Tensor(a!) out) -> ()Output form of crt_basis_extend; the result is written to output.
crt_basis_extend
function View source
at::Tensor fhelium::rns::crt_basis_extend(
const at::Tensor& source_residues,
const at::Tensor& source_parameters,
const at::Tensor& target_parameters,
const at::Tensor& matrix,
const at::Tensor& target_reciprocals,
const std::optional<at::Tensor>& source_normalizers = std::nullopt,
const std::optional<at::Tensor>& source_reciprocals = std::nullopt,
const std::optional<at::Tensor>& target_offsets = std::nullopt);2
3
4
5
6
7
8
9
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.crt_basis_extend
fhelium_rns_ops::crt_basis_extend(Tensor source_residues, Tensor source_parameters, Tensor target_parameters, Tensor matrix, Tensor target_reciprocals, Tensor? source_normalizers=None, Tensor? source_reciprocals=None, Tensor? target_offsets=None) -> TensorExtends standard residues to a target basis by a supplied CRT lift matrix.
source_residues has shape [*batch, source_limb, coefficient] with standard residues source_parameters. Let matrix[i][t] source_normalizers source_reciprocals and target_offsets, each source row becomes the centered residue matrix[i][t] target_offsets[t] [*batch, target_limb, coefficient] with reduced Montgomery residues for the target primes described by target_parameters. Neither lift selects the least nonnegative representative modulo
target_reciprocals and source_reciprocals are int64 vectors of
mixed_radix_modup_tiled
function View source
at::Tensor fhelium::rns::mixed_radix_modup_tiled(
const at::Tensor& source_residues,
at::TensorList decomposition_tables,
const at::Tensor& extension,
const at::Tensor& parameters);2
3
4
5
Devices: CUDA
Torch operator: torch.ops.fhelium_rns_ops.mixed_radix_modup_tiled
fhelium_rns_ops::mixed_radix_modup_tiled(Tensor source_residues, Tensor[] decomposition_tables, Tensor extension, Tensor parameters) -> TensorExtends source residues to a target basis through mixed-radix digits in one fused pass.
Computes the result of mixed_radix_decompose followed by mixed_radix_basis_extend_to_montgomery without writing the digits to global memory. decomposition_tables holds, in order, the normalizers, the propagation coefficients, and the source rows' modulus_lo, modulus_hi, neg_inv_modulus_lo, and neg_inv_modulus_hi. extension holds the basis-extension coefficients and parameters the target rns_params. The output has shape [*batch, target_limb, coefficient].
mixed_radix_modup_tiled_out
function View source
void fhelium::rns::mixed_radix_modup_tiled_out(
const at::Tensor& source_residues,
at::TensorList decomposition_tables,
const at::Tensor& extension,
const at::Tensor& parameters,
at::Tensor& out);2
3
4
5
6
Devices: CUDA
Torch operator: torch.ops.fhelium_rns_ops.mixed_radix_modup_tiled_out
fhelium_rns_ops::mixed_radix_modup_tiled_out(Tensor source_residues, Tensor[] decomposition_tables, Tensor extension, Tensor parameters, Tensor(a!) out) -> ()Output form of mixed_radix_modup_tiled; the result is written to out.
mixed_radix_decompose
function View source
at::Tensor fhelium::rns::mixed_radix_decompose(
const at::Tensor& source_residues,
const at::Tensor& mixed_radix_normalizers,
const at::Tensor& mixed_radix_propagation_coefficients,
const at::Tensor& modulus_lo,
const at::Tensor& modulus_hi,
const at::Tensor& neg_inv_modulus_lo,
const at::Tensor& neg_inv_modulus_hi);2
3
4
5
6
7
8
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.mixed_radix_decompose
fhelium_rns_ops::mixed_radix_decompose(Tensor source_residues, Tensor mixed_radix_normalizers, Tensor mixed_radix_propagation_coefficients, Tensor modulus_lo, Tensor modulus_hi, Tensor neg_inv_modulus_lo, Tensor neg_inv_modulus_hi) -> TensorDecomposes residues into mixed-radix digits by Garner's algorithm.
For source primes mixed_radix_normalizers[r] is mixed_radix_propagation_coefficients[r][c] is modulus_* vectors are the corresponding rns_params rows of the source primes. The output has the shape of source_residues.
mixed_radix_basis_extend_to_montgomery
function View source
at::Tensor fhelium::rns::mixed_radix_basis_extend_to_montgomery(
const at::Tensor& mixed_radix_components,
const at::Tensor& basis_extension_coefficients,
const at::Tensor& rns_params,
int64_t destination_row_count);2
3
4
5
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.mixed_radix_basis_extend_to_montgomery
fhelium_rns_ops::mixed_radix_basis_extend_to_montgomery(Tensor mixed_radix_components, Tensor basis_extension_coefficients, Tensor rns_params, int destination_row_count) -> TensorEvaluates mixed-radix digits modulo target primes in Montgomery form.
mixed_radix_components holds digits mixed_radix_decompose. basis_extension_coefficients[r-1][t] is destination_row_count target primes rns_params, the function computes [*batch, destination_row_count, coefficient].
mixed_radix_decompose_out
function View source
void fhelium::rns::mixed_radix_decompose_out(
const at::Tensor& source_residues,
const at::Tensor& mixed_radix_normalizers,
const at::Tensor& mixed_radix_propagation_coefficients,
const at::Tensor& modulus_lo,
const at::Tensor& modulus_hi,
const at::Tensor& neg_inv_modulus_lo,
const at::Tensor& neg_inv_modulus_hi,
at::Tensor& out);2
3
4
5
6
7
8
9
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.mixed_radix_decompose_out
fhelium_rns_ops::mixed_radix_decompose_out(Tensor source_residues, Tensor mixed_radix_normalizers, Tensor mixed_radix_propagation_coefficients, Tensor modulus_lo, Tensor modulus_hi, Tensor neg_inv_modulus_lo, Tensor neg_inv_modulus_hi, Tensor(a!) out) -> ()Output form of mixed_radix_decompose; the digits are written to out.
mixed_radix_basis_extend_to_montgomery_out
function View source
void fhelium::rns::mixed_radix_basis_extend_to_montgomery_out(
const at::Tensor& mixed_radix_components,
const at::Tensor& basis_extension_coefficients,
const at::Tensor& rns_params,
int64_t destination_row_count,
at::Tensor& out);2
3
4
5
6
Devices: CPU, CUDA, HIP
Torch operator: torch.ops.fhelium_rns_ops.mixed_radix_basis_extend_to_montgomery_out
fhelium_rns_ops::mixed_radix_basis_extend_to_montgomery_out(Tensor mixed_radix_components, Tensor basis_extension_coefficients, Tensor rns_params, int destination_row_count, Tensor(a!) out) -> ()Output form of mixed_radix_basis_extend_to_montgomery; the result is written to out.