Mgmt

‘mgmt’ Dialect

The mgmt dialect contains scheme-agnostic ciphertext management ops (like relinearize and mod reduce), to enable initial high-level compiler passes to perform a first pass at parameter selection, while lower-level passes may refine them with scheme-specific information.

Mgmt attributes

MgmtAttr

Container attribute for all mgmt parameter

Syntax:

#mgmt.mgmt<
  int,   # level
  int,   # dimension
  int64_t   # scale
>

This attribute is used to store all mgmt parameters.

The attribute is a struct with the following fields:

  • level : the level of the ciphertext, from L to 0
  • dimension : the dimension of the ciphertext, defaults to 2

Internally, this attribute is used by secret-to- for determining the level and dimension of the ciphertext.

It should be populated by –secret-with-mgmt- before going through the secret-to- pass.

Example:

#mgmt = #mgmt.mgmt<level = 1> // dimension defaults to 2
#mgmt1 = #mgmt.mgmt<level = 1, dimension = 3>
%0 = secret.generic ins(%arg0, %arg1 : !secret.secret<i16>) attrs = {mgmt.mgmt = #mgmt} {
   ...
} -> !secret.secret<i16>

Parameters:

ParameterC++ typeDescription
levelint
dimensionint
scaleint64_t

OpenfheParamsAttr

Container attribute for some OpenFHE-specific parameters

Syntax:

#mgmt.openfhe_params<
  int,   # evalAddCount
  int   # keySwitchCount
>

This attribute is used to store some OpenFHE-specific parameters.

The attribute is a struct with the following fields:

  • evalAddCount : param for OpenFHE SetEvalAddCount
  • keySwitchCount : param for OpenFHE SetKeySwitchCount

When this attribute presents, the lowering of openfhe pass will use these parameters to set the corresponding OpenFHE parameters.

It should be populated by –secret-with-mgmt-bgv before going through the secret-to-bgv bgv-to-openfhe pass.

Example:

#openfhe_params = #mgmt.openfhe_params<evalAddCount = 1, keySwitchCount = 1>

Parameters:

ParameterC++ typeDescription
evalAddCountint
keySwitchCountint

Mgmt ops

mgmt.adjust_scale (heir::mgmt::AdjustScaleOp)

Adjust the scale of the input ciphertext (for BGV and CKKS)

Syntax:

operation ::= `mgmt.adjust_scale` operands attr-dict `:` type($output)

This is scheme-agonistic operation that adjust the scale of the input ciphertext. This is an opaque operation, and the concrete value of the scale is determined by other methods.

To distinguish different opaque adjust_scale operations, the id attribute is used.

At the time of secret-insert-mgmt-<scheme>, the concrete scale is not known as the scheme parameter is not generated. Further passes like populate-scale-<scheme> is responsible for materializing the concrete scale when the scheme parameter is known.

When further lowered, it could be lowered to bgv.mul_plain or ckks.mul_plain depending on the scheme.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Attributes:

AttributeMLIR TypeDescription
id::mlir::IntegerAttr64-bit signless integer attribute

Operands:

OperandDescription
inputany type

Results:

ResultDescription
outputany type

mgmt.bootstrap (heir::mgmt::BootstrapOp)

Bootstrap the input ciphertext to refresh its noise budget

Syntax:

operation ::= `mgmt.bootstrap` operands attr-dict `:` type($output)

This is a scheme-agnostic operation that implies bootstrapping of the input ciphertext to refresh its noise budget.

Bootstrapping is a technique used in homomorphic encryption to reduce the noise in a ciphertext, allowing further operations to be performed on it without decryption.

When further lowered, it could be lowered to bgv.bootstrap or ckks.bootstrap depending on the scheme.

For the current backend, only ckks.bootstrap is supported. Further backend may include bgv.bootstrap.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
inputany type

Results:

ResultDescription
outputany type

mgmt.init (heir::mgmt::InitOp)

Init the plaintext with mgmt attributes

Syntax:

operation ::= `mgmt.init` operands attr-dict `:` type($output)

This is a scheme-agnostic operation that initializes the plaintext with mgmt attributes.

Plaintext has multiple sources, e.g. function argument, arith.constant, tensor.empty, etc. However, they may have multiple uses in HE circuit and the level/scale information for them may be different, so we could not annotate them with mgmt attributes directly, as they could not have more than one annotation.

Also, mgmt attributes annotated on them may get lost as other optimization like CSE or constant folding may canonicalize them away.

To address the problem, for each use of the plaintext, we insert an mgmt.init operation to initialize the plaintext with mgmt attributes.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
inputany type

Results:

ResultDescription
outputany type

mgmt.level_reduce (heir::mgmt::LevelReduceOp)

Reduce the level of input ciphertext by dropping the last k RNS limbs

Syntax:

operation ::= `mgmt.level_reduce` operands attr-dict `:` type($output)

This scheme-agonistic operation reduces the ciphertext level by k, as specified by the levelToDrop attribute.

If levelToDrop is not specified, it defaults to 1.

Input ciphertext is assumed to be in RNS form when further lowered.

Later passes may lower this op to bgv.level_reduce or ckks.level_reduce depending on the scheme.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Attributes:

AttributeMLIR TypeDescription
levelToDrop::mlir::IntegerAttr64-bit signless integer attribute

Operands:

OperandDescription
inputany type

Results:

ResultDescription
outputany type

mgmt.modreduce (heir::mgmt::ModReduceOp)

Modulus switch the input ciphertext down by one limb (RNS assumed)

Syntax:

operation ::= `mgmt.modreduce` operands attr-dict `:` type($output)

This is scheme-agonistic operation that implies modulus switching/rescaling by one limb.

Input ciphertext is assumed to be in RNS form when further lowered.

When further lowered, it could be lowered to bgv.modulus_switch or ckks.rescale depending on the scheme.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
inputany type

Results:

ResultDescription
outputany type

mgmt.relinearize (heir::mgmt::RelinearizeOp)

Relinearize the input ciphertext to be linear

Syntax:

operation ::= `mgmt.relinearize` operands attr-dict `:` type($output)

This is scheme-agonistic operation that implies relinearization of the input ciphertext to be linear (i.e. returns to dimension 2).

This is used solely by multiplication. For rotation, currently HEIR assumes relinearization is done internally and does not have a separate scheme-specific operation for it.

This accepts a ciphertext with dimension > 2 and returns a ciphertext with dimension 2. Note that the semantic includes the relinearization of higher dimension input like input with dimension 4 or higher, which when materialized should require multiple relinearization keys.

When further lowered, it could be lowered to bgv.relinearize or ckks.relinearize depending on the scheme.

Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
inputany type

Results:

ResultDescription
outputany type