DeviceBufferBase#
Fully qualified name: isaacsim::core::includes::DeviceBufferBase
-
template<typename T>
class DeviceBufferBase : public isaacsim::core::includes::Buffer<T># CUDA device (GPU) memory buffer implementation.
Manages a buffer of memory allocated on a CUDA device. Provides functionality for:
Memory allocation and deallocation
Device selection and switching
Memory copying between host and device
Debug printing of buffer contents
Note
Uses RAII principles for automatic resource management
Warning
Requires proper CUDA environment setup
- Template Parameters:
T – The data type stored in the buffer
Public Functions
-
inline DeviceBufferBase(const size_t &size = 0, const int device = -1)#
Constructs a new device buffer.
- Parameters:
size – [in] Initial size of the buffer in elements (default: 0)
device – [in] CUDA device ID to allocate on (default: -1 for CPU)
-
inline virtual ~DeviceBufferBase()#
Destructor that ensures proper cleanup of device memory.
-
inline virtual void setDevice(const int device = -1)#
Changes the CUDA device for this buffer.
If the device changes, existing memory is freed on the old device and reallocated on the new device.
- Parameters:
device – [in] New CUDA device ID (-1 for CPU)
-
inline virtual void resize(size_t size)#
Resizes the device buffer.
Reallocates memory if the new size is different from the current size. Handles deallocation of existing memory if necessary.
- Parameters:
size – [in] New size in number of elements
- inline virtual void resizeAsync(
- size_t size,
- cudaStream_t cudaStream = 0,
Asynchronously resizes the device buffer.
Reallocates memory if the new size is different from the current size. Handles deallocation of existing memory if necessary.
- Parameters:
size – [in] New size in number of elements
cudaStream – [in] CUDA stream to use for asynchronous operation
-
inline virtual T *data() const#
Gets a pointer to the device memory.
- Returns:
Raw pointer to the device memory
-
inline virtual size_t size() const#
Gets the current size of the buffer.
- Returns:
Number of elements in the buffer
- inline virtual void copy(
- const void *src,
- size_t size,
- enum cudaMemcpyKind kind = cudaMemcpyDeviceToHost,
Synchronously copies data to the device buffer.
- Parameters:
src – [in] Source pointer to copy from
size – [in] Number of elements to copy
kind – [in] Type of memory copy operation
- inline virtual void copyAsync(
- const void *src,
- size_t size,
- enum cudaMemcpyKind kind = cudaMemcpyDeviceToHost,
- cudaStream_t cudaStream = 0,
Asynchronously copies data to the device buffer.
- Parameters:
src – [in] Source pointer to copy from
size – [in] Number of elements to copy
kind – [in] Type of memory copy operation
cudaStream – [in] CUDA stream to use for the copy operation
- inline void debugPrint( )#
Prints the buffer contents for debugging.
- Parameters:
start – [in] String to print before the buffer contents
end – [in] String to print after the buffer contents
-
inline size_t sizeofType() const#
Gets the size of a single element in bytes.
- Returns:
Size of type T in bytes
-
inline size_t sizeInBytes() const#
Gets the total size of the buffer in bytes.
- Returns:
Total size of the buffer in bytes
-
inline MemoryType type() const#
Gets the memory type of the buffer.
- Returns:
Memory type (Host or Device)
Protected Attributes
-
MemoryType m_memoryType#
Type of memory where the buffer resides.