Skip to content

Instantly share code, notes, and snippets.

@dingran
Last active January 15, 2020 06:58
Show Gist options
  • Save dingran/bed1825cc90c085b0deb0f487f059ecf to your computer and use it in GitHub Desktop.
Save dingran/bed1825cc90c085b0deb0f487f059ecf to your computer and use it in GitHub Desktop.
Google Cloud Compute virtual machine set up with GPU

Google Cloud Compute virtual machine set up with GPU

VNC related

First, install desktop environment and vncsever

sudo apt-get install ubuntu-desktop gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install vnc4server

Use vncserver to start and vncserver -kill :1 to kill vncserver session.

Optionally use vncserver -geometry 1920x1080 to specify resolution

Update content of ~/.vnc/xstartup, need to restart vncserver to take effect

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &

gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &

Forward port, using the following gcloud command to forward port 5901 (to local port 5911) as well as to login

gcloud compute --project "some-proj-123456" ssh --zone "us-east1-c" "instance-2" --ssh-flag "-L 5911:127.0.0.1:5901"

Use VNC viewer (https://www.realvnc.com/) to open 5911 port

GPU driver and cuDNN installation

Follow instruction here: https://cloud.google.com/compute/docs/gpus/add-gpus

Driver installation script for Ubuntu 16.04

#!/bin/bash
echo "Checking for CUDA and installing."
# Check for CUDA and try to install.
if ! dpkg-query -W cuda; then
  # The 16.04 installer works with 16.10.
  curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  dpkg -i ./cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
  apt-get update
  apt-get install cuda -y
fi

Verification

$ nvidia-smi
Wed Jul 12 23:20:10 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.66                 Driver Version: 375.66                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 0000:00:04.0     Off |                    0 |
| N/A   38C    P0    58W / 149W |      0MiB / 11439MiB |    100%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

Installing cuDNN:

Now getting cuDNN here https://developer.nvidia.com/cudnn (need to log in, and download cuDNN 5.1 not 6.0)

Issue the following commands to install it (https://askubuntu.com/questions/767269/how-can-i-install-cudnn-on-ubuntu-16-04)

cd folder/extracted/contents
sudo cp -P include/cudnn.h /usr/include
sudo cp -P lib64/libcudnn* /usr/lib/x86_64-linux-gnu/
sudo chmod a+r /usr/lib/x86_64-linux-gnu/libcudnn*

Python related

First install python 3.6 version anaconda release

Then

pip install tensorflow-gpu keras tqdm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment