Struct sunscreen_fhe_program::FheProgram
source · [−]pub struct FheProgram {
pub scheme: SchemeType,
pub graph: StableGraph<NodeInfo, EdgeInfo>,
}
Expand description
The intermediate representation for an FHE program used in the compiler back-end.
Other modules may transform these using the forward_traverse and reverse_traverse methods, or iterate over the graph member for analysis or execution.
The graph construction methods append_*
take NodeIndex types as arguments. These
indices must refer to other nodes in the graph.
Fields
scheme: SchemeType
The scheme type this FHE program will run under.
graph: StableGraph<NodeInfo, EdgeInfo>
The underlying dependency graph.
Implementations
sourceimpl FheProgram
impl FheProgram
sourcepub fn new(scheme: SchemeType) -> Self
pub fn new(scheme: SchemeType) -> Self
Create a new new empty intermediate representation.
sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Write this graph into graphviz dot format. The returned string contains the file’s contents.
sourcepub fn append_negate(&mut self, x: NodeIndex) -> NodeIndex
pub fn append_negate(&mut self, x: NodeIndex) -> NodeIndex
Appends a negate operation that depends on operand x
.
sourcepub fn append_multiply(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
pub fn append_multiply(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
Appends a multiply operation that depends on the operands x
and y
.
sourcepub fn append_multiply_plaintext(
&mut self,
x: NodeIndex,
y: NodeIndex
) -> NodeIndex
pub fn append_multiply_plaintext(
&mut self,
x: NodeIndex,
y: NodeIndex
) -> NodeIndex
Appends a multiply operation that depends on the operands x
and y
.
sourcepub fn append_add(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
pub fn append_add(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
Appends an add operation that depends on the operands x
and y
.
sourcepub fn append_sub(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
pub fn append_sub(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
Appends a subtract operation that depends on the operands x
and y
.
sourcepub fn append_input_ciphertext(&mut self, id: usize) -> NodeIndex
pub fn append_input_ciphertext(&mut self, id: usize) -> NodeIndex
Appends an input ciphertext with the given name.
sourcepub fn append_input_plaintext(&mut self, id: usize) -> NodeIndex
pub fn append_input_plaintext(&mut self, id: usize) -> NodeIndex
Appends an input plaintext with the given name.
sourcepub fn append_input_literal(&mut self, value: Literal) -> NodeIndex
pub fn append_input_literal(&mut self, value: Literal) -> NodeIndex
Appends a constant literal unencrypted.
value
: The integer or floating-point value in the literal.
sourcepub fn append_output_ciphertext(&mut self, x: NodeIndex) -> NodeIndex
pub fn append_output_ciphertext(&mut self, x: NodeIndex) -> NodeIndex
Sppends a node designating x
as an output of the FHE program.
sourcepub fn append_relinearize(&mut self, x: NodeIndex) -> NodeIndex
pub fn append_relinearize(&mut self, x: NodeIndex) -> NodeIndex
Appends an operation that relinearizes x
.
sourcepub fn append_rotate_left(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
pub fn append_rotate_left(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
Appends an operation that rotates ciphertext x
left by the literal node at y
places.
Remarks
Recall that BFV has 2 rows in a Batched vector. This rotates each row. CKKS has one large vector.
sourcepub fn append_rotate_right(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
pub fn append_rotate_right(&mut self, x: NodeIndex, y: NodeIndex) -> NodeIndex
Appends an operation that rotates ciphertext x
right by the literal node at y
places.
Remarks
Recall that BFV has 2 rows in a Batched vector. This rotates each row. CKKS has one large vector.
sourcepub fn forward_traverse<F>(&mut self, callback: F)where
F: FnMut(GraphQuery<'_>, NodeIndex) -> TransformList,
pub fn forward_traverse<F>(&mut self, callback: F)where
F: FnMut(GraphQuery<'_>, NodeIndex) -> TransformList,
A specialized topological DAG traversal that allows the following graph mutations during traversal:
- Delete the current node
- Insert nodoes after current node
- Add new nodes with no dependencies
Any other graph mutation will likely result in unvisited nodes.
callback
: A closure that receives the current node index and an object allowing you to make graph queryes. This closure returns a transform list.forward_traverse
will apply these transformations before continuing the traversal.
sourcepub fn reverse_traverse<F>(&mut self, callback: F)where
F: FnMut(GraphQuery<'_>, NodeIndex) -> TransformList,
pub fn reverse_traverse<F>(&mut self, callback: F)where
F: FnMut(GraphQuery<'_>, NodeIndex) -> TransformList,
A specialized reverse topological DAG traversal that allows the following graph mutations during traversal:
- Delete the current node
- Insert nodoes after current node
- Add new nodes with no dependencies
Any other graph mutation will likely result in unvisited nodes.
callback
: A closure that receives the current node index and an object allowing you to make graph queryes. This closure returns a transform list.reverse_traverse
will apply these transformations before continuing the traversal.
sourcepub fn remove_node(&mut self, id: NodeIndex)
pub fn remove_node(&mut self, id: NodeIndex)
Remove the given node.
sourcepub fn get_outputs(&self) -> impl Iterator<Item = NodeIndex> + '_
pub fn get_outputs(&self) -> impl Iterator<Item = NodeIndex> + '_
Returns the node indices of output ciphertexts
sourcepub fn num_inputs(&self) -> usize
pub fn num_inputs(&self) -> usize
Returns the number of inputs ciphertexts this FHE program takes.
sourcepub fn prune(&self, nodes: &[NodeIndex]) -> FheProgram
pub fn prune(&self, nodes: &[NodeIndex]) -> FheProgram
Runs tree shaking and returns a derived FheProgram with only dependencies required to run the requested nodes.
nodes
: indices specifying a set of nodes in the graph. Prune return a newFheProgram
containing nodes in the transitive closure of this set.
sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates this FheProgram
for correctness.
sourcepub fn requires_relin_keys(&self) -> bool
pub fn requires_relin_keys(&self) -> bool
Whether or not this FHE program needs relin keys to run. Needed for relinearization.
sourcepub fn requires_galois_keys(&self) -> bool
pub fn requires_galois_keys(&self) -> bool
Whether or not this FHE program requires Galois keys to run. Needed for rotation and row swap operations.
Trait Implementations
sourceimpl Clone for FheProgram
impl Clone for FheProgram
sourcefn clone(&self) -> FheProgram
fn clone(&self) -> FheProgram
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more