1

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.

1 Answer 1

1

I would study the most up-to-date code for xmr-stak: https://github.com/fireice-uk/xmr-stak

With that codebase, every thread, whether that be a CPU or GPU thread, mines with it's own blob/nonce. The first thread to calculate a valid hash (one who's hash value is below the target) causes the result to be submitted to the pool.

5
  • Yes, I have read that like for 6 hours :) both the cpu and gpu part. I'm mostly interested in how often and in what ranges is the nonce distributed to the individual thread and devices (when I have several GPUs or GPU and CPU both enabled).
    – Marki555
    Commented Jul 11, 2018 at 18:57
  • There is no "nonce distributed". What's important is that each thread is hashing its own blob (which is different per thread because the miner edits the extra space so each blob is unique).
    – jtgrassie
    Commented Jul 17, 2018 at 13:57
  • But the GPU must generate the "unique" blobs itself (increment the nonce internally). It can't wait for the miner after each hash... Miner must somehow tell each GPU card which nonce ranges to use...
    – Marki555
    Commented Jul 17, 2018 at 19:44
  • From pool I get 76bytes of blob and at pos.39 it has space for 4b nonce. How do I construct the blob for each thread?
    – Marki555
    Commented Jul 17, 2018 at 21:10
  • There are many ways to do this. Nonce = thread index, on increment += thread count. That way, every thread has a unique nonce.
    – jtgrassie
    Commented Jul 17, 2018 at 21:21

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.