I tried to study source of both xmr-stak
and xmrig
to understand how it communicates with the kernel running on GPU, but both these softwares are too huge to understand (too many objects calling each other and various data passing between them).
I can have several GPU devices and each runs several threads which performs several calculations at the same time, right?
I know the software "communicates" with GPU by writing/reading some shared memory segments. So it writes the input hash (job blob from pool) to each GPU. I assume it somehow divides the whole 32-bit nonce between all the devices and threads, but how?
I have found this in minethd.h of older xmr-stak-amd:
// We use the top 8 bits of the nonce for thread and resume
// This allows us to resume up to 64 threads 4 times before
// we get nonce collisions
// Bottom 24 bits allow for an hour of work at 4000 H/s
inline uint32_t calc_start_nonce(uint32_t resume)
{ return (resume * iThreadCount + iThreadNo) << 24; }
I didn't find anywhere what is resume
(or ResumeCnt
)? Does the miner delegate ranges of nonce in batches? Or it gives them only once when new job from pool is received? (And hopes as per the comment above that it will receive another job earlier than 1 hour to avoid nonce collisions?) If in batches, how does the GPU tell the miner it needs a new range to work on?
Then for the results, the miner thread just periodically checks the shared mem if GPU has put some winning nonces there?
Also does the GPU perform all the calculations or some parts are done by CPU? I assume to be able to check if the result is above target, the GPU needs to finish the whole calculation.