---
title: "ClikaRT::ops::from_blob"
sidebar_label: "from_blob"
description: "Wrap caller-owned memory as a Tensor (no copy, no allocation). The tensor BORROWS data: keep the buffer alive until the last tensor aliasing it is destroyed."
---

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

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

## from\_blob() {#from_blob}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`from_blob`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`void*` `data`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `shape`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`DataType`](../../index.md#DataType) `dtype`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `device` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `strides` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`std::function<void(void *)>` `deleter` `=` `{}`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`StreamOrDevice`](../StreamOrDevice.md) `pinned_for` `=` `{}`<br />
)

</div>

Wrap caller-owned memory as a [Tensor](../Tensor.md) (no copy, no allocation).

The tensor BORROWS `data`: keep the buffer alive until the last tensor aliasing it is destroyed. Pass a `deleter` to hand ownership over; it is invoked exactly once, when the last alias drops.

**Parameters**

- `data`: the caller's buffer (lifetime rules above).
- `shape`: extents, one per dim.
- `dtype`: how the bytes are typed.
- `device`: the stream/device the memory belongs to (a host pointer = the CPU). Default: the default device.
- `strides`: element strides; empty = packed row-major. Default: empty.
- `deleter`: called with `data` when the last alias drops; empty = the caller keeps ownership. Default: empty.
- `pinned_for`: marks the host buffer as pinned for a peer device (see [`empty`](./empty.md#empty)). Default: absent.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when the shape/stride description is inconsistent (`code_name()` carries the reason).

**Returns:** a tensor viewing the caller's memory.

```cpp
std::vector<float> host(n);
auto t = ClikaRT::ops::from_blob(host.data(), {n}, ClikaRT::DataType::Float32);
// `host` must outlive `t` and every view of it.
```

<div class="api-declared">

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

</div>
