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

◆ take() [2/2]

std::optional< TensorImport > MayaFlux::Kakshya::TensorImport::take ( DLManagedTensorVersioned * managed)
staticnodiscard

Take ownership of a versioned DLPack tensor.

Parameters
managedTensor from a producer. Always consumed: its deleter is called on rejection as the protocol requires.
Returns
Import, or std::nullopt for a null pointer, a different major version, a device the host cannot read or an unusable layout.

Definition at line 212 of file TensorDLPack.cpp.

213{
214 if (!managed)
215 return std::nullopt;
216
217 const std::function<void()> release = [managed] {
218 if (managed->deleter)
219 managed->deleter(managed);
220 };
221
222 if (managed->version.major != DLPACK_MAJOR_VERSION)
223 return reject(release, "unsupported DLPack major version " + std::to_string(managed->version.major));
224 if ((managed->flags & DLPACK_FLAG_BITMASK_IS_SUBBYTE_TYPE_PADDED) != 0)
225 return reject(release, "padded sub-byte element storage is not supported");
226
227 TensorSpec spec;
228 if (const auto why = spec_from(managed->dl_tensor, spec); !why.empty())
229 return reject(release, why);
230
231 const bool empty = spec.element_count().value_or(0) == 0;
232 if (empty)
233 spec.byte_offset = 0;
234 const auto range = spec.byte_range();
235 if (!range)
236 return reject(release, spec.diagnose());
237
238 const auto* data = static_cast<const std::byte*>(managed->dl_tensor.data);
239 const size_t size = empty ? 0 : static_cast<size_t>(range->second);
240 if (!empty && !data)
241 return reject(release, "null data pointer for a non-empty tensor");
242
243 const bool read_only = (managed->flags & DLPACK_FLAG_BITMASK_READ_ONLY) != 0;
244 TensorImport imported(std::move(spec), data, size, read_only, release);
245 if (!imported.access()) {
246 imported.m_release = nullptr;
247 return reject(release, "tensor layout is not valid host memory");
248 }
249 return imported;
250}
const TensorSpec & spec() const noexcept
Layout described by the producer.
TensorImport(TensorImport &&other) noexcept
bool read_only() const noexcept
Whether the producer marked the tensor read-only.
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 access(), m_release, read_only(), spec(), and TensorImport().

Referenced by operator=().

Here is the call graph for this function:
Here is the caller graph for this function: