Standard Batch ANN Controller (Multithreaded)

The primitives of FHEONANNStandardBatchController evaluated by worker threads.

class FHEONANNStandardBatchThreadedController : public FHEONANNStandardBatchController

The primitives of FHEONANNStandardBatchController evaluated by worker threads.

Same functions, arguments, rotation keys and results as FHEONANNStandardBatchController (key generators and masks are inherited); the primitives below are reimplemented with threads (FHEONANNStandardBatchThreadedController.cpp): input and output channels of the convolutions and shortcuts, channels of the poolings, ReLUs and additions, outputs and images of the linear layers and the input channels of the converters. The workers are capped by setWorkerThreads(n) or —threads (0 = all hardware threads); OpenFHE parallelizes inside every operation as well, so —threads trades speed for memory.

Public Functions

inline FHEONANNStandardBatchThreadedController(CryptoContext<DCRTPoly> ctx)
inline void setWorkerThreads(int numThreads)
inline int getWorkerThreads() const
vector<Ctext> he_batch_convolution(FHEONHEController &fheonHEController, vector<Ctext> &encryptedInputs, vector<vector<vector<vector<vector<double>>>>> &rawKernelData, vector<vector<double>> &rawBiasData, int batchSize, int inputWidth, int inputChannels, int outputChannels, int kernelWidth, int padding = 0, int stride = 1)
vector<Ctext> he_batch_convolution_optimized(FHEONHEController &fheonHEController, vector<Ctext> &encryptedInputs, vector<vector<vector<vector<vector<double>>>>> &rawKernelData, vector<vector<double>> &rawBiasData, int batchSize, int inputWidth, int inputChannels, int outputChannels, int stride)

Multithreaded primitives of the standard batch ANN controller.

Every primitive computes exactly what FHEONANNStandardBatchController computes, with the same rotation keys: the input and output channels, the channels of the poolings and ReLUs and the outputs and images of the linear layers are processed by worker threads (run_parallel_for in Utils.h, at most worker_thread_limit or &#8212;threads).

vector<Ctext> he_batch_convolution_shortcut_optimized(FHEONHEController &fheonHEController, vector<Ctext> &encryptedInputs, vector<vector<vector<double>>> &rawKernelData, vector<vector<double>> &rawBiasData, int batchSize, int inputWidth, int inputChannels, int outputChannels, int stride)
vector<Ctext> he_optimzed_batch_avgPool(vector<Ctext> &encryptedInputs, int batchSize, int inputWidth, int inputChannels, int kernelWidth, int stride = 2)
vector<Ctext> he_batch_globalpool(vector<Ctext> &encryptedInputs, int batchSize, int inputWidth, int inputChannels, int kernelWidth, int rotatePositions)
Ctext he_batch_linear(Ctext &encryptedInput, vector<Ptext> &weightMatrix, Ptext &baisInput, int batchSize, int inputSize, int outputSize, int rotatePositions = 100)
Ctext he_batch_linear_memory_efficient(Ctext &encryptedInput, vector<Ptext> &weightMatrix, Ptext &baisInput, int batchSize, int inputSize, int outputSize, int rotatePositions = 100)
vector<Ctext> he_batch_linear_multiple_outputs(Ctext &encryptedInput, vector<Ptext> &weightMatrix, Ptext &baisInput, int batchSize, int inputSize, int outputSize)
vector<Ctext> he_batch_relu(vector<Ctext> &encryptedInputs, vector<int> scaleValues, int inputChannels, int vectorSize, int polyDegree = 59)
Ctext he_batch_inputs_converter(vector<Ctext> &encryptedInputs, int batchSize, int inputChannels, int inputWidth, int baseIndex = 64)
Ctext he_batch_inputs_converter_memory_efficient(vector<Ctext> &encryptedInputs, int batchSize, int inputChannels, int inputWidth, int baseIndex = 64)
vector<Ctext> he_batch_sum_ciphertexts(vector<Ctext> &firstEncryptedInputs, vector<Ctext> &secondEncryptedInputs, int inputChannels)
vector<Ctext> he_batch_linear_packed(vector<Ctext> &encryptedInputs, const vector<vector<double>> &weightData, vector<Ptext> &biasInputs, const vector<Ptext> &masks, int inputsPerBlock, int outputsPerBlock, int poolSize = 1)
vector<Ctext> he_batch_convolution_optimized(vector<Ctext> &encryptedInputs, vector<vector<vector<Ptext>>> &kernelData, vector<Ptext> &biasInputs, int batchSize, int inputWidth, int inputChannels, int outputChannels, int stride = 1)
vector<Ctext> he_batch_convolution_optimized(FHEONHEController &fheonHEController, vector<Ctext> &encryptedInputs, vector<vector<vector<vector<vector<double>>>>> &rawKernelData, vector<vector<double>> &rawBiasData, int batchSize, int inputWidth, int inputChannels, int outputChannels, int stride)

Perform an optimized secure convolution layer evaluation on batched encrypted data.

This function computes a convolution layer over multiple input channels for batched data under homomorphic encryption. It is optimized for the special case where stride = 1, kernel size = 3, and padding = 1, but also supports larger strides by applying striding across multiple channels simultaneously (multi-channel approach), improving efficiency for deep FHE-based networks.

For each output channel, the function multiplies input ciphertexts by the corresponding plaintext convolution kernels, sums contributions from all input channels, applies bias, and rotates/aggregates results across batches to produce the final output.

Note

  • This function assumes ciphertext packing follows contiguous layout: [batch0: channel_i feature map][batch1: channel_i feature map]…

  • Multi-channel striding is used to reduce the number of rotations and multiplications, making it efficient for FHE-based CNNs with multiple input channels.

Parameters:
  • encryptedInputs – Vector of ciphertexts, one per input channel, each encoding batched feature maps of size (batchSize × inputWidth × inputWidth).

  • batchSize – Number of batches encoded in the input ciphertexts.

  • inputWidth – Width (and height) of the input feature maps (assumed square).

  • inputChannels – Number of input channels.

  • outputChannels – Number of output channels.

  • stride – stride length used for the convolution operation.

  • fheonHEController – HE controller that encodes the kernels (encode_kernel_optimized) at the level of the rotated inputs.

  • rawKernelData – Kernel weights [outputChannel][inputChannel][batch][3][3], repeated over the batch (UtilsBatchData::load_batch_weights).

  • rawBiasData – Bias values [outputChannel][batch * outputWidth^2] (UtilsBatchData::load_batch_bias).

Returns:

vector<Ctext> Vector of ciphertexts containing the encrypted results of the convolution layer, one ciphertext per output channel, with batch data packed contiguously: [batch0 output channel_i][batch1 output channel_i]…

vector<Ctext> he_batch_convolution_shortcut_optimized(vector<Ctext> &encryptedInputs, vector<vector<Ptext>> &kernelData, vector<Ptext> &biasInputs, int batchSize, int inputWidth, int inputChannels, int outputChannels, int stride)
vector<Ctext> he_batch_convolution_shortcut_optimized(FHEONHEController &fheonHEController, vector<Ctext> &encryptedInputs, vector<vector<vector<double>>> &rawKernelData, vector<vector<double>> &rawBiasData, int batchSize, int inputWidth, int inputChannels, int outputChannels, int stride)

Perform a secure convolution operation on batched encrypted data.

This function implements a convolutional layer in the encrypted domain using homomorphic encryption for batched inputs. Given a set of encrypted input feature maps, convolution kernels, and bias terms, it computes the convolution across multiple channels and batches while respecting the specified input dimensions, kernel size, padding, and stride.

For each output channel, the function multiplies rotated input ciphertexts by corresponding kernel weights, sums contributions from all input channels, applies the bias, and aligns outputs across batches using rotations and packing strategies. The result is one ciphertext per output channel, encoding all batches contiguously.

Note

  • This function assumes ciphertext packing follows contiguous layout: [batch0: channel_i feature map][batch1: channel_i feature map]…

  • Multi-channel striding is used to reduce the number of rotations and multiplications, making it efficient for FHE-based CNNs with multiple input channels.

Parameters:
  • encryptedInputs – Vector of ciphertexts, one per input channel, each encoding batched feature maps of size (batchSize × inputWidth × inputWidth).

  • batchSize – Number of batches encoded in the input ciphertexts.

  • inputWidth – Width (and height) of the input feature maps (assumed square).

  • inputChannels – Number of input channels.

  • outputChannels – Number of output channels.

  • stride – stride length used for the convolution operation.

  • fheonHEController – HE controller that encodes the 1x1 weights (encode_input) at the level of each input.

  • rawKernelData – 1x1 weights [outputChannel][inputChannel][batch * inputWidth^2], every weight broadcast over its channel.

  • rawBiasData – Bias values [outputChannel][batch * outputWidth^2].

Returns:

vector<Ctext> Vector of ciphertexts containing the encrypted results of the convolution layer, one ciphertext per output channel, with batch data packed contiguously: [batch0 output channel_i][batch1 output channel_i]…