# No acceleration on Intel HEXL AVX512

**URL:** https://openfhe.discourse.group/t/no-acceleration-on-intel-hexl-avx512/783
**Category:** OpenFHE Hardware Acceleration
**Created:** [August 25, 2023, 12:31pm UTC](https://openfhe.discourse.group/t/no-acceleration-on-intel-hexl-avx512/783 "2023-08-25T12:31:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![miiip](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@miiip](https://openfhe.discourse.group/u/miiip)
#### Post date: [August 25, 2023, 12:31pm UTC](https://openfhe.discourse.group/t/no-acceleration-on-intel-hexl-avx512/783/1 "2023-08-25T12:31:43Z")

</div>

Hi all,

I’m trying to perform benchmarking for comparison operations using a m6i.metal backend with AVX512. I followed the guide from [here](https://github.com/openfheorg/openfhe-hexl) to build and install OpenFHE. The only difference is that I modified the [vars.sh](https://github.com/openfheorg/openfhe-configurator/blob/main/scripts/vars.sh) where I set the OpenFHE version to v1.1.1.

Here is my code:

```auto
#include "openfhe.h"
#include "binfhecontext.h"
#include <vector>
#include <random>
#include <thread>
#include "openfhecore.h"
#include <pthread.h>
using namespace lbcrypto;

std::vector<double> GenerateRandomVector(size_t size, double minVal, double maxVal) {
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_real_distribution<double> dis(minVal, maxVal);

    std::vector<double> randomVector;
    randomVector.reserve(size);

    for (size_t i = 0; i < size; ++i) {
        double randomValue = dis(gen);
        randomVector.push_back(randomValue);
    }

    return randomVector;
}

void ComparisonTest() {

    TimeVar t;
    double processingTime(0.0);
    ScalingTechnique scTech = FIXEDAUTO;
    uint32_t multDepth = 17;
    if (scTech == FLEXIBLEAUTOEXT)
        multDepth += 1;

    uint32_t scaleModSize = 50;
    uint32_t firstModSize = 60;
    uint32_t ringDim = 65536;
    SecurityLevel sl = HEStd_128_classic;
    BINFHE_PARAMSET slBin = STD128;
    uint32_t logQ_ccLWE = 25;
    uint32_t slots = 16; // sparsely-packed
    uint32_t batchSize = slots;

    CCParams<CryptoContextCKKSRNS> parameters;
    parameters.SetMultiplicativeDepth(multDepth);
    parameters.SetScalingModSize(scaleModSize);
    parameters.SetFirstModSize(firstModSize);
    parameters.SetScalingTechnique(scTech);
    parameters.SetSecurityLevel(sl);
    parameters.SetRingDim(ringDim);
    parameters.SetBatchSize(batchSize);
    parameters.SetSecretKeyDist(UNIFORM_TERNARY);
    parameters.SetKeySwitchTechnique(HYBRID);
    parameters.SetNumLargeDigits(3);

    CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);

    // Enable the features that you wish to use
    cc->Enable(PKE);
    cc->Enable(KEYSWITCH);
    cc->Enable(LEVELEDSHE);
    cc->Enable(ADVANCEDSHE);
    cc->Enable(SCHEMESWITCH);

    // Generate encryption keys.
    auto keys = cc->KeyGen();

    // Step 2: Prepare the FHEW cryptocontext and keys for FHEW and scheme switching
    auto FHEWparams = cc->EvalSchemeSwitchingSetup(sl, slBin, false, logQ_ccLWE, false, slots);

    auto ccLWE = FHEWparams.first;
    auto privateKeyFHEW = FHEWparams.second;
    ccLWE.BTKeyGen(privateKeyFHEW);

    cc->EvalSchemeSwitchingKeyGen(keys, privateKeyFHEW);

    // Set the scaling factor to be able to decrypt; the LWE mod switch is performed on the ciphertext at the last level
    auto modulus_LWE = 1 << logQ_ccLWE;
    auto beta = ccLWE.GetBeta().ConvertToInt();
    auto pLWE2 = modulus_LWE / (2 * beta); // Large precision

    double scaleSignFHEW = 1.0;
    const auto cryptoParams = std::dynamic_pointer_cast<CryptoParametersCKKSRNS>(cc->GetCryptoParameters());
    uint32_t init_level = 0;
    if (cryptoParams->GetScalingTechnique() == FLEXIBLEAUTOEXT)
        init_level = 1;
    cc->EvalCompareSwitchPrecompute(pLWE2, init_level, scaleSignFHEW);

    std::vector<double> x1 = GenerateRandomVector(slots, -8, 8);
    Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(x1, 1, 0, nullptr, slots);
    auto ciphertexts1 = cc->Encrypt(keys.publicKey, ptxt1);

    std::vector<double> x2 = GenerateRandomVector(slots, -8, 8);
    Plaintext ptxt2 = cc->MakeCKKSPackedPlaintext(x2, 1, 0, nullptr, slots);
    auto ciphertexts2 = cc->Encrypt(keys.publicKey, ptxt2);

    TIC(t);
    auto ciphertextResult = cc->EvalCompareSchemeSwitching(ciphertexts1, ciphertexts2, slots, slots);

    processingTime = TOC(t);
    std::cout << "Comparison DONE in " << processingTime / 1000.0 << " (seconds)" << std::endl;

}
int main() {

    ComparisonTest();

    return 0;
}

```

When I run the code on my laptop without hw acceleration I get 44 seconds. When I run the code on the aws machine with AVX512 and OpenFHE compiled with HEXL I get 46 seconds.

Why do I get the same result on an ordinary laptop with 24 cores and no hw acceleration as on a production machine with 128 cores and AVX512?

Thank you!

---

<div class="post-metadata">

### Author: ![pascoe](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@pascoe](https://openfhe.discourse.group/u/pascoe)
#### Post date: [August 28, 2023, 8:05pm UTC](https://openfhe.discourse.group/t/no-acceleration-on-intel-hexl-avx512/783/2 "2023-08-28T20:05:10Z")

</div>

Hi Mihail, the version of openfhe-hexl you were using is only compatible with OpenFHE v0.9.2. An updated version of openfhe-hexl that is compatible with OpenFHE v1.1.1 was pushed earlier today.

---

<div class="post-metadata">

### Author: ![miiip](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@miiip](https://openfhe.discourse.group/u/miiip)
#### Post date: [September 1, 2023, 8:05pm UTC](https://openfhe.discourse.group/t/no-acceleration-on-intel-hexl-avx512/783/3 "2023-09-01T20:05:48Z")

</div>

Hi,

Thank you for your answer. Could you please provide an example of CMake file to build a simple example? It seems that the original [CMake file](https://github.com/openfheorg/openfhe-development/blob/main/CMakeLists.User.txt) doesn’t work:

![image](https://canada1.discourse-cdn.com/flex031/uploads/openfhe/original/1X/cf02b965d5b8078c1220d225dbc4f0f0afa687e2.png)

I tried to solve the error but it seems that HEXL is not installed anywhere.

Thank you!

---

<div class="post-metadata">

### Author: ![miiip](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@miiip](https://openfhe.discourse.group/u/miiip)
#### Post date: [September 3, 2023, 1:41pm UTC](https://openfhe.discourse.group/t/no-acceleration-on-intel-hexl-avx512/783/4 "2023-09-03T13:41:54Z")

</div>

More information here:

> [@Intel HEXL AVX512 Bug](https://openfhe.discourse.group/t/intel-hexl-avx512-bug/789):
>
> Hi, I think there is a bug in the build system. Here are the steps to reproduce it: When I start the building process I am in the /home/ec2-user location (here I run git clone https://github.com/openfheorg/openfhe-configurator.git) Follow the instruction from [here](https://github.com/openfheorg/openfhe-hexl/blob/c228a8e12627304035f44d984e90e07d519ea931/README.md). Once the build is done, cd openfhe-configurator/openfhe-staging/openfhe-development/build/ and then run sudo make install Try to build a simple example like [this](https://github.com/openfheorg/openfhe-development/blob/main/src/pke/examples/simple-real-numbers.cpp) using the standard [CMakeLists.User.txt](https://github.com/openfheorg/openfhe-development/blob/main/CMakeLists.User.txt). You create a folder m…
