# Residency

> Where the payload lives is the constructor's name, as in the C lifecycle verbs, so a residency an index lacks has no constructor to call.

`#include <usearch/types.hpp>` 3.0.0-rc.1 · cabb6603

Where the payload lives is the constructor’s name, as in the C lifecycle verbs, so a residency an index lacks has no constructor to call. Each takes only the placement its own hardware has, as memory domains, devices or paths with one shard per entry, and an empty list derives the placement: every NUMA node, device zero, or wherever the manifest points.

```cpp
std::int32_t const sockets[2] = {0, 1}, gpus[4] = {0, 1, 2, 3}, key_nodes[1] = {0};
usearch_bytes_view_t const drives[1] = {us::bytes_view("/mnt/nvme0")};
usearch_ram_options_t const keys_in_ram {.memory_domains = key_nodes, .memory_domains_count = 1};

auto [in_ram, in_ram_status] = us::dense_index_t::init_ram( // one graph per socket
    {.metric = metric, .quantization = usearch_scalar_bf16_k, .dimensions = 768,
     .ram = {.memory_domains = sockets, .memory_domains_count = 2}});
auto [in_vram, in_vram_status] = us::dense_index_t::init_vram( // sharded, never replicated
    {.metric = metric, .quantization = usearch_scalar_bf16_k, .dimensions = 768,
     .vram = {.devices = gpus, .devices_count = 4}});
auto [on_nvme, on_nvme_status] = us::dense_index_t::view_nvme(
    {.path = us::bytes_view("index.safegraphs"), .nvme = {.paths = drives, .paths_count = 1}, // striped across the drives
     .ram = &keys_in_ram},                                                                    // keys resolved through RAM
    rings);
```

An NVMe handle serves a checkpoint in place and is read-only, so every mutating verb fails on it with `status_code_t::read_only_k`. Without `ram`, it holds nothing per entry, so `count`, `get`, `sample`, MaxSim and hinted searches fail with `status_code_t::unsupported_k`. `load_nvme` takes the same arguments and opens a manifest writable, so `refine` rewrites its parts one at a time, while a lone monolith fails with `status_code_t::unsupported_k`. Bigger indexes come from merging, never mutating: shards build in RAM, serialize, and join a manifest.

## API

### Functions

#### `gpu_devices`

Fills `devices` with the GPUs this process can drive, NVIDIA first, then AMD, then Apple, so a device's position is the ordinal `executor_t::for_vram` names it by, answering how many there are, which may exceed what `devices` holds.

[types.hpp:713 ↗](https://github.com/unum-cloud/USearch/blob/cabb660355b45ed0d6ade2dc86ca58be01d61e29/cpp/usearch/types.hpp#L713)

```cpp
expected<std::size_t> gpu_devices(
    std::span<usearch_gpu_device_t> devices) noexcept;
```
