A Mining and Machine Learning PC for $500

In my never-ending quest for the “next big thing” in technology, I’ve been dividing my time between cryptocurrency and machine learning. I’m still not sure about the long-term value of Bitcoin and other altcoins, but the tech they’re built on, such as blockchain and smart contracts, is fascinating.

At the same time, it seems like machine learning is set to take over the world. I’ve been working my way through a couple of online data science / machine learning / deep learning courses. I’m particularly interested in learning more about TensorFlow, Google’s machine learning library.

In order to speed up processing with TensorFlow, I decided to build a PC with a decent graphics card. When I’m not using this PC to run machine learning programs, I could use the video card to mine a few altcoins. Finally, worst case scenario, if both of these technologies fail I’ll have a decent computer for gaming.

The Hardware

My first step was finding a video card. TensorFlow uses the CUDA Toolkit from NVIDIA so that seemed like a good place to start. I also knew that to mine Ethereum, I needed at least 4GB of memory on the card. With that in mind, I ended up choosing the EVGA GeForce GTX 1050ti Video Card for $157.99. Not exactly top-of-the-line, but good enough to get started on a budget.

Now I needed a PC to hold this card. Again, I was trying to go cheap so I looked into refurbished computers. There’s an off-lease, refurbished computer store near my house. I was able to pick up a Dell computer there with a keyboard, mouse, and monitor for about $350.

I went with the Dell Optiplex 7010. The 3.2 GHz i5 processor is plenty fast for my needs, and the mini-tower case provides plenty of room for the video card. I also bought a TP-Link N150 USB Wireless Adapter since this computer didn’t have built-in wireless.

The Software

The computer came with Windows 10 (which is actually not terrible), but I knew I wanted to run Linux for my purposes. So, I shrank the primary partition on the hard drive and downloaded a copy of Ubuntu Desktop 16.04.3 LTS and created a bootable USB flash drive.

There are already plenty of resources online explaining how to set up a dual-boot Windows / Ubuntu system so I won’t cover that here. Let me know if you run into trouble and I’ll try to point you in the right direction.

Once Ubuntu is installed, make sure the video card is using the proprietary drivers. The open-source drivers won’t cut it for mining or machine learning. To check, go to System Settings, then Software & Updates, and click the Additional Drivers tab. After the tab loads, you should see that your video card is using the NVIDIA binary driver. If not, select it and click the Apply Changes button.

Ethereum Mining

Now that the operating systems are installed, I was ready to start setting up the rest of the software. I decided to test mining first. You can’t mine Bitcoin on a regular computer, so it was out of the question, but you can mine Ethereum.

With that in mind, first install Ethereum. This is easy to do on Ubuntu using the Ethereum PPA (Personal Package Archive). These instructions are from the Go Ethereum Wiki. First, open a terminal and enter these commands:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

This adds the Ethereum PPA to your system, updates the list of available packages, and installs the Ethereum software. Once that’s complete, enter the following command to create a new Ethereum account:

geth account new

Be sure to write down your password and keep it in a safe place. This account holds all of your ether. Without the password you won’t be able to access your money. Also, make a note of your address. That’s the number returned by the command between curly braces.

Now it’s time to install the miner. There are several choices for mining on the Ethereum network. After trying a few different options, I chose Claymore.

First, download the Claymore Dual Miner v10.0 from their releases page on GitHub. Make a new directory named claymore for the miner inside your home directory. Now move the downloaded file from your Downloads directory to the claymore directory and extract it by double clicking it.

Rather than try to mine solo, I decided to join a mining pool. Again, there are many choices available, but after some research I went with nanopool.org. Their 1% fee seemed reasonable, and you can get payouts after mining as little as 0.05 ether.

The nanopool.org getting started guide includes instructions for setting up Claymore on Linux. After correcting a few typos everything worked perfectly. First, I replaced the contents of the file start.bash with this:

export GPU_FORCE_64BIT_PTR=0
export GPU_MAX_HEAP_SIZE=100
export GPU_USE_SYNC_OBJECTS=1
export GPU_MAX_ALLOC_PERCENT=100
export GPU_SINGLE_ALLOC_PERCENT=100

~/claymore/ethdcrminer64 -epool eth-us-east1.nanopool.org:9999 -ewal 0xa375d885105db5df1f2452ef9e347f261eb3f690/Atone01/me@anthonylewis.com -mode 1

The number starting with 0xa375... is my Ethereum address. You should replace this with your own, unless you want me to get all the ether you mine. Following that is my worker name and then my email address. nanopool.org will use this to email you if your worker goes. It’s also used as a password to update settings.

Next, update the file epools.txt to setup failover servers:

POOL: eth-eu1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-eu2.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-us-east1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-us-west1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0
POOL: eth-asia1.nanopool.org:9999, WALLET: 0xa375d885105db5df1f2452ef9e347f261eb3f690.Atone01/me@anthonylewis.com, PSW: x, WORKER: , ESM: 0, ALLPOOLS: 0

The format is similar to start.bash but slightly different. These servers will be used if the server you entered in start.bash goes down.

Now that these files are updated, you can open a terminal and start the miner by entering this command:

~/claymore/start.bash

The command will first build a DAG on your video card which takes a few seconds, then it will start getting jobs from nanopool.org and attempting to mine ether. Occasionally, you will see text in green on your terminal that says “SHARE FOUND” and then “Share accepted”. This means your mining worked and you just earned a little ether.

You can see my results by looking at my worker on nanopool.org. At around 12 Mh/second I’m certainly not going to get rich off of this miner, but $10-15 USD per month is better than nothing. It’s not often that I actually get paid to learn about a new technology.

Machine Learning with TensorFlow

Now that Ethereum mining is working, I moved on to installing TensorFlow. The TensorFlow website has great documentation for Installing TensorFlow on Ubuntu, but there a few gotcha’s in the documentation.

Install NVIDIA Requirements

The first requirement for using TensorFlow with a GPU is the CUDA Toolkit from NVIDIA. The current required version is 8.0, but the latest version on NVIDIA’s site is 9.0. TensorFlow currently will not work with the latest version.

Once I had the versions worked out, CUDA is easy to install. The first step is to add the CUDA repository to your system. Rather than doing it manually as with Ethereum, CUDA provides a .deb package to do this for you.

You can download the base installer by going to CUDA Toolkit 8.0 Download Page and answering a few questions, or skip the questions and click this link to get the CUDA Repo for Ubuntu 16.04.

Once you download the file, open a terminal, go to the Downloads directory, and enter these commands:

sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

The next requirement is the CUDA Deep Neural Network library. This download requires a membership in the NVIDA Developer Program. Thankfully, it’s free. Go to the cuDNN Download page, and signup or login as required.

Click to expand the section labeled “Download cuDNN v6.0 (April 27, 2017), for CUDA 8.0”. In that section are three .deb files to download for Ubuntu 16.04:

  1. cuDNN v6.0 Runtime Library for Ubuntu16.04
  2. cuDNN v6.0 Developer Library for Ubuntu16.04
  3. cuDNN v6.0 Code Samples and User Guide for Ubuntu16.04

After downloading those three files, open a terminal, go to the Downloads directory, and enter these commands:

sudo dpkg -i libcudnn6_6.0.20-1+cuda8.0_amd64-deb
sudo dpkg -i libcudnn6-dev_6.0.20-1+cuda8.0_amd64-deb
sudo dpkg -i libcudnn6-doc_6.0.20-1%2Bcuda8.0_amd64-deb

Finally, install the NVIDIA CUDA Profile Tools Interface:

sudo apt-get install libcupti-dev

Now that CUDA is installed, edit the ~/.profile file to update the PATH and LD_LIBRARY_PATH environment variables with new paths. The last two lines of the file should look something like this:

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:/usr/local/cuda/bin:$PATH"

# add CUDA to LD_LIBRARY_PATH
export LD_LIBRARY_PATH="/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"

If you’ve been following along, just add /usr/local/cuda/bin between colons to the PATH, and add the line with export LD_LIBRARY_PATH=... at the end of the file.

Install TensorFlow

With all of the NVIDIA requirements in place, it’s finally time to install and test TensorFlow. I decided to use the recommended virtualenv installation method.

First, install pip and virtualenv for Python 3 with this command:

sudo apt-get install python3-pip python3-dev python-virtualenv

Once the installation is done, create a virtualenv for TensorFlow with this command:

virtualenv --system-site-packages -p python3 ~/tensorflow

Then activate the newly created virtualenv.

source /tensorflow/bin/activate

The prompt should now start with (tensorflow). Remember to activate this virtualenv every time you want to work with TensorFlow.

Now ensure that pip is installed inside the virtualenv:

easy_install -U pip

And finally, install TensorFlow with GPU support:

pip3 install --upgrade tensorflow-gpu

Note that you don’t need to use sudo in front of the commands inside the virtualenv since these installations only affect the current user.

Now run a short program to verify TensorFlow is working. Launch the python interactive interpreter:

python

Then enter this short program:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If everything is setup correctly, this should simply print Hello, TensorFlow!.

And with that you have a $500 PC ready for learning about Ethereum mining and using TensorFlow for machine learning.