![]() |
Zivid C++ API 2.18.0+1b44dbef-1
|
Reference-counted handle to data on a GPU device. More...
#include <Zivid/DeviceArray.h>
Public Member Functions | |
| DeviceArray ()=default | |
| Default constructor - creates an empty DeviceArray. | |
| ~DeviceArray ()=default | |
| Destructor - releases reference to the underlying buffer. | |
| DeviceArray (const DeviceArray &other)=default | |
| Copy constructor - shares ownership of the buffer. | |
| DeviceArray & | operator= (const DeviceArray &other)=default |
| Copy assignment - shares ownership of the buffer. | |
| DeviceArray (DeviceArray &&other) noexcept=default | |
| Move constructor. | |
| DeviceArray & | operator= (DeviceArray &&other) noexcept=default |
| Move assignment. | |
| void * | devicePointer () const |
| Get the raw GPU device pointer to the data. | |
| std::vector< int > | shape () const |
| Get the shape of the data. | |
| std::vector< int > | strides () const |
| Get the strides of the data in element count. | |
| std::vector< int > | stridesInBytes () const |
| Get the strides of the data in bytes. | |
| size_t | size () const |
| Get the total number of elements in the data. | |
| size_t | sizeInBytes () const |
| Get the total size of the data in bytes. | |
| ComputeBackend | backend () const |
| Get the GPU compute backend type of this buffer. | |
| bool | isValid () const |
| Check if the buffer is valid (not empty) | |
| bool | isEmpty () const |
| Check if the buffer is empty. | |
| Array2D< Format > | toArray2D (StreamOrQueue streamOrQueue) const |
| Copy device buffer data to host and return as Array2D. | |
| Array1D< Format > | toArray1D (StreamOrQueue streamOrQueue) const |
| Copy device buffer data to host and return as Array1D. | |
| void | copyToHost (Format *destination, size_t sizeInBytes, StreamOrQueue streamOrQueue) const |
| Copy device buffer data to host memory. | |
Reference-counted handle to data on a GPU device.
The underlying device buffer is reference counted and will remain valid as long as any DeviceArray instance references it.
The buffer provides access to a raw device pointer that can be used with GPU compute frameworks (such as CUDA), compute libraries, or other GPU frameworks for efficient processing without CPU transfers.
Obtain a DeviceArray from a PointCloud using methods like devicePointsXYZ(), devicePointsXYZW(), deviceSNRs(), deviceNormalsXYZ(), deviceImageRGBA(), etc. The acquisition method takes a user stream or queue and synchronizes the SDK's compute stream into it before returning. The returned DeviceArray is therefore already ordered against the caller's stream/queue, and devicePointer() is a plain accessor.
Lifetime: a DeviceArray allocated by the SDK must not outlive the Zivid Application that produced it. For device memory that needs to outlive the Application, allocate the buffer yourself and pass it into the fill variant of the acquisition method (e.g. imageDeviceArray<Format>(streamOrQueue, destinationBuffer)).
Example usage:
|
default |
Default constructor - creates an empty DeviceArray.
|
default |
Destructor - releases reference to the underlying buffer.
|
default |
Copy constructor - shares ownership of the buffer.
|
defaultnoexcept |
Move constructor.
| ComputeBackend Zivid::DeviceArray< Format >::backend | ( | ) | const |
Get the GPU compute backend type of this buffer.
| void Zivid::DeviceArray< Format >::copyToHost | ( | Format * | destination, |
| size_t | sizeInBytes, | ||
| StreamOrQueue | streamOrQueue ) const |
Copy device buffer data to host memory.
| destination | Pointer to host memory where data will be copied |
| sizeInBytes | Size of the destination buffer in bytes |
| streamOrQueue | The CUDA stream / OpenCL command queue to enqueue the D2H copy on |
Enqueues the device-to-host copy on streamOrQueue and returns immediately. The caller is responsible for synchronizing streamOrQueue (e.g. via Zivid::synchronizeStream) before reading from destination. The caller must also ensure that the destination buffer is large enough to hold the data.
Pass the same stream/queue that was used at acquisition so the D2H copy is correctly ordered against the SDK's compute. For a blocking copy that does the sync internally, use the parameterless host accessors on the originating Frame2D / PointCloud.
| void * Zivid::DeviceArray< Format >::devicePointer | ( | ) | const |
Get the raw GPU device pointer to the data.
No synchronization is performed. The DeviceArray was already synchronized against the caller's stream/queue at acquisition time by the method that produced it (e.g. Frame2D::imageDeviceArray, PointCloud::devicePointsXYZ). Callers can use the pointer on that same stream/queue immediately.
The returned pointer is only valid as long as this DeviceArray (or a copy) exists, and only while the Zivid Application that produced the DeviceArray is alive.
| bool Zivid::DeviceArray< Format >::isEmpty | ( | ) | const |
Check if the buffer is empty.
| bool Zivid::DeviceArray< Format >::isValid | ( | ) | const |
Check if the buffer is valid (not empty)
|
default |
Copy assignment - shares ownership of the buffer.
|
defaultnoexcept |
Move assignment.
| std::vector< int > Zivid::DeviceArray< Format >::shape | ( | ) | const |
Get the shape of the data.
| size_t Zivid::DeviceArray< Format >::size | ( | ) | const |
Get the total number of elements in the data.
| size_t Zivid::DeviceArray< Format >::sizeInBytes | ( | ) | const |
Get the total size of the data in bytes.
| std::vector< int > Zivid::DeviceArray< Format >::strides | ( | ) | const |
Get the strides of the data in element count.
| std::vector< int > Zivid::DeviceArray< Format >::stridesInBytes | ( | ) | const |
Get the strides of the data in bytes.
| Array1D< Format > Zivid::DeviceArray< Format >::toArray1D | ( | StreamOrQueue | streamOrQueue | ) | const |
Copy device buffer data to host and return as Array1D.
| streamOrQueue | The CUDA stream / OpenCL command queue to enqueue the D2H copy on |
Valid for all DeviceArray formats: PointXYZ, PointXYZW, PointZ, SNR, NormalXYZ, ColorRGBA, ColorRGBA_SRGB, ColorBGRA, ColorBGRA_SRGB, and ColorRGBAf. Throws an exception if the DeviceArray is not from an unorganized point cloud.
The D2H copy is enqueued on streamOrQueue and the function returns immediately; the host memory behind the returned Array1D is NOT safe to read until the caller synchronizes streamOrQueue (e.g. via Zivid::synchronizeStream). For a blocking copy, use the parameterless host accessors on the originating UnorganizedPointCloud (e.g. UnorganizedPointCloud::pointsXYZ).
| Array2D< Format > Zivid::DeviceArray< Format >::toArray2D | ( | StreamOrQueue | streamOrQueue | ) | const |
Copy device buffer data to host and return as Array2D.
| streamOrQueue | The CUDA stream / OpenCL command queue to enqueue the D2H copy on |
Valid for all DeviceArray formats: PointXYZ, PointXYZW, PointZ, SNR, NormalXYZ, ColorRGBA, ColorRGBA_SRGB, ColorBGRA, ColorBGRA_SRGB, and ColorRGBAf. Throws an exception if the DeviceArray is not from an organized point cloud or from Frame2D.
The D2H copy is enqueued on streamOrQueue and the function returns immediately; the host memory behind the returned Array2D is NOT safe to read until the caller synchronizes streamOrQueue (e.g. via Zivid::synchronizeStream). Pass the same stream/queue that was used at acquisition (e.g. with PointCloud::devicePointsXYZ or Frame2D::imageDeviceArray) so the D2H copy is correctly ordered against the SDK's compute.
If you don't want to manage stream synchronization yourself, use the parameterless host accessors on the originating Frame2D / PointCloud (e.g. PointCloud::pointXYZArray, Frame2D::imageRGBA); those return host-ready Array2D / Image using the SDK's internal stream.