---
title: "ClikaRT::ops::to"
sidebar_label: "to"
description: "Moves a tensor to a device or stream. Already-resident inputs pass through (no transfer)."
---

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

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

3 overloads.

## to(Tensor, StreamOrDevice) {#to}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`to`**([`Tensor`](../Tensor.md) `src`, [`StreamOrDevice`](../StreamOrDevice.md) `target` `=` `{}`)

</div>

Moves a tensor to a device or stream.

Already-resident inputs pass through (no transfer). The result is produced on `target`'s stream; downstream ops on that stream order after the transfer automatically.

**Parameters**

- `src`: the source tensor.
- `target`: destination stream or device. Default: `src`'s stream.

**Throws**

- `ClikaRT::Error`: when the input's dtype/shape is not served for this operation (the machine-readable reason rides `code_name()`).

**Returns:** the tensor on the destination device.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2096

</div>

## to(Span\< Tensor\>, StreamOrDevice) {#to-2}

<div class="api-signature">

`std::vector<`[`Tensor`](../Tensor.md)`>` **`to`**([`ClikaRT::Span`](../Span.md)`<const` [`Tensor`](../Tensor.md)`>` `tensors`, [`StreamOrDevice`](../StreamOrDevice.md) `target` `=` `{}`)

</div>

Multi-tensor [`to`](./to.md#to): moves a batch in ONE call; the batched transfer beats N single moves when several tensors cross together (one submission, one ordering point).

**Parameters**

- `tensors`: the tensors to move.
- `target`: destination stream or device.

**Throws**

- `ClikaRT::Error`: when the input's dtype/shape is not served for this operation (the machine-readable reason rides `code_name()`).

**Returns:** the moved tensors, in input order.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2106

</div>

## to(Tensor, string\_view) {#to-3}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`to`**([`Tensor`](../Tensor.md) `src`, `std::string_view` `device_str`)

</div>

String-addressed [`to`](./to.md#to): the device is named by string: `"cpu"`, `"cuda"`, `"cuda:1"`, ….

**Parameters**

- `src`: the source tensor.
- `device_str`: the device name.

**Throws**

- `ClikaRT::Error`: when the string names no available device, or the transfer cannot be served (`code_name()` carries the reason).

**Returns:** the tensor on the named device.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2116

</div>
