---
title: "GPUs"
canonical: "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/GPUs.html"
source: "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/GPUs.md"
part: "The Magma Language"
chapter: "Parallelism"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "The Magma Language", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/index-magma-language.md"}
  - {"title": "Parallelism", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/index-parallelism.md"}
prev: {"title": "Magma Kernel Distributed Parallelism", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/kernel-distributed-parallelism.md"}
next: {"title": "Linear Algebra", "source": "https://docs.magma-maths.org/v2.30-1/MagmaLanguage/Parallelism/linear-algebra.md"}
intrinsics:
  - {"name": "SetGPU", "signature": "SetGPU(b): BoolElt"}
  - {"name": "GetGPU", "signature": "GetGPU() -> BoolElt"}
  - {"name": "SetNGPUs", "signature": "SetNGPUs(n): RngIntElt"}
  - {"name": "GetNGPUs", "signature": "GetNGPUs() -> RngIntElt"}
  - {"name": "SetGPUDevices", "signature": "SetGPUDevices(S): SeqEnum"}
  - {"name": "SetGPUDevice", "signature": "SetGPUDevice(k): RngIntElt"}
---

<a id="sec-gpu"></a>
<a id="id1"></a>
# GPUs

Support for NVIDIA Tesla Graphical Processing Units (GPUs) is provided when the CUDA library is installed on the system and the Magma CUDA executable `magma.cuda.exe` is used (suitably renamed for the driving `magma` command line script if need be).

The GPU mode is automatically selected by default in the Magma CUDA executable when running on a computer with CUDA support; the procedure call `SetGPU(false);` disables the CUDA matrix algorithms in this executable, while `SetGPU(true);` enables them again. (For the standard non-CUDA executable, `SetGPU` is ignored since the GPU mode is irrelevant.)

Multiple GPU-based linear algebra is supported since V2.26.

<a id="procedure-par-setgpu"></a>
## `SetGPU(b): BoolElt`

<a id="function-getgpu"></a>
## `GetGPU() -> BoolElt`

Set the NVIDIA GPU mode to $b$; this determines whether Magma should use NVIDIA GPUs via CUDA when supported. This is only relevant to a CUDA-enabled executable (typically downloaded as `magma.cuda.exe`) and is `true` by default in that case (so the GPU is used by default); for a non-CUDA-enabled executable, the procedure has no effect. Currently, a GPU is exploited in matrix multiplication over ${\bf F}_{2}$ and small prime finite fields and consequently anything which depends on such multiplication, such as the dense $F_4$ Gröbner basis algorithm over such fields.

<a id="procedure-setngpus-rngintelt"></a>
## `SetNGPUs(n): RngIntElt`

Set the number of GPUs to be used to $n$ (uses devices $0\ ..\ n - 1$ by default).

<a id="function-getngpus"></a>
## `GetNGPUs() -> RngIntElt`

Return the number of GPUs now used.

<a id="procedure-setgpudevices-seqenum"></a>
## `SetGPUDevices(S): SeqEnum`

Set the specific used GPU devices to be the numbers in sequence $S$ (while setting the number of devices to $\#S$); the entries of $S$ must be distinct and $\ge 0$.

<a id="procedure-setgpudevice-rngintelt"></a>
## `SetGPUDevice(k): RngIntElt`

Set the single specific GPU device to be used to be $k$; this is equivalent to calling `SetGPUDevices([k])` .

Being able to set specific devices provides finer-grained management when a machine has more than one GPU. For example, suppose that the machine has two GPUs (device numbers 0 and 1). One could just use `SetNGPUs(2)` for one job to use two GPUs, but one might prefer to run two separate jobs each using a single GPU. In that case the first job could specify `SetGPUDevice(0)` while the second job would specify `SetGPUDevice(1)`.

NB: The utility `nvtop` (downloadable from `https://github.com/Syllo/nvtop`) is very useful for seeing the GPU usage during a run. It continuously shows how much each GPU is being used both in time and memory usage.
