![]() |
Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
|
DEMO |
Exports and imports Signet tensors via DLPack, enabling zero-copy interoperability with PyTorch, NumPy, JAX, and other DLPack-aware frameworks. More...
#include <numpy_bridge.hpp>
Static Public Member Functions | |
| static expected< DLManagedTensor * > | export_tensor (const TensorView &tensor) |
| Export a TensorView as a DLManagedTensor (zero-copy, non-owning). | |
| static expected< DLManagedTensor * > | export_owned_tensor (OwnedTensor &&tensor) |
| Export an OwnedTensor as a DLManagedTensor (zero-copy ownership transfer). | |
| static expected< TensorView > | import_tensor (const DLManagedTensor *managed) |
| Import a DLManagedTensor as a TensorView (zero-copy). | |
| static expected< OwnedTensor > | import_tensor_copy (const DLManagedTensor *managed) |
| Import a DLManagedTensor as an OwnedTensor (deep copy). | |
Exports and imports Signet tensors via DLPack, enabling zero-copy interoperability with PyTorch, NumPy, JAX, and other DLPack-aware frameworks.
Three export modes:
Two import modes:
Definition at line 329 of file numpy_bridge.hpp.
|
inlinestatic |
Export an OwnedTensor as a DLManagedTensor (zero-copy ownership transfer).
The OwnedTensor is moved into the DLManagedTensor's manager context. When the consumer calls the deleter, the OwnedTensor (and its data) is freed. This is a true zero-copy ownership transfer – no data is copied and no source lifetime constraints apply.
| tensor | An OwnedTensor to transfer (moved from; left in a valid but unspecified state after the call). |
Definition at line 391 of file numpy_bridge.hpp.
|
inlinestatic |
Export a TensorView as a DLManagedTensor (zero-copy, non-owning).
The TensorView's data is NOT copied. The returned DLManagedTensor's DLTensor.data points directly into the TensorView's memory.
IMPORTANT: The TensorView (and its underlying data) must outlive the DLManagedTensor. The consumer calls deleter() when done, which frees only the DLManagedTensor and its helper arrays, NOT the data.
| tensor | A valid, contiguous TensorView. |
Definition at line 345 of file numpy_bridge.hpp.
|
inlinestatic |
Import a DLManagedTensor as a TensorView (zero-copy).
The returned TensorView wraps the DLTensor's data directly. The DLManagedTensor (and thus the underlying data) must remain valid for the lifetime of the TensorView. The caller is still responsible for calling the DLManagedTensor's deleter when done.
Only CPU and CUDAHost tensors are supported. Non-CPU devices are rejected. Strided (non-contiguous) tensors are rejected unless the strides match C-contiguous layout exactly.
| managed | A valid DLManagedTensor (must not be null). |
Definition at line 443 of file numpy_bridge.hpp.
|
inlinestatic |
Import a DLManagedTensor as an OwnedTensor (deep copy).
Copies the data from the DLPack tensor into a new heap allocation. After this call returns, the DLManagedTensor can be released independently – the OwnedTensor owns its data.
Only CPU and CUDAHost tensors are supported. Strided (non-contiguous) tensors ARE supported – data is gathered into a contiguous C-order layout via element-by-element copy.
For contiguous tensors, a fast memcpy path is used. For strided tensors, a multi-index iteration walks the source layout.
| managed | A valid DLManagedTensor (must not be null). |
Definition at line 554 of file numpy_bridge.hpp.