---
title: "Device"
sidebar_label: "Device"
description: "The clika_runtime Device class."
---

<!-- Generated by tools/api_reference/generate_api_docs.py. Do not edit. -->

A compute device: a backend (cpu, cuda, vulkan, metal, htp, tpu) plus a device index. Built from the strings torch users type ("cpu", "cuda:0"); str(device) gives that string back.

## `index` (property)

The device index within its backend (-1 for the whole-machine cpu).

## `type` (property)

The backend name: "cpu", "cuda", "vulkan", "metal", "htp" or "tpu".

## `__init__`

```python
__init____init__(self, spec: str) -> None
```

__init__(self, spec: str) -> None
__init__(self, type: str, index: int) -> None

Overloaded function.

1. ``__init__(self, spec: str) -> None``

A device from its string form (the parse() grammar). Strings also convert implicitly, so device="cpu" works wherever a Device is taken.

2. ``__init__(self, type: str, index: int) -> None``

A device from a backend name and an index: Device("cuda", 0).

## `cpu`

```python
cpucpu(index: int = -1) -> clika_runtime._core.Device
```

cpu(index: int = -1) -> clika_runtime._core.Device

The whole-machine CPU by default; a non-negative index names one socket.

## `gpu`

```python
gpugpu(index: int = 0) -> clika_runtime._core.Device
```

gpu(index: int = 0) -> clika_runtime._core.Device

The generic accelerator (resolved at call time; falls back to cpu() when no GPU backend is available).

## `parse`

```python
parseparse(spec: str) -> clika_runtime._core.Device
```

parse(spec: str) -> clika_runtime._core.Device

Parse "<api>" or "<api>:<index>" (cpu/gpu/cuda/vulkan/metal/htp/tpu); an unknown form raises InvalidArgumentError.
