Optimizing GPU performance for cryptocurrency mining using differential evolution
Abstract
Current cryptocurrency market is in its beginnings, develops rapidly and offers many opportunities. The article focuses on a special case where the application of evolutionary optimization leads to a direct and immediate significant increase in financial earnings. The following text presents the implementation of differential evolution for the optimization of operational frequencies of graphics cards, which are utilized to mine scrypt or X11 based cryptocurrencies.
Full text
OPTIMIZING GPU PERFORMANCE FOR CRYPTOCURRENCY MINING USING DIFFERENTIAL EVOLUTION Tomas Panacek Edmund Kmet Brno University of Technology Brno University of Technology Institute of Automation and Computer Science Computer and Information Services Centre Technicka 2, Brno Antoninska 548/1, Brno Czech Republic Czech Republic [email protected] [email protected] Abstract: Current cryptocurrency market is in its beginnings, develops rapidly and offers many opportunities. The article focuses on a special case where the application of evolutionary optimization leads to a direct and immediate significant increase in financial earnings. The following text presents the implementation of differential evolution for the optimization of operational frequencies of graphics cards, which are utilized to mine scrypt or X11 based cryptocurrencies. Keywords: cryptocurrency, Bitcoin, hash rate, GPU, optimization, differential evolution 1 Introduction The first concept of a purely digital currency (so called ”b-money”) was proposed by Wei Dai in 1998 [1]. Ten years later, the first implementation of a cryptocurrency was published [2] and in 2009, the first amount of Bitcoins was created(in a process colloquially called ”mining”) [3] and the first transaction was made [4]. In the beginning Bitcoins were mined on CPUs but with increasing number of Bitcoin users the efficiency of CPU mining was dramatically falling down. This resulted in implementing the computational procedures onto the graphics processing units (GPUs) [6]. Because of relatively high power consumption of GPUs, FPGAs (field programmable gate arrays) and subsequently ASICs (application-specific integrated circuits), were utilized for cryptocurrency mining. On the other side, investing in GPUs is safer, because FPGAs and ASICs have limited use in comparison to GPUs and GPUs can be sold easily. With more ASICs on the network the Bitcoin mining difficulty increased to the level where GPU mining was not profitable mainly because the costs of electricity were higher than the income. This led to development of new digital currencies based on hashing algorithms which are not easily implemented on ASICs. The first alternative cryptocurrency was Litecoin (introduced in 2011) and more ASIC-resistant/GPU-friendly alternatives followed. Nowadays, cryptocurrencies (such as SHA-256-based Bitcoin [2], scrypt-based Litecoin, x11-based Dash and many others) are established alternative media of exchange with total market capitalization in billions of USD (May 2015) [5]. Still, the production of a cryptocurrency depends solely on voluntary users of the cryptocurrency, who run specific hardware on their expenses to produce a cryptocurrency for themselves. Cryptocurrency mining on a standard computer with one or more GPUs, as described in this article, requires a mining software - a ”client” (e.g. freely available software cgminer,sgminer or similar [6] [7]), an Internet connection and a server (a.k.a. ”mining pool” [6]) account. Once connected to a mining pool, the client receives a task to be solved and then returns a solution to the mining pool. The performance of the client in solving such tasks is reported by the client to the user in form of a nominal hash rate in millions of calculated hashes per second (Mhash/s). The client also allows the user to set the operational parameters of the hardware used, such as GPU core and memory frequencies. The following text deals with increasing the performance of mining of alternative cryptocurrencies based on the scrypt or x11 hashing algorithms [7] on GPUs (the explanation of the choice of these algorithms is beyond the scope of this article). 2 The optimization problem Using default values of GPU core and memory frequencies as specified by GPU manufacturer does not provide the maximum hash rate the GPU is capable of, neither does setting these parameters to their maximum values [6] [11] [8]. Each GPU has its ”sweet spot” [6] for a given task, a combination of core and memory frequencies where the hash rate peaks (see fig. 2). These sub-optimal values are in reality often tweaked by modifying already verified values manually or automatically employing more or less sophisticated methods (e.
g. complete enumeration [9] [10]). For an AMD Radeon R290X GPU with core and memory frequency ranging from 700 MHz to 1050 MHz and 900 MHz to 1450 MHz respectively, the number of potential solutions equals to (1050 −700) ×(1450 −900) = 192.500. Considering that one evaluation can take 30 seconds (or more), it is obvious that more sophisticated method of optimization is needed. Let the nominal hash rate be a function of GPU core and memory frequencies: ℎ=𝑓(𝑓𝑐𝑜𝑟𝑒, 𝑓𝑚𝑒𝑚)(1) The aim of the optimization is to maximize ℎwhile the GPU is treated as a black box. 3 Optimizing GPU parameters The optimization method of choice was the Differential evolution algorithm [12]. The algorithm was initialized randomly with parameter values within a safe range determined by trial and error (the core and memory frequencies cannot be too high, otherwise the device ”hangs up” and must be restarted). The size of the population was 20 solutions. Calculation of the value the objective function (1) of a potential solution consisted of the following steps: 1. set values 𝑓𝑐𝑜𝑟𝑒 and 𝑓𝑚𝑒𝑚, 2. wait for a predefined amount time (𝑇𝑠𝑡𝑎𝑏) to stabilize the nominal hash rate, 3. calculate the average value of 𝑁samples of the nominal hash rate over a time interval 𝑇𝑒𝑣𝑎𝑙. The nominal hash rate is a number of hashes generated by the device dependent on the clock speed of the device. The reason behind using the nominal hash rate instead of the amount of cryptocurrency mined is that the amount of cryptocurrency is proportional to the effective hash rate [6]. The effective hash rate is lower than nominal hash rate because of unpredictable phenomena such as network outages, duplicated computations etc. Total time required to evaluate one solution is roughly 𝑇≃𝑇𝑠𝑡𝑎𝑏 +𝑇𝑒𝑣𝑎𝑙.(2) The length of the stabilization time interval 𝑇𝑠𝑡𝑎𝑏 was set to 60 s. The number of samples to calculate the average value was set to 100 and the sampling interval was 100 ms, therefore 𝑇𝑒𝑣𝑎𝑙 = 100 ×0.1 = 10𝑠. Total time needed to evaluate one solution was therefore 𝑇= 60𝑠+ 10𝑠= 70𝑠. The process of evaluation is depicted on fig. 1. Figure 1: An example of the process of fitness calculation. The triangular marks indicate a change in the input parameters 𝑓𝑐𝑜𝑟𝑒 and 𝑓𝑚𝑒𝑚. The example is based on actual data collected during optimization of a single AMD Radeon R280X GPU. The results of optimization of two different GPU models, comparison of performances using default and optimized values are shown in fig. 2. The exact values are summarized in table 1. The optimizer software was implemented on the .NET platform. The optimizer sets parameter values to and reads nominal hash rate from the mining software client via TCP/IP.
4 Conclusion The application of the methods presented here led to increase of the mining performance of two GPU samples, i. e. 12.5 % in case of AMD Radeon 280X and 29.0 % in case of AMD Radeon 290X. The optimized values of 𝑓𝑐𝑜𝑟𝑒 and 𝑓𝑚𝑒𝑚 are not directly applicable on every GPU device from these product lines because of manufacturing tolerances. The advantage of the optimization method described here is that it can by applied onto arbitrary GPU model. Table 1: Optimization results optimizer run 𝑓𝑐𝑜𝑟𝑒 [MHz] 𝑓𝑚𝑒𝑚 [MHz] ℎ[Mhash//s] 280X default 850 1400 0.539 280X optimized 1019 1488 0.700 (+ 29.0 %) 290X default 1000 1250 0.736 290X optimized 877 1374 0.828 (+ 12.5 %) The modified method was succesfully applied to several mining rigs, each consisting of multiple GPUs. The method proved to be functional and contributed to increased yield from cryptocurrency mining. Further works need to include power consumption into fitness calculation to reduce running costs of the mining rig. The optimizer software is available from the author upon request. Figure 2: Maps illustrating relationship between nominal hash rate and GPU core / memory frequencies. Top: a single AMD Radeon R280X GPU. Bottom: a single AMD Radeon 290X GPU. Factory default frequencies are marked with ’o’. Optimized frequencies are marked with ’+’. The maps are based on data collected during optimization. Acknowledgement: This work was partially supported by Brno University of Technology, Faculty of Mechanical Engineering.
References [1] DAI, W. b-money. Available at http://www.weidai.com/bmoney.txt [Online; accessed 10-May-2015] [2] NAKAMOTO, S. Bitcoin: A Peer-to-Peer Electronic Cash System. October 2008. Available at http://bitcoin.org/bitcoin.pdf. [Online; accessed 2-April-2015] [3] Bitcoin Block Explorer. Block 0. Available at http://blockexplorer.com/b/0 [Online; accessed 10-May-2015] [4] Bitcoin Block Explorer. Block 170 - the first Bitcoin transaction. Available at http://blockexplorer.com/b/170 [Online; accessed 10-May-2015] [5] Crypto-Currency Market Capitalizations. Available at http://coinmarketcap.com. [Online; accessed 10- May-2015] [6] KOLIVAS, C. Cgminer mining software. Available at http://ck.kolivas.org/apps/cgminer [Online; accessed 6-April-2015] [7] Sgminer - ASIC and GPU miner based on Cgminer. Available at http://github.com/sgminer-dev/sgminer [Online; accessed 6-April-2015] [8] Bitcoin Forum. Available at http://bitcointalk.org [Online; accessed 6-April-2015] [9] ANDERSSON, R. HashPeak – GPU mining hashrate peak detector. Available at http://rickardandersson.com/hashpeak-gpu-mining-hashrate-peak-detector [Online; accessed 6-April- 2014] [10] WALTON, J. Finding Optimal Clock Speed for CGMiner and R9 290/R9 290X. Available at http://www.holynerdvana.com/2013/12/finding-optimal-clock-speed-for-cgminer.html [Online; accessed 6- April-2015] [11] FOREST, G. Tuning ATI Clock Settings for sgminer/cgminer Available at http://obsoleet.org/resources/dogecoin/tuning.html [Online; accessed 3-April-2015] [12] STORN, R. Differential Evolution for Continuous Function Optimization. Available at http://www.icsi.berkeley.edu/˜storn/code.html [Online; accessed 1-Dec-2014]