Skip to content

Instantly share code, notes, and snippets.

@ryanmeasel
Last active September 16, 2018 20:46
Show Gist options
  • Save ryanmeasel/ea1f3aef1f98cc4955539a65f3c02d53 to your computer and use it in GitHub Desktop.
Save ryanmeasel/ea1f3aef1f98cc4955539a65f3c02d53 to your computer and use it in GitHub Desktop.
Setting up Tensorflow-gpu on a GCP VM

Overview

Installation instructions for setting up a GCP VM with Tensorflow-gpu.

Instructions

GCP VM Instance

  1. Select Compute Engine > VM Instances > Create Instance.
  2. Specify Name, Region, and Zone. Note, the zone must support GPU instances.
  3. Under Machine Type, select Customize.
    1. Choose the number of VCPUs.
    2. Choose the amount of memory.
    3. Choose the number and type of GPUs.
  4. Under Boot disk, select Change.
    1. Choose Ubuntu 16.04 LTS.
    2. Specify the boot disk size.
  5. Configure any other desired settings for the instance.
  6. Select Create.

CUDA setup

  1. SSH into the instance.
  2. Download and install the CUDA 9.0 package.
    curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.0.176-1_amd64.deb
    sudo dpkg -i ./cuda-repo-ubuntu1604_9.0.176-1_amd64.deb
    sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
    sudo apt-get update
    sudo apt-get install cuda-9-0 -y
    export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

CUDNN setup

  1. Download cudnn-9.0-linux-x64-v7.2.1.38.tgz from the Nvidia website.
  2. SCP the tar file to the server.
    gcloud compute --project "${PROJECT_NAME}" scp --zone "${GCP_ZONE}" ${CUDNN_TAR_FILE} ${INSTANCE_NAME}:~/
  3. SSH into the instance.
  4. Install CUDNN.
    tar -xvf ${CUDNN_TAR_FILE}
    sudo cp cuda/include/cudnn.h /usr/local/cuda/include
    sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
    sudo chmod a+r /usr/local/cuda/include/cudnn.h 

Tensorflow-gpu setup

  1. Install tensorflow-gpu.
    sudo apt-get install python-pip python-dev python-virtualenv
    mkdir ~/tensorflow 
    cd ~/tensorflow 
    virtualenv --system-site-packages
    source ~/tensorflow/venv/bin/activate  
    pip install --upgrade tensorflow-gpu
  2. Verify the installation.
    python -c "import tensorflow as tf; print(tf.__version__)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment