---
title: "ClikaRT::Device"
sidebar_label: "Device"
description: "A compute device: a backend API plus a device index (e.g. the 1 in CUDA device 1). Default-constructs to the whole-machine host CPU. An accelerator index is zero-based and names one physical device."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--struct">struct</span>

**Header:** `ClikaRT/compute/device.h`

Compute device and backend-API identifiers.

A compute device: a backend API plus a device index (e.g. the `1` in CUDA device 1). Default-constructs to the whole-machine host CPU.

An accelerator index is zero-based and names one physical device. A CPU index instead names a SOCKET, with the whole machine at [`device::kWholeMachineCpuIndex`](device-namespace/index.md#kWholeMachineCpuIndex), so [`Device::cpu()`](./Device.md#cpu) uses every core, while `Device::cpu(0)` confines work to socket 0's cores and its local memory.

## Static member functions

### cpu() {#cpu}

<div class="api-signature">

`static` `constexpr` [`Device`](./Device.md) **`cpu`**(`std::int32_t` `i` `=` [`device::kWholeMachineCpuIndex`](device-namespace/index.md#kWholeMachineCpuIndex)) `noexcept`

</div>

Named factories. [`cpu()`](./Device.md#cpu) is every core; `cpu(i)` is socket `i`.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 73

</div>

### cuda() {#cuda}

<div class="api-signature">

`static` `constexpr` [`Device`](./Device.md) **`cuda`**(`std::int32_t` `i` `=` `0`) `noexcept`

</div>

The [`index`](./Device.md#index)-th CUDA device.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 77

</div>

### vulkan() {#vulkan}

<div class="api-signature">

`static` `constexpr` [`Device`](./Device.md) **`vulkan`**(`std::int32_t` `i` `=` `0`) `noexcept`

</div>

The [`index`](./Device.md#index)-th Vulkan device.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 79

</div>

### metal() {#metal}

<div class="api-signature">

`static` `constexpr` [`Device`](./Device.md) **`metal`**(`std::int32_t` `i` `=` `0`) `noexcept`

</div>

The [`index`](./Device.md#index)-th Metal device.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 81

</div>

### htp() {#htp}

<div class="api-signature">

`static` `constexpr` [`Device`](./Device.md) **`htp`**(`std::int32_t` `i` `=` `0`) `noexcept`

</div>

The [`index`](./Device.md#index)-th HTP (Hexagon) device.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 83

</div>

### tpu() {#tpu}

<div class="api-signature">

`static` `constexpr` [`Device`](./Device.md) **`tpu`**(`std::int32_t` `i` `=` `0`) `noexcept`

</div>

The [`index`](./Device.md#index)-th TPU device.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 85

</div>

### gpu() {#gpu}

<div class="api-signature">

`static` [`Device`](./Device.md) **`gpu`**(`std::int32_t` `index` `=` `0`)

</div>

The generic accelerator: the first backend, in priority order CUDA \> TPU \> Metal \> Vulkan (each a candidate only in a build that carries its backend) that loads and exposes a device on THIS host (resolved at call time, not constexpr; HTP is an NPU and not part of "gpu"). When no GPU backend is available it falls back to [`cpu()`](./Device.md#cpu) and says so once at warning level on the "ClikaRT" logging channel, so generic code gets a usable device on any host. For explicit control use the per-API factories and `backend_load_status` ([backends.h](device-namespace/index.md#backends-h)).

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 95

</div>

## Member functions

### Device() {#Device}

<div class="api-signature">

`constexpr` `constexpr` **`Device`**() `noexcept=default`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 61

</div>

### Device(device::ComputeAPI, int32\_t) {#Device-2}

<div class="api-signature">

`constexpr` `constexpr` **`Device`**([`device::ComputeAPI`](device-namespace/index.md#ComputeAPI) `api_`, `std::int32_t` `index_`) `noexcept`

</div>

A device from its `api_` and `index_` values.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 63

</div>

### Device(device::ComputeAPI) {#Device-3}

<div class="api-signature">

`constexpr` `constexpr` **`Device`**([`device::ComputeAPI`](device-namespace/index.md#ComputeAPI) `api_`) `noexcept`

</div>

An API with no index means that backend's default device: the whole machine on CPU, device 0 on an accelerator (which has no "whole machine").

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 68

</div>

### is\_cpu() {#is_cpu}

<div class="api-signature">

`constexpr` `bool` **`is_cpu`**() `const noexcept`

</div>

True for the CPU API.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 98

</div>

### is\_cuda() {#is_cuda}

<div class="api-signature">

`constexpr` `bool` **`is_cuda`**() `const noexcept`

</div>

True for the CUDA API.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 100

</div>

### is\_vulkan() {#is_vulkan}

<div class="api-signature">

`constexpr` `bool` **`is_vulkan`**() `const noexcept`

</div>

True for the Vulkan API.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 102

</div>

### is\_metal() {#is_metal}

<div class="api-signature">

`constexpr` `bool` **`is_metal`**() `const noexcept`

</div>

True for the Metal API.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 104

</div>

### is\_htp() {#is_htp}

<div class="api-signature">

`constexpr` `bool` **`is_htp`**() `const noexcept`

</div>

True for the HTP API.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 106

</div>

### is\_tpu() {#is_tpu}

<div class="api-signature">

`constexpr` `bool` **`is_tpu`**() `const noexcept`

</div>

True for the TPU API.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 108

</div>

## Data members

### api {#api}

<div class="api-signature">

[`device::ComputeAPI`](device-namespace/index.md#ComputeAPI) **`api`** `=` [`device::ComputeAPI::CPU`](device-namespace/index.md#ComputeAPI)

</div>

which accelerator API drives this device

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 58

</div>

### index {#index}

<div class="api-signature">

`std::int32_t` **`index`** `=` [`device::kWholeMachineCpuIndex`](device-namespace/index.md#kWholeMachineCpuIndex)

</div>

ordinal within the API (CPU default = the whole machine)

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 59

</div>

## Friends

### operator== {#operator-eq}

<div class="api-signature">

`friend` `constexpr` `bool` **`operator==`**([`Device`](./Device.md) `a`, [`Device`](./Device.md) `b`) `noexcept`

</div>

True when `a` and `b` match in both api and index.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 111

</div>

### operator\!= {#operator-ne}

<div class="api-signature">

`friend` `constexpr` `bool` **`operator!=`**([`Device`](./Device.md) `a`, [`Device`](./Device.md) `b`) `noexcept`

</div>

True when `a` and `b` differ.

<div class="api-declared">

Declared in `ClikaRT/compute/device.h`, line 115

</div>
