GPU mining strategies (algorithm) I am currently in the process of creating a fairly simple bitcoin miner for CPU and GPU (for demonstration purposes not for money earning). 

However I am having a little troubling understanding how the GPU miners generally work. Now I do want a fairly simple version of this, but I hope to be able to get one that performs decently (hopefully within 10-30% of normal miners, and definitely faster than CPU version).

In general I would think the strategy you have for executing on the GPU is something like the below. I hope someone could help me out on whether I am doing something completely wrong and give me some pointers towards how you usually do it.


Transfer the binary version of the data to hash to the kernel (I noticed a lot of input arguments to the OpenCL kernels on some of the versions I have seen, I assume this is some sort of optimizations of data transfer)
Now, calculate the double sha256 hash of the data (Is it generally advisable to have a loop checking multiple nonces or just one per kernel?)
Return a result. What is the best way of doing this? Do I check inside the kernel if it is lower than the desired target, do I just return any value and return to the host device to check for validity or how is this generally done? If checking multiple nonces I assume you should keep track of what was the best result during the run.


I do have a general and very basic GPU implementation but it is currently slower than the CPU implementation I have. I do more or less as above where each kernel check several nonces and return the "best" one (i.e. most trailing zeros of the hash (using getwork protocol) ).
Now that bitcoin difficulty is too high to see much output even on a properly configured gpu with the right drivers, running cgminer at > 100 Mhash/s of sha256d, your learning excercise might be better making an sha256d "altcoin" of &lt; 100,000 difficulty.

In terms of strategy, I think that you want to download a "stratum proxy" which preprocesses blocks from "somewhere" to compute a "midstate" which anything runnning cgminer on your LAN can try hashing with lots of nonce values.  I think that "somewhere" could conceivably be some sort of local testcoin full node which you've poked the source code of.  Whilst "somewhere" could also be a usual BTC mining pool, you won't see enough shares to get bitcoin for your gpu programming.

Next I think that you want to set up your gpu pc with correctly installed drivers and cgminer, so that you can see the text in a terminal showing a reasonable hashrate when you run cgminer with your stratum proxy specified.  You might need to open a port number and do some messing like that the first time it is used, and it took me a few days to get that far on linux.

Once you have seen your gpu working with "ordinary" cgminer, you might want to go into the source code of cgminer, but unfortunately that hides most of the inherant parrallelism of the gpu behind the proprietary binary hardware drivers to which it makes some calls.  It may be that those won't let you use more than 1 gpu core for reasons unknown to me.  You can also call cgminer as a multithreaded cpu miner but that is sooo 2010 that it won't do much with bitcoin nowadays.  Hence my hint that an altcoin or home testnetcoin on sha256d might be interesting.