Create an N1 VM that has attached GPUs (original) (raw)

Linux Windows


This document explains how to create a VM that has attached GPUs and uses anN1 machine family. You can use most N1 machine types except the N1 shared-core.

Before you begin

Required roles

To get the permissions that you need to create VMs, ask your administrator to grant you theCompute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to create VMs. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create VMs:

You might also be able to get these permissions with custom roles or other predefined roles.

Overview

The following GPU models can be attached to VMs that use N1 machine families.

NVIDIA GPUs:

NVIDIA RTX Virtual Workstation (vWS) (formerly known as NVIDIA GRID):

You can create an N1 VM that has attached GPUs by using either the Google Cloud console, Google Cloud CLI, or REST.

Console

  1. In the Google Cloud console, go to the Create an instance page.
    Go to Create an instance
  2. Specify a Name for your VM. SeeResource naming convention.
  3. Select a region and zone where GPUs are available. See the list of availableGPU zones.
  4. In the Machine configuration section, select the GPUs machine family, and then do the following:
    1. In the GPU type list, select one of the GPU models supported on N1 machines.
    2. In the Number of GPUs list, select the number of GPUs.
    3. If your GPU model supportsNVIDIA RTX Virtual Workstations (vWS) for graphics workloads, and you plan on running graphics-intensive workloads on this VM, selectEnable Virtual Workstation (NVIDIA GRID).
    4. In the Machine type list, select one of the preset N1 machine types. Alternatively, you can also specify custom machine type settings.
  5. In the Boot disk section, clickChange. This opens the Boot disk configuration page.
  6. On the Boot disk configuration page, do the following:
    1. On the Public images tab, choose asupported Compute Engine imageor Deep Learning VM Images.
    2. Specify a boot disk size of at least 40 GB.
    3. To confirm your boot disk options, click Select.
  7. Optional: In the VM provisioning model list, select aprovisioning model.
  8. To create and start the VM, click Create.

gcloud

To create and start a VM use thegcloud compute instances createcommand with the following flags.

If your workload is fault-tolerant and can withstand possible VM preemption, consider using Spot VMs to reduce the cost of your VMs and the attached GPUs. For more information, seeGPUs on Spot VMs. The --provisioning-model=SPOT is an optional flag that configures your VMs as Spot VMs. For Spot VMs, the automatic restart and host maintenance options flags are disabled.

gcloud compute instances create VM_NAME
--machine-type MACHINE_TYPE
--zone ZONE
--boot-disk-size DISK_SIZE
--accelerator type=ACCELERATOR_TYPE,count=ACCELERATOR_COUNT
[--image IMAGE | --image-family IMAGE_FAMILY]
--image-project IMAGE_PROJECT
--maintenance-policy TERMINATE
[--provisioning-model=SPOT]

Replace the following:

Example

For example, you can use the following gcloud command to start an Ubuntu 22.04 VM with 1 NVIDIA T4 GPU and 2 vCPUs in theus-east1-d zone.

gcloud compute instances create gpu-instance-1
--machine-type n1-standard-2
--zone us-east1-d
--boot-disk-size 40GB
--accelerator type=nvidia-tesla-t4,count=1
--image-family ubuntu-2204-lts
--image-project ubuntu-os-cloud
--maintenance-policy TERMINATE

REST

Identify the GPU type that you want to add to your VM. Submit a GET request to list the GPU types that are available to your project in a specific zone.

If your workload is fault-tolerant and can withstand possible VM preemption, consider using Spot VMs to reduce the cost of your VMs and the attached GPUs. For more information, seeGPUs on Spot VMs. The "provisioningModel": "SPOT" is an optional parameter that configures your VMs as Spot VMs. For Spot VMs, the automatic restart and host maintenance options flags are disabled.

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/acceleratorTypes

Replace the following:

Send a POST request to theinstances.insert method. Include the acceleratorType parameter to specify which GPU type you want to use, and include the acceleratorCount parameter to specify how many GPUs you want to add. Also set the onHostMaintenance parameter to TERMINATE.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances { "machineType": "projects/PROJECT_ID/zones/ZONE/machineTypes/MACHINE_TYPE", "disks": [ { "type": "PERSISTENT", "initializeParams": { "diskSizeGb": "DISK_SIZE", "sourceImage": "projects/IMAGE_PROJECT/global/images/family/IMAGE_FAMILY" }, "boot": true } ], "name": "VM_NAME", "networkInterfaces": [ { "network": "projects/PROJECT_ID/global/networks/NETWORK" } ], "guestAccelerators": [ { "acceleratorCount": ACCELERATOR_COUNT, "acceleratorType": "projects/PROJECT_ID/zones/ZONE/acceleratorTypes/ACCELERATOR_TYPE" } ], "scheduling": { ["automaticRestart": true], "onHostMaintenance": "TERMINATE", ["provisioningModel": "SPOT"] }, }

Replace the following:

Install drivers

To install the drivers, choose one of the following options:

What's next?