0
$\begingroup$

recently I'm trying to use TFHE library for project(https://tfhe.github.io/tfhe/). In order to accelerate the whole program, I use pthread to make multi thread computation. However, I find that the encryption is getting slower with the number of thread increasing. The program is just using bootsSymEncrypt to encrypt each bit of a number. When I use 2 thread, the average encrypting time of one bit is about 0.04ms; when the number is 4, the encryption time is 0.07ms; when the number is 8, the encryption time is about 0.15ms. That's really strange for me. My machine is 4 cores with 8 threads, i7-9700 with Ubuntu 20.04, could someone help me explain this problem ?Thank you!

$\endgroup$

1 Answer 1

0
$\begingroup$

I am unfamiliar with the TFHE library; however my guess is that its execution time is bounded by DRAM accesses (that is, cache misses) and not by CPU computations (that is, the size of the memory it tries to access doesn't fit within the cache).

If that were the case, then (consistent with what you observed) adding more threads wouldn't speed things up; each thread would spend its time waiting for its turn to make a DRAM access, and having more threads wouldn't make the DRAM any faster.

$\endgroup$
2
  • $\begingroup$ Thank you for your answer. I'm reading a blog "codeproject.com/Articles/5755/…", which focused on the relation about memory and thread. I found that my program is memory-sensitive for the usage of index, and I think what you described is important. Could u tell me more about this problem? $\endgroup$
    – Kao Tou
    Jun 7, 2021 at 10:31
  • $\begingroup$ @Kao Tou: even if my guess is correct, performance of caches is hard to summarize in 600 characters (and is worth studying in detail if you want to understand computer performance). The TL;DR is that the cache is a fast memory that copies recent accesses to main memory (DRAM); if the CPU makes an access that's not in the cache, it's much slower. The largest cache (there are typically several) is shared between cores. If you run multiple threads that stress the cache, accesses by one thread will often throw out the data used by another, slower down the system. This is called thrashing. $\endgroup$
    – poncho
    Jun 7, 2021 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.