In GPU scrypt mining, the optimized threshold of lookup gap is 2. It means the GPU only saves 0, 2, 4, ..., etc to GDDR (global memory of GPU) and reduce huge amount of time of saving all 128KB data for one scrypt calculation. However, it needs some GPU cycles to re-compute for the elements if the algorithm needs data in the index of 1, 3, 5, ... And remixing those 1024 elements also takes GPU cycles. In the GPU architecture, the hardware scheduler will help to hide the latency of memory read/write. So, the GPU cycles are not wasted.
One of the inefficient part is the parallelized processing with conditional code. For a wave-front or stream processor to compute n-dimension at once, not every core needs and computes the values of odd index of elements. So some cores must be masked as off and they are wasted.
if (j & 1)
salsa(...);
When GPU computes N
elements at once, then every variable j
of different thread could be even or odd. So only the thread which has odd number in j
needs to run the code salsa
first. There is only one shared program counter in the compute unit, so every thread runs the same code. But for those threads that don't need the to do salsa
agin, those processors are being masked off like they are not running and compute the code.
So, in the GPU programming manual, it tells you the following is inefficient.
if (A)
B = 0;
else
B = 1;
Then the GPU needs to run the code twice. One is for the true condition and another is for the false condition.
It's better to re-write the code as follows.
B = A ? 0 : 1;
However, in scrypt, salsa is not a simple expression can do like this way.