Skip to content

How-ToGPU

How to Choose Which GPU Ollama Uses (or Force CPU)

How to make Ollama use a specific graphics card with CUDA_VISIBLE_DEVICES (NVIDIA), ROCR_VISIBLE_DEVICES (AMD ROCm) or GGML_VK_VISIBLE_DEVICES (Vulkan), how to force CPU-only with an invalid ID, and how to check the result with ollama ps.

By , Systems & Technical Editor

2 min read

How to Choose Which GPU Ollama Uses (or Force CPU)

If your PC has more than one graphics card, or an integrated GPU alongside a discrete one, Ollama may not pick the one you want. Ollama lets you choose with an environment variable, and the right variable depends on whether the card runs on NVIDIA's CUDA, AMD's ROCm or Vulkan. This guide follows Ollama's hardware support documentation.

Before you start: is the card supported?

Ollama's documentation says it supports NVIDIA GPUs with compute capability 5.0 or newer and driver version 550 or newer. It also supports AMD cards through ROCm, and further GPUs on Windows and Linux through its Vulkan backend. If you're not sure your card qualifies, see our guide to checking a GPU works with Ollama.

NVIDIA: CUDA_VISIBLE_DEVICES

  1. Open a terminal and run nvidia-smi -L. NVIDIA's documentation says this lists each NVIDIA GPU in the system along with its UUID.

  2. Set CUDA_VISIBLE_DEVICES to a comma-separated list of the GPUs Ollama should use.

  3. Ollama says numeric IDs work, but their order can vary, so UUIDs are more reliable. For example, set it to the UUID string nvidia-smi -L shows for your preferred card.

AMD: ROCR_VISIBLE_DEVICES

On AMD cards that use ROCm, set ROCR_VISIBLE_DEVICES to a comma-separated list instead. Ollama's documentation says you can list devices with rocminfo, and recommends using the device's Uuid rather than a number where available.

Vulkan: GGML_VK_VISIBLE_DEVICES

For GPUs running on the Vulkan backend, set GGML_VK_VISIBLE_DEVICES to one or more numeric IDs. Ollama gives a specific tip for PCs with an unstable integrated GPU: keep Vulkan enabled and set the variable to the discrete card's index, for example GGML_VK_VISIBLE_DEVICES=1 when Vulkan1 is the discrete GPU. To turn off all Vulkan GPUs, set OLLAMA_VULKAN=0 or GGML_VK_VISIBLE_DEVICES=-1.

Forcing CPU-only

Ollama's documentation says that to ignore the GPUs and force CPU use, you set an invalid GPU ID such as -1 in CUDA_VISIBLE_DEVICES or ROCR_VISIBLE_DEVICES. Expect much slower responses; our guide to running a local LLM without a GPU explains what to expect.

How to set the variable

These are server settings, so Ollama has to be restarted to pick them up:

  • Windows: quit Ollama from the taskbar, search Settings for environment variables, choose Edit environment variables for your account, add the variable and value, click OK, then start Ollama from the Start menu.

  • Linux (systemd): run systemctl edit ollama.service, add a line such as Environment="CUDA_VISIBLE_DEVICES=GPU-..." under [Service], then run systemctl daemon-reload and systemctl restart ollama.

Check it worked

Load a model and run ollama ps: the Processor column shows whether it's on the GPU, the CPU or split. On NVIDIA cards, nvidia-smi shows which GPU's memory use rose. Our guide to checking Ollama is using your GPU goes further. If you want Ollama to use two cards together, its FAQ says a model that fits on one GPU loads there, and only larger models are spread across all available GPUs.

Our verdict

Use CUDA_VISIBLE_DEVICES for NVIDIA, ROCR_VISIBLE_DEVICES for AMD with ROCm and GGML_VK_VISIBLE_DEVICES for Vulkan, preferably with UUIDs where Ollama supports them, then restart Ollama and confirm with ollama ps.

The bottom line

Use `CUDA_VISIBLE_DEVICES` for NVIDIA, `ROCR_VISIBLE_DEVICES` for AMD with ROCm and `GGML_VK_VISIBLE_DEVICES` for Vulkan, preferably with UUIDs where Ollama supports them, then restart Ollama and confirm with `ollama ps`.

Sources

  1. 01Ollama, Hardware support (GPU selection for NVIDIA, AMD and Vulkan)
  2. 02Ollama, FAQ (server configuration and multiple GPUs)
  3. 03NVIDIA, nvidia-smi documentation (-L, --list-gpus)

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

How to Fix Slow Token Generation in llama.cpp

How-To

How to Fix Slow Token Generation in llama.cpp

How to fix slow llama.cpp text generation by confirming GPU offload with -ngl and setting -t to your physical core count or lower, with the llama.cpp developers' own example showing the effect of each setting.

Marcus Thorne2 min

How to Run Multiple Models at Once in Ollama

How-To

How to Run Multiple Models at Once in Ollama

How Ollama keeps several models loaded and handles parallel requests, with the defaults for OLLAMA_MAX_LOADED_MODELS, OLLAMA_NUM_PARALLEL and OLLAMA_MAX_QUEUE, how to change them, and how Ollama places models across multiple GPUs.

Marcus Thorne3 min

How to Check a Driver Version in Windows 11

How-To

How to Check a Driver Version in Windows 11

How to check any device's driver version in Windows 11 through Device Manager's Driver tab, and how to see an NVIDIA graphics driver's version by typing nvidia-smi in Terminal.

Marcus Thorne2 min