Struct anira::Tensor#
-
struct Tensor : public anira_tensor#
Inheritance diagram for anira::Tensor:
![digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"1" [label="anira::Tensor" tooltip="anira::Tensor" fillcolor="#BFBFBF"]
"2" [label="anira_tensor" tooltip="anira_tensor"]
"1" -> "2" [dir=forward tooltip="public-inheritance"]
}](../../_images/graphviz-cda7c70640528a5cfbb0afa417b7dd108d0fb9af.png)
Collaboration diagram for anira::Tensor:
![digraph {
graph [bgcolor="#00000000"]
node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
edge [color="#1414CE"]
"1" [label="anira::Tensor" tooltip="anira::Tensor" fillcolor="#BFBFBF"]
"3" [label="anira_memory_handle" tooltip="anira_memory_handle"]
"4" [label="anira_sync_token" tooltip="anira_sync_token"]
"2" [label="anira_tensor" tooltip="anira_tensor"]
"1" -> "2" [dir=forward tooltip="public-inheritance"]
"2" -> "3" [dir=forward tooltip="usage"]
"2" -> "4" [dir=forward tooltip="usage"]
}](../../_images/graphviz-327ea38d25896554463d436910bd73ed682eba78.png)
anira_tensor with names and factories on it: the C struct itself (216 bytes, trivially copyable, no member added), so a Tensor* is an anira_tensor*.
The from_* factories are the anira_tensor_init_* field fills over a std::span shape: [thread-safe] [callback-safe], real-time, noexcept. They refuse like the C entries: dtype 0, more than ANIRA_MAX_RANK extents or a negative extent give the all-zero record (dtype 0). Only from_dlpack can fail with a message and throws. The factories of the draft platform arms (anira/abi/draft/tensor_platform.h) have no C++ spelling while they are unmeasured: call anira_tensor_init_metal(&tensor, …) and its siblings on a Tensor.
Public Functions
-
inline float *data_f32() const noexcept#
anira_tensor_data_f32: the first element of a one-block host float32 tensor, nullptr otherwise (a device tensor, another dtype, a planar tensor).
-
inline void *data(DType element_dtype) const noexcept#
anira_tensor_data: the first element of a host tensor whose dtype equals the argument, nullptr otherwise; never converts.
-
template<class T>
inline T *plane(uint32_t index) const noexcept# anira_tensor_plane: the first element of one plane of a planar host tensor whose dtype is T’s, nullptr otherwise (a one-block tensor, a plane out of range, another dtype).
-
inline std::size_t num_elements() const noexcept#
anira_tensor_num_elements: the product of the extents, 1 at rank 0, 0 for the all-zero record of a refused factory.
-
inline std::size_t extent(uint32_t axis) const noexcept#
anira_tensor_extent: one extent, 0 for an axis at or above ndim.
Public Static Functions
-
static inline Tensor from_host(void *data, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_host: pageable host memory, borrowed.
-
static inline Tensor from_pinned(void *data, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_pinned: page-locked host memory, borrowed.
-
template<class T>
static inline Tensor from_host_planar(std::span<T*const> planes, std::span<const int64_t> extents) noexcept# anira_tensor_init_host_planar: planar host memory, one pointer per plane of axis 0 (the channel pointers of an audio host), borrowed like the memory. The element type names the dtype and is spelled at the call, Tensor::from_host_planar<float>(channels, shape); the span’s size must equal shape[0], else the all-zero record comes back, as in C. A const element type sets ANIRA_TENSOR_READ_ONLY. Only an entry that says so accepts a planar tensor.
-
static inline Tensor from_cuda(void *ptr, int32_t device, void *event, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_cuda: a device pointer; event is a cudaEvent_t or nullptr (visible).
-
static inline Tensor from_gl_buffer(uint32_t id, uint32_t target, void *glsync, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_gl_buffer: a GL buffer object; glsync is a GLsync or nullptr (visible).
-
static inline Tensor from_vulkan(uint64_t buffer, uint64_t memory, uint64_t offset, uint64_t timeline, uint64_t value, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_vulkan: VkBuffer, VkDeviceMemory and offset at their wire width; a timeline semaphore of 0 means visible.
-
static inline Tensor from_opaque_fd(int32_t fd, uint64_t size, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_opaque_fd: exported opaque memory; no fence.
-
static inline Tensor from_wgpu_buffer(void *buffer, uint64_t offset, const SyncToken *fence, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_wgpu_buffer: the fence is copied into acquire and that copy is the hand-off (the caller does not reset its source); nullptr means visible.
-
static inline Tensor from_dmabuf(int32_t fd, uint64_t size, uint64_t offset, int32_t sync_fd, DType element_dtype, std::span<const int64_t> extents) noexcept#
anira_tensor_init_dmabuf: exported buffer memory; a sync_fd of 0 or more is owned by the tensor’s acquire token from here on, a negative one means visible.
-
static inline Tensor from_dlpack(void *dl_managed_tensor_versioned)#
anira_tensor_init_dlpack over a DLManagedTensorVersioned* of DLPack major 1 ([main-thread]). On success the managed tensor belongs to the record and release calls its deleter once; on failure this throws anira::Error and the caller keeps the managed tensor.
-
inline float *data_f32() const noexcept#