
Adding GPUs to instances
Check and request for an increase in your quotas for GPUs:
- Search for GPU. If you have 0 in your allocated quotas, select the type of GPU and region and click on edit the quotas. Fill in the request form (https://console.cloud.google.com/iam-admin/quotas?project=packt-gcp).
There are several restrictions when it comes to using GPUs on Google Compute. GPUs are not available in shared or pre-emptible machines. GPU instances are terminated for regular (weekly) maintenance events. See https://cloud.google.com/compute/docs/gpus/ for up-to-date information on the restrictions. See also https://cloud.google.com/compute/docs/gpus#introduction to learn what machine types are available based on your desired GPU count.
To create a VM with GPU from the console:
- Go to the VM console and click on Create Instance
- Select a zone that is GPU compatible
- Click on customize the machine type and again on the GPUs link
- Select the Number of GPUs and the associated type you require:

Similarly you can create a GPU-enabled instance with gcloud with the following command:
Where --accelerator type= specifies the type of GPU and count= specifies the number of GPUs.
For instance, this command will create an Ubuntu 1604 instance with one NVIDIA? Tesla? K80 GPU and two vCPUs in the us-east1-d zone. The startup-script metadata instructs the instance to install the CUDA toolkit with its recommended driver version:
The startup script installs the right CUDA driver for the Ubuntu. For other drivers and operating systems, follow the instructions at https://developer.nvidia.com/cuda-downloads.
Once the driver has finished installing, you can verify that it is properly installed:
- Do ssh into your instance
- Type nvidia-smi to see your driver version and how much GPU memory you have
The command nvcc --version shows the current CUDA version.