Ethash Kernel¶
Ethash is a consensus algorithm for cryptocurrency on Ethereum, using proof of work. Ethash also uses Keccak, a hash function that has been standardized as SHA-3. But Ethash and SHA-3 are not the same, and the two should not be confused. Ethash has been designed to resist ASICs. The main method is to increase the load of memory through a large number of random table lookups, and ASICs can no longer use dedicated circuits to accelerate.
Ethash uses a DAG dataset with an initial value of 1GB and a fake random number table cache with an initial value of 16MB. Their contents are recalculated every 30,000 blocks. This interval of 30,000 blocks is called For epoch. The content generated by each epoch will increase, so 1GB and 16MB are just initial values. For 1 Ethash calculation, Ethash need to randomly 64 times from DAG dataset. The first access’s address is determined by Keccak result of header and nonce, the other 63 access’s addresses are determined by the previous access result. Such dependency increase latency of single hash calculation.
So improve the performance, we do Ethash calculation in a batch mode. We’ll start the first round of DAG dataset access of the whole batch, which are independent from each other. Then start the second round, third round until all 64 rounds are finished. Each kernel will then enable to create DAG access request without most dependency. To improve bandwidth utilization, we spread the DAG dataset across all 32 HBM channels. More specifically, we cut 32 HBM channels to 4 group of 2GB memory space. Kernel will distribute its access across 4 group. Within each group, we use RAMA IP to improve random acess efficiency.
DAG Gen Kernel¶
The DAG dataset is generated from a cache dataset. Ethereum mining software will get this cache dataset ready. The DAG generation kernel. The DAG generation algorithm is also inter-dependent, but the cache dataset is much smaller than DAG dataset. We implement 16 copies of processing unit. Each will occupy 1 HBM channel, for both read and write. DAG gen is not the critical part of mining, this kernel is only to reduce CPU workload.