Back to Home

Bitcoin: a history of development, from CPU to FPGA / Intel Blog

bitcoin · bitcoin · bitcoin · bitcoins · BTC

Bitcoin: a history of development, from CPU to FPGA


    (photo source)
    Previously, we considered the basic principles that follow when mining bitcoins.
    This time we will consider the history of the development of computing systems designed for bitcoin mining, as well as technological advances and difficulties that encountered along this path.

    CPU: First Generation of Miners


    If you look at the source code of a bitcoin miner, it turns out that it is surprisingly simple. The main part looks something like this:
    while (1)
    {
      HDR[kNoncePos]++;
      IF (SHA256(SHA256(HDR)) < (65535 << 208)/ DIFFICULTY)
        return;
    }
    


    The SHA256 calculation is performed on 512-bit data blocks and includes 64 rounds of encryption, requiring many 32-bit additions, shifts, and bit operations. Each subsequent round of encryption depends on the results of the previous one, creating a chain of dependencies. Although the execution of individual encryption rounds cannot be parallelized, the verification of each individual hash can be performed in parallel, which makes the calculations perfectly parallelizable.
    The performance of such miners reaches 33 MH / s per processor (Core i7 990x). There is nothing more to add.

    GPU: Second Generation of Miners


    In October 2010, the code of the first open-source OpenCL miner was published, after which it was quickly adapted and optimized through the efforts of community enthusiasts. Such miners consisted of implementing a bitcoin protocol in a language like Java or Python and an enumeration algorithm in the form of an OpenCL file, which had to be compiled under the ISA of the corresponding GPU.

    The huge variety of OpenCL implementations was explained by attempts to squeeze out everything that they were capable of from the compilers in pursuit of improving the quality of the code. In addition, a part of the code that was not directly related to OpenCL was responsible for calling the OpenCL API in order to double-check the results or control GPU parameters in response to temperature conditions and user settings.
    Since it was supposed that such equipment would work for months, users would go into hardships playing with the power supply voltage (lowering to reduce the cost of overhead mining costs, or increasing along with the frequency to increase performance), the GPU core, and code parameters such as number of threads. All in order to increase throughput within the framework of reasonable stability and temperature.

    Because Bitcoin mining does not require a special load on RAM or floating-point operations, a large number of critical paths in the electrical circuit or bottlenecks in the GPU architecture do not manifest themselves in any way. However, over time, there might be a need to reconfigure the parameters, as power and cooling systems degrade over time in their performance.
    AMD’s typical GPUs tend to perform better than NVidia’s GPUs for $ GH / s, partly due to the instruction system well suited for SHA256 computing and the VLIW architecture, which contains more ALUs running in parallel, let and at a slightly lower frequency. In particular, shift and bit selection operations can be implemented with a single AMD ISA instruction.
    The integrated graphics, in particular from Intel, already has better performance per watt, but the CPU is characterized by much more modest power budgets - 200W, typical for a GPU, are completely unacceptable for a CPU, which, generally speaking, is not only busy with graphics . In addition, as many CPUs as video cards could be connected to one computer cannot be connected (more on that later). And the depreciation of equipment is not so fast for the CPU. Therefore, the integrated graphics is not the choice of the miner.

    The main code of the miner, written in OpenCL, and not in assembler or in machine codes, after compilation often patched to use GPU instructions that are not directly supported by OpenCL.
    An implementation on OpenCL is one large block of code that first selects a series of parameters based on the id of the stream, and then performs all 64 rounds of hashing in one deployed loop.

    A Datacenter In My Garage


    Having spent $ 300-600 on GPU-based mining equipment, which almost literally prints money, and spent a lot of time setting its parameters, the next step naturally raises the idea of ​​increasing the scale of the computing power disaster .

    Having bought another GPU of the same kind and having repeated the settings, you will double your profit. In fact, if coins are mined so fast and so rapidly growing in price, it may make sense to buy ten or even twenty GPUs! True, this can lead to disaster - due to the group behavior of miners who bought video cards, the difficulty of mining will jump to heaven and the profitability of mining will also rapidly fall. Fortunately, the disaster did not happen, thanks to the growth of the USD / BTC rate, the cost of buying video cards nevertheless paid off.
    GPUs were much more affordable for end users than FPGAs. Using them for mining, although it requires skills in building a PC and reading forums for many hours, you can be a complete layman in parallel programming, not to mention tools for working with FPGA. However, the GPU has several key limitations:
    1. The GPU does not work on its own. Each GPU must be included in an 8x or 16x PCI-E slot, which are relatively few on motherboards.
    2. The motherboard, processor, hard drive and RAM are practically not used in GPU mining, but they increase the cost of the system, i.e. increase the cost of mining per unit of productivity. A typical user has the only PC on hand where you can install 1-2 GPUs, but nothing more.
    3. Each GPU consumes 200-300W, which very quickly exceeds the capabilities of the power supply and requires an upgrade.
    4. Standard cases are not designed to cool multiple GPUs. Especially if the “few” are more than two.
    5. The use of many GPUs quickly reaches the limits of power supply, cooling and noise levels acceptable in most residential areas.
    6. Due to some problems (probably in the software part) of the implementation, OpenCL may require a display to be connected to the GPU. Although the technology itself does not put forward such requirements.
    7. A typical GPU occupies two slots in a PC case, preventing a large number of video cards from connecting to a PC.

    To solve these problems, the following solution appeared. Firstly, because Bitcoin mining does not really use the bandwidth of the interface with the motherboard, then PCI-E 1x has enough bandwidth, and the GPU also works in the 1x slot. A simple cable sold for $ 8 allows you to connect a 16x GPU to a 1x slot. True, this means that the video card cannot be in the PC case, which prompted enthusiasts to create racks designed exclusively for mounting the GPU. Using the right motherboard, with a large number of cheap 1x slots, solved the problem of connecting a large number of GPUs. The abandonment of the familiar housing made it possible to solve the problem of heat removal more efficiently. A resistor, plugged into the DVI connector, successfully simulates a monitor connection, if required for OpenCL.
    Using this approach, one motherboard, CPU, and RAM can serve 5-6 GPUs, thereby increasing the cost-effectiveness of the venture.


    examples of how a GPU-based bitcoin mining machine might look like (photo source)

    Some of these systems can work stably for several months, but then problems with stability become apparent. The reason is that the GPU consumes too much current on the 12V line, overloading the motherboard connector. The solution to this problem is an independent supply of power to video cards, bypassing the motherboard.

    After solving the problems with connecting the GPU, the issues of proper power supply and equipment cooling come to the fore. With the consumption of one GPU in the region of 200W, the specific power of such a system is comparable or even exceeds the performance of data centers. Actually, data centers are almost never used to host GPU miners due to associated costs and equipment certification requirements. Also, few homes are able to provide such electrical power, and various electricity billing schemes can lead to sky-high electricity bills. For these reasons, in practice, mining is most successful in the areas of storage facilities, where there are no big problems with the noise and cooling created, and electricity is available at industrial rates.


    Bitcoin miner containing 69 GPUs (photo source)

    FPGA: Third Generation Miners


    June 2011 brought the public the first open-source bitcoin miner implementation for FPGA. FPGAs are good for both shift operations and bit operations that make up the core of the mining algorithm. An interesting test for developers of FPGA miners was the development of a design that would allow the efficient use of various FPGAs, both hi-end and low-end.

    The solution turned out to be very elegant - the miner consists of several instances of the SHA256 module, which is parameterized by the deployment depth. With full deployment, the module creates separate hardware nodes for each of the 64 rounds of hashing, separated by registers - a kind of pipeline. Such an implementation allows 1h hash / clock / module performance. The shorter deployment depth leads to a shorter pipeline, and a complete hash calculation requires several passes along its steps. If the FPGA is large enough, then several of these pipelines can fit in it. The choice between the depth of deployment and the number of copies of the pipeline is subject to optimization.

    The main problem for FPGA miners was that their power consumption is much higher than for typical cases of using FPGA. This is due to the almost constant activity of logic elements in the process of computing. As a result, most off-the-shelf FPGA boards, such as instructional kits that are easily accessible to students, could not provide either enough power or enough cooling. Moreover, for hi-end chips, the problem was many times more acute.

    As a result, specialized boards appeared that minimized costs by eliminating all excess peripherals (RAM, I / O, etc.), and which were designed for the sole purpose of providing the necessary power and temperature conditions for FPGAs. The Spartan XC6SLX150 FPGA-based motherboards made it possible to achieve a performance of 860MH / s, at a frequency of 215 MHz, an energy consumption of 39W, and a cost of $ 1060. The proprietary development of Butterfly Labs (BFL), located in Kansas, showed similar performance of 830 MH / s at a price of $ 599. The top solution from the same company based on Altera FPGAs showed a performance of 25.2 GH / s at a price of $ 15K (650-750 MH / s per chip).
    To date, BFL has been and remains the most successful commercial bitcoin company.

    Unfortunately, FPGAs were difficult to compete with GPUs - the latter cost ~ 30% less and had greater resale potential after completing their journey as a Bitcoin miner. It did not help that the GPU overtook the FPGA on the ladder of the process technology, often using a more modern and energy-efficient process technology. However, the main advantage of the FPGA is its nearly fivefold gain in power consumption, which makes them as attractive as the GPU, provided they are used for a year or two. In particular, the most advanced FPGAs, for example, those manufactured by Intel for Altera using the latest 22nm and 14nm process technology, are extremely beneficial in terms of power consumption, but have a relatively high price.


    A 500GH / s miner from BFL based on ASIC, surrounded by four FPGA miners at 25.2 GH / s. You can notice two power cables - the miner consumes ~ 2700W. (photo source: James Gibson)

    The FPGA board turned out to be short, because a new generation of hardware, ASIC, was born, giving a gain by orders of magnitude in both energy efficiency and productivity. Efforts to develop FPGAs were not in vain, as Much, from the Verilog description of the miner to the layout of the printed circuit boards, has been reused.

    About ASIC generation - the fourth generation of bitcoin miners, who stepped into the age of custom-made silicon (Age of Bespoke Silicon) next time.

    Read Next