ClikaRT::ops::from_blob
function
from_blob()
Tensor from_blob(
void* data,
ClikaRT::Span<const std::int64_t> shape,
DataType dtype,
StreamOrDevice s = {},
ClikaRT::Span<const std::int64_t> strides = {},
std::function<void(void *)> deleter = {},
StreamOrDevice pinned_for = {}
)
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. 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.s: 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 withdatawhen the last alias drops; empty = the caller keeps ownership. Default: empty.pinned_for: marks the host buffer as pinned for a peer device (seeempty). 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.
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.
Declared in ClikaRT/compute/ops.h, line 2298