MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ as_tensor_access

MAYAFLUX_API std::optional< TensorAccess > as_tensor_access ( std::span< const std::byte > storage,
const TensorSpec & spec,
bool read_only = true )
friend

Validate and borrow tensor memory.

Parameters
storageMemory the spec addresses, from its first byte.
specLayout to interpret the memory with.
read_onlyWhether writers must treat the memory as immutable.
Returns
Access view, or std::nullopt (with the reason logged) when the spec is inconsistent, addresses memory outside storage, or lives on a device the host cannot read.

Definition at line 7 of file TensorAccess.cpp.

9{
10 if (const auto reason = spec.diagnose(); !reason.empty()) {
12 "as_tensor_access: {}", reason);
13 return std::nullopt;
14 }
15 if (!spec.device.is_host_accessible()) {
17 "as_tensor_access: tensor '{}' lives on a device the host cannot read", spec.name);
18 return std::nullopt;
19 }
20
21 const auto range = spec.byte_range();
22 if (!range || range->second > storage.size()) {
24 "as_tensor_access: tensor '{}' needs {} bytes but {} are available",
25 spec.name, range ? range->second : 0, storage.size());
26 return std::nullopt;
27 }
28
30}
#define MF_ERROR(comp, ctx,...)
bool read_only() const noexcept
Whether writers must treat the memory as immutable.
TensorAccess(std::span< const std::byte > storage, TensorSpec spec, bool read_only)
const TensorSpec & spec() const noexcept
Layout of the borrowed memory.
std::span< const std::byte > storage() const noexcept
The whole borrowed region.
@ Runtime
General runtime operations (default fallback).
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
std::vector< double > range(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Value range (max - min) per window.
Definition Analysis.cpp:473

References MayaFlux::Journal::Kakshya, MF_ERROR, read_only(), MayaFlux::Journal::Runtime, spec(), storage(), and TensorAccess().