Skip to content

Instantly share code, notes, and snippets.

@johndpope
Forked from mlgill/setup_aws_gpu.sh
Last active August 17, 2018 20:19
Show Gist options
  • Save johndpope/ac3ae5f4e033d1ca6c94d3387e4dc309 to your computer and use it in GitHub Desktop.
Save johndpope/ac3ae5f4e033d1ca6c94d3387e4dc309 to your computer and use it in GitHub Desktop.
Setup AWS GPU instance - bump 9.2.148
#!/bin/bash
####################################################################################
## AWS GPU Instance Setup Script ##
## John Pope ##
## ##
## Gist location: https://gist.github.com/johndpope/ac3ae5f4e033d1ca6c94d3387e4dc309 ##
## Date updated: 2018/08/17 ##
####################################################################################
## download z-enemy / won't work inside zsh
sudo apt-get install libjansson-dev
sudo apt install python-pip
pip install gdown
pip install six
gdown https://drive.google.com/uc?id=1X1d4exSpb705fFGd6a16VB7r4oebcQEc
tar -xzvf z-enemy-1.16-cuda92.tar.gz
sudo apt-get install curl libcurl3
#sudo su
#sudo apt-get install zsh
#sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# zsh
# BASH prompt colors
BLUE='\033[1;34m'
RED='\033[1;31m'
NC='\033[0m'
echo ""
echo -e $BLUE"############################################################################"$NC
echo -e $BLUE"# MUST use Ubuntu Server 16.04 LTS (HVM), SSD Volume Type, ami-80861296 #"$NC
echo -e $BLUE"# MUST set region to US-EAST-1A under 'Configure Instance Details, Subnet' #"$NC
echo -e $BLUE"############################################################################"$NC
echo ""
sleep 2
nvidia_cuda_version="9.2.148"
echo ""
echo -e $BLUE"Using: nvidia_cuda_version = $nvidia_cuda_version"$NC
echo ""
sleep 2
echo ""
echo -e $BLUE"Installing apt-get packages"$NC
echo ""
sleep 1
# ensure system is updated and has basic build tools
sudo apt-get update
#sudo apt-get --assume-yes upgrade
sudo apt-get --assume-yes install tmux build-essential gcc g++ make binutils graphviz
sudo apt-get --assume-yes install software-properties-common
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install -y xserver-xorg mesa-utils
sudo apt-get install -y gcc make linux-generic
mkdir downloads
cd downloads
echo ""
echo -e $BLUE"Installing cuda drivers"$NC
echo ""
sleep 1
# download and install GPU drivers
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_${nvidia_cuda_version}-1_amd64.deb" \
-O "cuda-repo-ubuntu1604_${nvidia_cuda_version}_amd64.deb"
sudo dpkg -i cuda-repo-ubuntu1604_${nvidia_cuda_version}_amd64.deb
sudo apt-get update
sudo apt-get -y install cuda
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
##ssl nonsense
wget -qO - http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/7fa2af80.pub | sudo apt-key add -
sudo apt-get update && apt-get install -y apt-transport-https
sudo echo 'deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /' > /etc/apt/sources.list.d/cuda.list
sudo apt-get update
sudo modprobe nvidia
nvidia-smi
echo "export PATH=\"/usr/local/cuda/bin:\$PATH\"" >> ~/.zshrc
source ~/.zshrc
echo ""
echo -e $BLUE"customizing for aws p2 instance"
echo ""
sleep 2
sudo nvidia-smi -pm 1
sudo nvidia-smi -acp 0
sudo nvidia-smi --auto-boost-default=0
#sudo nvidia-smi -ac 2505,875 - specific to p2 need g2 settings
## sgminer
apt install opencl-headers
apt-get install libcurl4-openssl-dev pkg-config libtool libncurses5-dev
sudo apt install autoconf
sudo apt install ocl-icd-opencl-dev
sudo apt-get install g++ freeglut3-dev build-essential libx11-dev \
libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
git clone https://github.com/XDNA-Core/sgminer-hex
cd sgminer-hex
git submodule init
git submodule update
autoreconf -i
CFLAGS="-O2 -Wall -march=native -std=gnu99" ./configure
make
export GPU_USE_SYNC_OBJECTS=1
export GPU_MAX_ALLOC_PERCENT=100
./sgminer -k hex --intensity 8 -u XWn8BDU4QXHQji6insi33CYeTEr5N4sn34 -p c=XDNA --worksize 16 -o stratum+tcp://stratum.gos.cx:5000

Setting Up an AWS GPU Instance

  1. Navigate to the AWS EC2 dashboard. Ensure your location is "US East, N. Virginia" in the black bar at the top of the window.
  2. Create a new instance on AWS by selecting "Launch Instance" from the EC2 dashboard.
  3. Select "Ubuntu Server 16.04 LTS (HVM), SSD Volume Type - ami-80861296" for the operating system. The AMI number (ami-80861296) can be entered manually under "Community AMIs" if Amazon has changed the default instance since this guide was created.
  4. Select a p2.xlarge GPU compute instance.
  5. Ensure the "Subnet" says 'use-east-1a'.
  6. Add 128 GB of storage to the instance so there is room for your files.
  7. Click through the remaining screens until you get to "Security Group". Ensure that only SSH (port 22) is open. Select "Review and Launch".
  8. When the instance has launched, copy the setup script (setup_aws_gpu.sh) onto the instance, which will look something like this:
    scp -i ~/.ssh/id_rsa setup_aws_gpu.sh [email protected]:~
  9. SSH onto the instance and run the setup script. It will take care of the entire install and will provide status updates in blue as it does so.
  10. Once complete, the instance will have to be rebooted for the CUDA GPU drivers to be completely loaded:
    sudo shutdown -r now
  11. SSH back onto the instance and it's ready for use. Note that the IP address may have changed.

This entire setup has been saved as ami-79d5996f, and can be loaded directly from AWS rather than running the above setup script. However, it's good to have the script as a reference for future endeavors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment