10 if (
const auto reason =
spec.diagnose(); !reason.empty()) {
12 "as_tensor_access: {}", reason);
15 if (!
spec.device.is_host_accessible()) {
17 "as_tensor_access: tensor '{}' lives on a device the host cannot read",
spec.name);
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());
34 return m_spec.element_count().value_or(0);
47 if (!first || !
m_spec.is_contiguous())
50 return size ? std::span<const std::byte>(first, *size) : std::span<const std::byte> {};
55 const auto raw =
bytes();
56 return { .data = raw.data(), .bytes = raw.size(), .format =
m_spec.dtype.gpu_format() };
#define MF_ERROR(comp, ctx,...)
bool read_only() const noexcept
Whether writers must treat the memory as immutable.
TensorGpuView gpu_view() const noexcept
Upload description for a dense tensor.
TensorAccess(std::span< const std::byte > storage, TensorSpec spec, bool read_only)
std::span< const std::byte > bytes() const noexcept
Bytes of the elements when they are dense in C order.
uint64_t element_count() const noexcept
Number of elements.
std::span< const std::byte > m_storage
const TensorSpec & spec() const noexcept
Layout of the borrowed memory.
std::span< const std::byte > storage() const noexcept
The whole borrowed region.
const std::byte * element_data() const noexcept
Pointer to element zero, or nullptr for an empty tensor.
@ Runtime
General runtime operations (default fallback).
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
std::optional< TensorAccess > as_tensor_access(std::span< const std::byte > storage, const TensorSpec &spec, bool read_only)
Validate and borrow tensor memory.
Pointer, byte count and element format for uploading a tensor.
Complete description of a tensor: type, shape, layout, meaning.