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

◆ as_tensor_access()

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

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
29 return TensorAccess(storage, spec, read_only);
30}
#define MF_ERROR(comp, ctx,...)
Validated, non-owning view of tensor memory and its layout.
@ Runtime
General runtime operations (default fallback).
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
constexpr bool is_host_accessible() const noexcept
Whether the host can read this memory directly.
std::optional< std::pair< uint64_t, uint64_t > > byte_range() const noexcept
Storage bytes [first, last) the spec addresses, from storage start.
std::string diagnose() const
Empty when the spec is self-consistent, otherwise the reason it is not.

Referenced by MayaFlux::Kakshya::TensorData::access(), MayaFlux::Kakshya::TensorImport::access(), and MayaFlux::Kakshya::TensorContainer::view().

Here is the caller graph for this function: