Informatics

How to calculate Bitcoins using GPGPU

This blog entry will cover the necessary steps to calculate bitcoins using the GPU of a graphics card (GPGPU).

* Hardware used

    ATI HD 6770 graphics card

* official bitcoin client

    it needs more than 2 GiB of data space, so it is convenient to use a data directory with enough free space.

* pool client: in this case I used “p2pool”

    client is p2pool_win32_3.1/run_p2pool.exe

* the program which calculates bitcoins.

    in this case it is optimized to use GPGPU with OpenCL:
    phoenix-2.0.0/phoenix.exe

* make the graphics card rest inside comfortable temperature values boundaries

    with MSI Afterburner

* additional information


HARDWARE USED

graphics card ATI HD 6770
It’s really an ATI HD 5770 with very little fw modifications:

    40nm 850 GHz core (800:40:16),
    1024 MiB 1200 MHz DDR5, 1360 GFLOPS,
    12.59 GFLOPS/W
    TDP: 18 W idle, 108 W max

Note that GFLOPS values are theoretical maximums: it is just the product of core frequency by the number of cores (ATI’s unified shaders) by two (as the cores can make two operations per cycle over the same data, on ideal conditions, in order to hide the memory access/core frequency great difference).
In this case: 850 MHz * 800 * 2 = 1360 GFLOPS = 1.36 TFLOPS (!)
This value will never be reached in a program, most frequently because data must be retrieved from memory, and this step is much slower than core frequency. There are intermediate caches, but nevertheless data will be typically as massive as the expected data processing speed.


OFFICIAL BITCOIN CLIENT

Download it from its official page.
It needs more than 2 GiB of data space, so it is convenient to use a data directory with enough free space.

Default data and configuration directory in Windows 7 is:

    C:\Users\<user name>\AppData\Roaming

In order to use a different data storage directory, you must indicate it by command line at run time:

    -datadir=”<data directory>”

Program must run on server mode. This way it listens on port 8333.
In theory it is possible to indicate “server=1” on configuration file (bitcoin.conf in data directory: you will have to create it the first time), but it didn’t work for me… so I indicated it also by command line:

    -server

So the command to run is in my case:

    “C:\Program Files (x86)\Bitcoin\bitcoin-qt.exe” -datadir=”D:\Bitcoin” -server

Bitcoin creates a direct access on Windows “Start” Menu in order to run the program on each boot, if you choose this option. This direct access do not have previously command line options, so it is convenient to modify it.

The configuration file (bitcoin.conf in data directory: you will have to create it the first time) must contain the user and password used for the connection with the client program which calculates or manages a pool (these program can be local as in this tutorial, or remote).
It is not important to remember the password because it is used only for communication between the bitcoin client and the program.

One can also indicate the GUI language in this file, if needed.

    rpcuser=BITCOIN
    rpcpassword=thegirlwiththeearring
    lang=en

After running the official bitcoin client for the first time, it will spend several hours (or even days) to download the necessary (all) bitcoin blocks known till that date…
This will exhaust some 2 GiB or more.

Until this process is ended, I think that the program do not accept connections, so the calculation or pool manager program cannot really start working.

In order to speed up the download process, you can preinstall the database at a precedent date: for example, here you can find the database until certain number of blocks were reached. Follow the instructions and you’ll save precious time! Bare in mind that you should use this process only for first-time installations: that is, with an empty wallet. That’s what that site says…


POOL CLIENT: IN THIS CASE I USED “P2POOL”

Download it here.

This program is not strictly necessary, but if it is not used between the (official) bitcoin client and the program which actually makes the calculations, you will only obtain credit after a complete bitcoin block is “discovered”. This will provide 50 BTC. But this task is extremely expensive in computational terms:
at 100 Mega Hash per second (100 MH/s) of calculation power, it will actually take about 2.5 years…
at 170 MH/s of calculation power, it will actually take about 1.5 years…
These are the estimated calculation power of a ATI HD 6770 graphics card.
With a plain computer CPU, it doesn’t matter how advanced, you have to add a zero to the year estimation… I think we can discard the option of a computer draining power for a decade just for… well may be nothing by then.

By associating to a pool, the calculations are distributed between numerous clients, and the credit obtained from each block (50 BTC) is also distributed between the members: the more calculation power you have (respect to the others), the more credit you will receive.
It seems that calculations are divided in such a way that your computer do not calculate all the time for the same block. This is also a good thing because all the maths involved are based on probabilities, so some blocks are harder (take more time to be broken) than others: distributing the effort in more than one leads to a more predictable relation between time or effort implied, and obtained retribution.

In this case, p2pool obtain for itself the 0.5% of the total credit obtained by each client.
But this value can be modified by command line.

This program connects to the pool and also with the (official) bitcoin client, that we have installed in the previous step.

Communications with the bitcoin client use the port 8333 of the bitcoin client (and because of this, it must run on server mode).
The program also listens on port 9332 and 9333. Port 9332 is used for the web REST interface, and port 9333 is used to receive communications from other members of the pool.
One should open port 9333 on the inside direction in the firewall, though I haven’t seen connections, and in fact it can run behind a firewall without problems.

Installation do not require anything but to decompressed the packet inside its definitive directory.
The program require user and password to connect with the bitcoin client: they’re passed as arguments by command line.
One can create a .bat file beside the .exe in order to accomplish this. Following the previous bitcoin client configuration, contents of the .bat should be:

    run_p2pool BITCOIN thegirlwiththeearring

Under .\data\bitcoin you can read the log of the program.

After the program runs, it will try to connect to your bitcoin client on 127.0.0.1:8333 and 127.0.0.1:8332
They will also connect to external clients on remote_ip:8333

p2pool client has a REST interface that generates an interesting statistics web page (it requires SVG and javascript support on the browser), that is accessible on:

    127.0.0.1:9332

It is not very convenient to open this port 9332 in the firewall, as this interface can make such things as send donations to the pool.
A reverse authenticated proxy in front of this port can be used.
This will allow you and only you to see your computer’s bitcoin statistics page on internet.
The easiest way to do this is to use nginx.
After downloading nginx for Windows (the development version always, as it contains the latest security patches, which are important on a service publish on the Internet), decompressed it inside its definitive folder (maybe you don’t want to use “C:\Program Files”, as this location in Windows 7 will not allow nginx to write its own files, which can be very annoying).
After doing this, substitute inside the nginx configuration file:

    conf/nginx.conf

this part:

    location / {
    root html;
    index index.html index.htm;
    }

with this another one:

    location / {
    satisfy all;
    allow 10.0.0.0/8;
    allow 127.0.0.1;
    deny all;
    auth_basic “bitcoin statistics”;
    auth_basic_user_file htpasswd;
    proxy_pass http://127.0.0.1:9332;
    }

Note that if you do not want to restrict access by IP (in this case it allows as an example access to only IPs 10.0.0.0/8 and localhost; modify this values as needed), you can erase the lines from “satisfy all;” to “deny all;”.
The rest of the file set a welcome message, the file where user and password for this proxy are stored (we will see them in a second), and the redirection that nginx will perform aftger granting access.
Now, create inside the nginx “conf” directory a text file with name

    htpasswd

and pairs (or just one pair) of values “user:password” on each line.
Now you can open 80 port on your firewall, if you have a blocking one.

The result will be that by connecting to your computer on http://, and after inserting correct user and password you will see your bitcoin statistics.

nginx runs on Windows just clicking on the exe file.
See http://www.nginx.org/en/docs/windows.html
You can obtain a list of the process with this command-line line:

    tasklist /fi “imagename eq nginx.exe”

In order to reload the configuration file in case you modify it whilst running, you can use:

    nginx -s reload

Other nginx signals:

    nginx -s stop fast shutdown
    nginx -s quit graceful shutdown
    nginx -s reopen re-opening log files

THE PROGRAM WHICH CALCULATES BITCOINS

In this case it is optimized to use GPGPU with OpenCL:

    phoenix-2.0.0/phoenix.exe

Download phoenix2 here.

Previously, it is convenient to install the most actualized graphics card controllers and the OpenCL SDK. Though in my case I made it all run without this last one : I suspect that this was because there exists an already installed OpenCL library installed on all Windows 7 OS.

Installation do not requires anything but to decompress the packet inside its definitive folder.
The configuration file must be created copying the provided doc/example.cfg onto the installation directory with name:

    phoenix.cfg

and modifying it as needed.
First of all, be sure that this file is configured to use OpenCL (GPU) and not the computer CPU:

    autodetect = +cl -cpu

If a bitcoin pool is not used, backend parameter must be configured to connect directly to the (official) bitcoin client, with previously configured user and password (see above):

If using a pool, the port to bind to is 9332, with any user and password:

I had to comment out this line:

    #logfile = False #Set this option to log to a file.

because it logs (erroneously) to a file called “False” :o

With just one graphics card, the configuration to adjust is the one under “[cl:0:0]”.
These parameters must be adjusted to each particular hardware.
With the ATI HD 6770 these changes are good:

    kernel = phatk2 # provides 4-5% more performance

And it is recommended also:

    bfi_int = True
    fastloop = False

“agression” value indicates how much load of work will be send to the graphics card: if the computer is in use it is better to maintain low values as a GPU at 100% of work load implies sudden monitor freezings which are annoying.

    aggression = 3 # for a HD 6770 it’s about ~85% load

If the computer is not in use, it can be greater till 100% of load is reached:

    aggression = 12 # for a HD 6770 it’s 100% load

MAKE THE GRAPHICS CARD REST INSIDE COMFORTABLE TEMPERATURE VALUES BOUNDARIES

With MSI Afterburner.
Download it from its official page here.

“MSI Afterburner” allows graphics card’s memory and GPU downclocking in order not to reach the 100% use and maximum power consumption.
Of course you can also use it to overclock your GPU. But you have to be sure not to exceed safe values, bearing in mind that temperatures must be bore for very long terms of time – 100ºC for an hour may be safe, but who knows how this temperature can affect the GPU after a month…

By default, with agression=12, with ATI HD 6770 GPU at 850 MHz and internal Memory at 1200 MHz (default full load values for this graphics card), ~170 MH/s can be obtained. The sustained GPU temperature can be about 80 ºC.

Downclocking to GPU at 300 MHz and internal memory at 300 MHz, ~100 MH/s can be obtained, with a GPU temperature of about 63-65 ºC.
Of course, this low temperature values are obtained because the energy drown is less than at full capacity.

For downclocking configuration, an undocumented option must be activated.
This obliges to touch the configuration, download ATI libraries eliminated in later versions of its controllers, reboot the program with a parameter, and restart de computer.
Easy.

MSI Afterburner configuration is located here:

    C:\Program Files (x86)\MSI Afterburner\MSIAfterburner.cfg

and in order to maintain it on future upgrades:

    C:\Program Files (x86)\MSI Afterburner\Profiles\MSIAfterburner.cfg

In Windows 7, you will have to copy it to another place (files cannot be modified inside Program Files folders), modify it, and overwrite the original one acknowledging the warning about administration permissions needed.
The lines are (copy then exactly as they are here, and btw they’re two lines, not three… the first one is someway long; overwrite these options if they already exist in the file, or add the at the end otherwise):

    UnofficialOverclockingEULA=I confirm that I am aware of unofficial overclocking limitations and fully understand that MSI will not provide me any support on it
    UnofficialOverclockingMode= 1

Now, the strange ATI libraries are these ones:

    atipdl64.dll 414 KiB
    atipdlxx.dll 352 KiB

I found then here, but I suppose they can be obtained elsewhere at forums or similar places:

Now, start MSI Afterburner from command line with this option:

    -xcl

Close it and restart the computer.

After MSI Afterburner is started again, you can lower GPU and internal memory frequency values: do so till you reach the minimum allowed value. Now, close the program and run it again so it will allow you to low then a little bit more. Repeat as necessary until desired values are reached.

If it do not allow the values to be modified, go to “Settings” and change the mode from “user” to “kernel”.

One should be able to store the achieved settings in MSI Afterburner profiles in order to be able to easily retrieve them in the future, but I wasn’t able to make this characteristic run…
I was not also able to change the core’s voltage. I suspect this is because of a hardware restriction imposed by ATI on new graphics cards.
It is not necessary to let the program running in order for the limits to remain.

More info about these steps here:
http://forums.guru3d.com/showthread.php?t=338906
http://forums.guru3d.com/showthread.php?t=359671
http://forums.guru3d.com/showthread.php?t=359671&page=2


ADDITIONAL INFORMATION

http://en.wikipedia.org/wiki/Bitcoin
https://bitcointalk.org/index.php?topic=9430.0

Bitcoin Calculator:
http://tpbitcalc.appspot.com/

Mining hardware Comparison
https://en.bitcoin.it/wiki/Mining_hardware_comparison

How to get started using your GPU to mine for Bitcoins on Windows
http://www.newslobster.com/random/how-to-get-started-using-your-gpu-to-mine-for-bitcoins-on-windows

bitcoin mining continued: radeon 5770
http://www.smpake.com/?p=59

Bitcoin Mining
http://deepflash.blogspot.com.es/2011/09/bitcoin-mining.html

Running Bitcoin
https://en.bitcoin.it/wiki/Running_Bitcoin#Start_automatically

[400GH/s] p2pool: Decentralized, DoS-resistant, Hop-Proof pool
https://github.com/forrestv/p2pool
http://u.forre.st/u/obkyymtw/p2pool_win32_3.1.zip
https://bitcointalk.org/index.php?topic=18313.0
https://bitcointalk.org/index.php?topic=18313.msg968972#msg968972
https://en.bitcoin.it/wiki/P2Pool
https://en.bitcoin.it/wiki/Pooled_mining

Phoenix – Efficient, fast, modular miner
https://bitcointalk.org/?topic=6458.0
https://bitcointalk.org/index.php?topic=75786
https://bitcointalk.org/index.php?topic=25860.0

python OpenCL bitcoin miner
https://bitcointalk.org/?topic=1334.0

Enable unofficial overclocking after Catalyst 12.2
http://forums.guru3d.com/showthread.php?t=359671&page=2

What’s the best CPU miner and how do I run it in Windows 7?
https://bitcointalk.org/index.php?topic=15907.0

To explore the bitcoins obtained or transferred by some user:
http://blockexplorer.com/address/<~31 digits identifier>
for example:
http://blockexplorer.com/address/18b7hZvfGQ6B9chxezn2W1D5pyqGcW8pAn

Transactions made with some bitcoin block can be explored; for example:
http://blockexplorer.com/block/00000000000000af130d565291ba49208c546685c69b48a293aaf06387fc22ef
http://blockexplorer.com/b/192000

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s