Such Doge. So Cloud.

Or, how to set up an EC2 box to mine 300 KH/s

So I thought that this DogeCoin was starting to sound more and more interesting, and, having access to some spare CPU cycles in the cloud and not wanting to burn up my Retina MBP GPU, I thought it would be fun to see if I could mine at a decent rate in on Amazon EC2. I started out just doing some CPU mining, but that was not terribly effective (only getting me a few Doge/hr), and since it's fun to play with other people's hardware, I thought this would be fun to explore.

Turns out, I kind of can - it's about 8 minutes to get up and running - read on for detailed walkthrough, or skip to the end for analysis (or just leave if you'd rather do that)...

Instance type

Poking around, it seems that this Amazon Linux AMI with NVIDIA GRID GPU Driver is a good candidate.

So register/sign in with Amazon however you need to and click the Continue button, then just leave the rest of the "Launch with 1-Click" settings alone and you should be set.

Connect however you're going to connect. Walking you through connecting to an EC2 instance is beyond the scope of this, but you should be able to figure it out.

You should update packages...

sudo yum update (select yes when prompted) sudo yum install automake

Download the CudaMiner source code we'll be installing:

[ec2-user@ip-10-51-131-176 ~]$ wget https://github.com/cbuchner1/CudaMiner/archive/master.zip --2013-12-25 11:13:45-- https://github.com/cbuchner1/CudaMiner/archive/master.zip Resolving github.com (github.com)... 192.30.252.129 Connecting to github.com (github.com)|192.30.252.129|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://codeload.github.com/cbuchner1/CudaMiner/zip/master [following] --2013-12-25 11:13:45-- https://codeload.github.com/cbuchner1/CudaMiner/zip/master Resolving codeload.github.com (codeload.github.com)... 192.30.252.146 Connecting to codeload.github.com (codeload.github.com)|192.30.252.146|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 310982 (304K) [application/zip] Saving to: ‘master.zip’ 100%[========================================================================================>] 310,982 --.-K/s in 0.008s 2013-12-25 11:13:45 (37.1 MB/s) - ‘master.zip’ saved [310982/310982] [ec2-user@ip-10-51-131-176 ~]$ ls master.zip [ec2-user@ip-10-51-131-176 ~]$ unzip master.zip Archive: master.zip e47cf1994a3021050bf64521acf6978d3a5c4f27 creating: CudaMiner-master/ ... lots of output ... [ec2-user@ip-10-51-131-176 ~]$ cd CudaMiner-master/ [ec2-user@ip-10-51-131-176 CudaMiner-master]$

Now we've gotten and unzipped the code, let's start trying to build it.

Running naked ./configure fails with a configure: error: Missing required libcurl >= 7.15.2 which is annoying, so let's try autogen instead.

[ec2-user@ip-10-51-131-176 CudaMiner-master]$ ./autogen.sh configure.ac:116: error: possibly undefined macro: AC_MSG_ERROR If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation.

So let's see what else we can glean from what they've given us:

[ec2-user@ip-10-51-131-176 CudaMiner-master]$ cat configure.sh ./configure "CFLAGS=-O3" "CXXFLAGS=-O3" --with-cuda=/usr/local/cuda [ec2-user@ip-10-51-131-176 CudaMiner-master]$ which cuda /usr/bin/which: no cuda in (/opt/nvidia/cuda/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin) [ec2-user@ip-10-51-131-176 CudaMiner-master]$

Well that's unfortunate - it looks like the ./configure.sh script is pointing to the wrong location (for us) for cuda.

Let's fix that:

[ec2-user@ip-10-51-131-176 CudaMiner-master]$ echo ./configure "CFLAGS=-O3" "CXXFLAGS=-O3" --with-cuda=/opt/nvidia/cuda > configure.sh [ec2-user@ip-10-51-131-176 CudaMiner-master]$ cat configure.sh ./configure CFLAGS=-O3 CXXFLAGS=-O3 --with-cuda=/opt/nvidia/cuda [ec2-user@ip-10-51-131-176 CudaMiner-master]$

Trying ./configure.sh now gets further and it errors at:

checking for pthread_create in -lpthread... yes ./configure: line 7109: syntax error near unexpected token `,' ./configure: line 7109: `LIBCURL_CHECK_CONFIG(, 7.15.2, ,'`

So I'll try ensuring I have all my libcurls:

[ec2-user@ip-10-51-131-176 CudaMiner-master]$ sudo yum install libcurl-devel.x86_64

And try again. Nope, same error... But googling around suggests that this may have to do with the line endings - there's a difference between Windows and *nix systems with how they end lines, and this is kind of a common cause of errors, amazingly...

[ec2-user@ip-10-51-131-176 CudaMiner-master]$ sudo yum install dos2unix [ec2-user@ip-10-51-131-176 CudaMiner-master]$ find . -type f -exec dos2unix {} \; [ec2-user@ip-10-51-131-176 CudaMiner-master]$ ./autogen.sh [ec2-user@ip-10-51-131-176 CudaMiner-master]$ ./configure.sh

Success! The output of ./configure is now:

configure: creating ./config.status config.status: creating Makefile config.status: creating compat/Makefile config.status: creating compat/jansson/Makefile config.status: creating cpuminer-config.h config.status: executing depfiles commands

So then now that that's configured I can actually build the thing:

[ec2-user@ip-10-51-131-176 CudaMiner-master]$ make

This dumps TONS of output to the console (including gobs of warnings), and takes a few minutes.

Built!

It looks like the make was successful on the first try, and I have the following output at the end:

ptxas info : Used 32 registers, 336 bytes cmem[0] g++ -O3 -pthread -L/opt/nvidia/cuda/lib64 -o cudaminer cudaminer-cpu-miner.o cudaminer-util.o cudaminer-sha2.o cudaminer-scrypt.o salsa_kernel.o spinlock_kernel.o legacy_kernel.o fermi_kernel.o kepler_kernel.o test_kernel.o titan_kernel.o -lcurl compat/jansson/libjansson.a -lpthread -lcudart -fopenmp make[2]: Leaving directory `/home/ec2-user/CudaMiner-master' make[1]: Leaving directory `/home/ec2-user/CudaMiner-master'

So now you can test it out like so:

./cudaminer -o stratum+tcp://doge.poolerino.com:3333 -u superjustin.superpumpupworker -p workwork &

Feel free to swap out your own pool and worker name/password, or just do a few hashes for me. =)

It will take the system a few minutes to get the GPU figured out and autotuned, but while you wait you can get set up to take advantage of the 8 CPU's that will be sitting idle once we get this GPU hashing.

For reference, here is my output:

*** CudaMiner for nVidia GPUs by Christian Buchner *** This is version 2013-12-18 (beta) based on pooler-cpuminer 2.3.2 (c) 2010 Jeff Garzik, 2012 pooler Cuda additions Copyright 2013 Christian Buchner My donation address: LKS1WDKGED647msBQfLBHV3Ls8sveGncnm [2013-12-25 11:32:32] 1 miner threads started, using 'scrypt' algorithm. [2013-12-25 11:32:32] Starting Stratum on stratum+tcp://doge.poolerino.com:3333 [2013-12-25 11:32:32] Stratum detected new block [2013-12-25 11:32:57] GPU #0: GRID K520 with compute capability 3.0 [2013-12-25 11:32:57] GPU #0: the 'K' kernel requires single memory allocation [2013-12-25 11:32:57] GPU #0: interactive: 0, tex-cache: 0 , single-alloc: 1 [2013-12-25 11:32:57] GPU #0: Performing auto-tuning (Patience...) [2013-12-25 11:32:57] GPU #0: maximum warps: 459 [2013-12-25 11:34:47] GPU #0: 244.68 khash/s with configuration K18x21 [2013-12-25 11:34:47] GPU #0: using launch configuration K18x21 [2013-12-25 11:34:48] GPU #0: GRID K520, 12096 hashes, 0.09 khash/s [2013-12-25 11:34:48] GPU #0: GRID K520, 12096 hashes, 116.83 khash/s[2013-12-25 11:34:54] GPU #0: GRID K520, 1439424 hashes, 231.48 khash/s [2013-12-25 11:34:54] accepted: 1/1 (100.00%), 231.48 khash/s (yay!!!) [2013-12-25 11:34:56] GPU #0: GRID K520, 508032 hashes, 228.09 khash/s [2013-12-25 11:34:56] accepted: 2/2 (100.00%), 228.09 khash/s (yay!!!) [2013-12-25 11:34:59] GPU #0: GRID K520, 556416 hashes, 228.73 khash/s

Etc etc etc. So every line or two it is accepting a ... whatever it is. I really don't understand the mining process that well, but I'm learning.

CPU Hash

This is a lot easier because we can just go grab a precompiled 64-bit binary and run it.

[ec2-user@ip-10-51-131-176 CudaMiner-master]$ cd [ec2-user@ip-10-51-131-176 ~]$ wget http://downloads.sourceforge.net/project/cpuminer/pooler-cpuminer-2.3.2-linux-x86_64.tar.gz?r=&ts=1387953566&use_mirror=softlayer-ams [ec2-user@ip-10-51-131-176 ~]$ tar xvf pooler-cpuminer-2.3.2-linux-x86_64.tar.gz\?r\= [ec2-user@ip-10-51-131-176 ~]$ ./minerd --url stratum+tcp://doge.poolerino.com:3333 -u superjustin.superpumpupworker -p workwork &

Ta-Da!

And that, step-by-step is how you can run a pretty decent DogeMining box in the cloud. So Cloud. So Doge.

Does this make any sense to do?

I don't know. Like this, totally 'naked' it is hashing at about 300 KH/s, which is generating me on the order of a few hundred coins/hr at this pool right now.

Math! 200 coins at $0.65/hr. That would mean that I would not return unless the price of a coin was about $0.003 (point three cents), and I think that the current (5:41AM on Christmas Morning) price is a factor of three below that. So it doesn't really seem to make a TON of sense to do economically, but hey, it's fun! I'm mining in the cloud! And maybe DogeCoin and BitCoin will go up in price 1000000000000000000%!

So I think that by setting this up, I'm now losing about $0.40/hr. Which is... Less-than-effective, but hey! With the scalabiltily, and not needing to worry about the hardware, I can always make it up in volume!

Better automating the process

A more efficient set of commands could definitely be built, and I'd toyed with the idea of "burning" this AMI so that I can just click and have it up and running, but I haven't decided the best way to (or if I'm going to) automate this more.

Lots of tools I'm really interested in in the configuration management space would make this helpful, but the learning curve on those is pretty steep and it probably won't help a ton.

In any case, if you want to send me Doge, that's much appreciated, too!

DAJa5tjgjrnJ3iMJb8khpDuE8tW8KNBWqG