---
title: "TargetDevice"
language: "en"
type: "Symbol"
summary: "TargetDevice is an option for certain functions that specifies on which device the computation should be attempted."
keywords: 
- gpu net training
- gpu
- gpu evaluation
- V100
- Nvidia
- Volta GPU
- CUDA
- OpenCL
- graphics processor
- coprocessor
canonical_url: "https://reference.wolfram.com/language/ref/TargetDevice.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Neural Network Construction & Properties"
    link: "https://reference.wolfram.com/language/guide/NeuralNetworkConstruction.en.md"
related_workflows: 
  - 
    title: "Run Neural Network Training on GPUs"
    link: "https://reference.wolfram.com/language/workflow/RunNeuralNetworkTrainingOnGPUs.en.md"
related_functions: 
  - 
    title: "NetTrain"
    link: "https://reference.wolfram.com/language/ref/NetTrain.en.md"
  - 
    title: "NetChain"
    link: "https://reference.wolfram.com/language/ref/NetChain.en.md"
  - 
    title: "NetGraph"
    link: "https://reference.wolfram.com/language/ref/NetGraph.en.md"
  - 
    title: "NetExternalObject"
    link: "https://reference.wolfram.com/language/ref/NetExternalObject.en.md"
  - 
    title: "Parallelize"
    link: "https://reference.wolfram.com/language/ref/Parallelize.en.md"
  - 
    title: "NetEvaluationMode"
    link: "https://reference.wolfram.com/language/ref/NetEvaluationMode.en.md"
related_tutorials: 
  - 
    title: "Neural Networks in the Wolfram Language"
    link: "https://reference.wolfram.com/language/tutorial/NeuralNetworksOverview.en.md"
---
# TargetDevice
⚠ *Unsupported in Public Cloud*

TargetDevice is an option for certain functions that specifies on which device the computation should be attempted.

## Details

* Possible settings for ``TargetDevice`` change depending on the system and the available hardware.

* General settings include:

|       |                                  |
| ----- | -------------------------------- |
| "CPU" | use the CPU                      |
| "GPU" | use available dedicated hardware |

* The specification ``TargetDevice -> "GPU"`` has the following interpretation, depending on ``\$SystemID`` :

|            |                                              |
| ---------- | -------------------------------------------- |
| "CoreML"   | "MacOSX-ARM64"                               |
| "CUDA"     | "Windows-x86-64" or "Linux-x86-64"           |
| "DirectML" | "Windows-x86-64" if no CUDA card is detected |

* Settings specific to system and available hardware include:

|            |                                       |
| ---------- | ------------------------------------- |
| "CoreML"   | Apple CoreML framework                |
| "CUDA"     | Nvidia CUDA API                       |
| "DirectML" | Microsoft Direct Machine Learning API |

* Currently, the only settings supported by ``NetTrain`` are ``"CPU"`` and ``"CUDA"``.

* ``TargetDevice -> {"GPU", n}`` allows a specific GPU to be used, where ``n`` is an integer between 1 and the number of GPUs available on your computer.

* In general, a specific value of ``n`` might not identify the same GPU when different backends such as ``"CUDA"`` and ``"DirectML"`` are used.

* ``TargetDevice -> {"GPU", All}`` specifies that all available GPUs should be used jointly.

* ``TargetDevice -> {"GPU", {n1, n2, …}}`` specifies that a specific subset of the GPUs should be used jointly.

* On Apple silicon machines, ``TargetDevice -> "CoreML"`` attempts to perform the computation using the Apple Neural Engine. It is not currently supported for ``NetTrain`` and ``NetMeasurements.``  »

* On Windows machines, ``TargetDevice -> "DirectML"`` can perform the computation using an integrated or discrete GPU with DirectX support. It is not currently supported for ``NetTrain`` and ``NetMeasurements.``

* ``TargetDevice -> "CUDA"`` requires NVIDIA GPUs with compute capability 3.7 or 5.0 and higher.

* In a fresh Wolfram Language installation on Linux and Windows machines, ``TargetDevice -> "GPU"`` and related GPU settings will automatically download additional libraries. Such a download can also trigger again in case updates are available. The downloads can also be started manually by running ``PacletInstall["MXNetResources"]``, ``PacletInstall["ONNXRuntimeResources"]`` and ``PacletInstall["CUDAResources"]``.

## Examples (10)

### Basic Examples (1)

Train a net using the system's default GPU:

```wl
In[1]:= trained = NetTrain[NetModel["LeNet"], "MNIST", TargetDevice -> "GPU"]

Out[1]= [image]
```

Evaluate the resulting net using the system's default GPU:

```wl
In[2]:= trained[[image], TargetDevice -> "GPU"]

Out[2]= 8
```

### Scope (6)

#### Inference (5)

Evaluate a model on the CPU:

```wl
In[1]:= NetModel["Wolfram ImageIdentify Net V1"][RandomImage[], TargetDevice -> "CPU"]

Out[1]= Entity["Concept", "IgneousRock::9r5r5"]
```

---

Evaluate a model on the system's default GPU:

```wl
In[1]:= NetModel["Wolfram ImageIdentify Net V1"][RandomImage[], TargetDevice -> "GPU"]

Out[1]= Entity["Concept", "IgneousRock::9r5r5"]
```

---

Specify the use of CoreML (on macOS ARM64):

```wl
In[1]:= NetModel["Wolfram ImageIdentify Net V1"][RandomImage[], TargetDevice -> "CoreML"]

Out[1]= Entity["Concept", "IgneousRock::9r5r5"]
```

---

Specify the use of a DirectML-compatible card (on Windows x86-64):

```wl
In[1]:= NetModel["Wolfram ImageIdentify Net V1"][RandomImage[], TargetDevice -> "DirectML"]

Out[1]= Entity["Concept", "IgneousRock::9r5r5"]
```

---

Specify the use of a CUDA-compatible card (on Windows x86-64 or Linux x86-64):

```wl
In[1]:= NetModel["Wolfram ImageIdentify Net V1"][RandomImage[], TargetDevice -> "CUDA"]

Out[1]= Entity["Concept", "IgneousRock::9r5r5"]
```

#### Training (1)

Train a net using a specified CUDA GPU:

```wl
In[1]:= NetTrain[NetModel["LeNet"], "MNIST", TargetDevice -> {"GPU", 1}]

Out[1]= [image]
```

Train a net using two specified GPUs, where each GPU receives a batch of 16 training examples per training iteration:

```wl
In[2]:= NetTrain[NetModel["LeNet"], "MNIST", TargetDevice -> {"GPU", {1, 2}}, BatchSize -> 32]

Out[2]= [image]
```

Train a net using all available GPUs:

```wl
In[3]:= NetTrain[NetModel["LeNet"], "MNIST", TargetDevice -> {"GPU", All}, BatchSize -> 64]

Out[3]= [image]
```

### Possible Issues (3)

If the system GPU is not supported, the operation will fail:

```wl
In[1]:=
n = 100000;
trainingData = RandomReal[1, {n, 4}] -> RandomReal[1, {n, 4}];
net = NetChain[{8, Tanh, 2048, Tanh, 2048, Tanh, 4}, "Input" -> 4];
trained = NetTrain[net, trainingData, TargetDevice -> "GPU"]
```

NetTrain::badtrgdev: TargetDevice -> GPU could not be used, please ensure that you have a compatible NVIDIA graphics card and have installed the latest operating system drivers.

```wl
Out[1]= $Failed
```

---

Some settings are only supported for model evaluation and will fail during training:

```wl
In[1]:= NetTrain[NetModel["LeNet"], "MNIST", TargetDevice -> "CoreML"]
```

NetTrain::trgdevbad: Invalid setting TargetDevice -> CoreML.

```wl
Out[1]= $Failed
```

---

There is currently no CUDA support on macOS:

```wl
In[1]:= NetTrain[NetModel["LeNet"], "MNIST", TargetDevice -> "CUDA"]
```

NetTrain::trgdevunsupp: TargetDevice -> CUDA is not supported on MacOSX platforms.

```wl
Out[1]= $Failed
```

## See Also

* [`NetTrain`](https://reference.wolfram.com/language/ref/NetTrain.en.md)
* [`NetChain`](https://reference.wolfram.com/language/ref/NetChain.en.md)
* [`NetGraph`](https://reference.wolfram.com/language/ref/NetGraph.en.md)
* [`NetExternalObject`](https://reference.wolfram.com/language/ref/NetExternalObject.en.md)
* [`Parallelize`](https://reference.wolfram.com/language/ref/Parallelize.en.md)
* [`NetEvaluationMode`](https://reference.wolfram.com/language/ref/NetEvaluationMode.en.md)

## Tech Notes

* [Neural Networks in the Wolfram Language](https://reference.wolfram.com/language/tutorial/NeuralNetworksOverview.en.md)

## Related Guides

* [Neural Network Construction & Properties](https://reference.wolfram.com/language/guide/NeuralNetworkConstruction.en.md)

## Related Workflows

* [Run Neural Network Training on GPUs](https://reference.wolfram.com/language/workflow/RunNeuralNetworkTrainingOnGPUs.en.md)

## History

* [Introduced in 2016 (11.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn110.en.md) \| [Updated in 2024 (14.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn141.en.md)