---
title: "ClikaRT::placement::PlacementScope"
sidebar_label: "PlacementScope"
description: "RAII region: sets the calling thread's ambient placement on construction and restores the previous one on destruction (normal exit and exception unwind alike)."
---

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

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

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

Ambient placement: a per-thread default `StreamOrDevice` that ops use when a call does not name a stream or device. Set it for a region with the RAII `PlacementScope`, or directly with `set_ambient()`. Every placement parameter's unspecified form consults the ambient (see `StreamOrDevice::resolve()`), so the whole op surface honors it with no per-call plumbing. An explicit stream argument always wins; an explicit device names placement: the work follows its inputs and otherwise takes the calling thread's current lane on that device, the ambient's stream when the scope set one there, otherwise the thread's own asynchronous lane (`StreamOrDevice(device).resolve()` names it). A device's default stream is never chosen on its own; scope one explicitly (`PlacementScope(Stream::default_stream(d))`) to run synchronously.

The ambient is per-thread. Setting it on one thread never affects work dispatched from another, and a traced capture resolves the ambient at capture time (the recorded graph keeps the placement it was captured with).

```text
ClikaRT::placement::PlacementScope scope(gpu0);
auto y = ClikaRT::ops::add(a, b);   // runs on the thread's lane for gpu0
// scope ends: the previous ambient is restored
```

RAII region: sets the calling thread's ambient placement on construction and restores the previous one on destruction (normal exit and exception unwind alike). Scopes nest; each restores exactly what it displaced. Not copyable or movable: the scope is bound to the thread and region that created it.

## Member functions

### PlacementScope(StreamOrDevice) {#PlacementScope}

<div class="api-signature">

`explicit` **`PlacementScope`**([`StreamOrDevice`](../StreamOrDevice.md) `value`)

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/placement.h`, line 49

</div>

### \~PlacementScope() {#PlacementScope-2}

<div class="api-signature">

**`~PlacementScope`**()

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/placement.h`, line 51

</div>

### PlacementScope(PlacementScope) {#PlacementScope-3}

<div class="api-signature">

**`PlacementScope`**(`const PlacementScope&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/placement.h`, line 53

</div>

### operator=(PlacementScope) {#operator-assign}

<div class="api-signature">

[`PlacementScope`](./PlacementScope.md)`&` **`operator=`**(`const` [`PlacementScope`](./PlacementScope.md)`&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/placement.h`, line 54

</div>

### PlacementScope(PlacementScope) {#PlacementScope-4}

<div class="api-signature">

**`PlacementScope`**(`PlacementScope&&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/placement.h`, line 55

</div>

### operator=(PlacementScope) {#operator-assign-2}

<div class="api-signature">

[`PlacementScope`](./PlacementScope.md)`&` **`operator=`**([`PlacementScope`](./PlacementScope.md)`&&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/compute/placement.h`, line 56

</div>
