GenericBufferBase#
Fully qualified name: isaacsim::core::includes::GenericBufferBase
-
template<typename T>
class GenericBufferBase : public isaacsim::core::includes::Buffer<T># Device-generic (CPU or CUDA device) memory buffer implementation.
Manages a buffer of memory allocated in host RAM (using std::vector) or on a CUDA device. Provides functionality for:
Memory allocation and deallocation.
Device selection and switching (with or without data transfer).
Memory copying between host and device.
Fill the buffer with a constant value.
Generate a string representation of the buffer.
Note
Uses RAII principles for automatic resource management.
Warning
Requires proper CUDA environment setup and Unified Virtual Address (UVA) space.
- Template Parameters:
T – The data type stored in the buffer.
Public Functions
-
inline GenericBufferBase(const size_t &size = 0, const int device = -1)#
Construct a new device-generic (CPU or CUDA device) buffer.
- Parameters:
size – [in] Initial size of the buffer in elements.
device – [in] CUDA device ID (higher or equal to 0) to allocate on or -1 for CPU.
-
inline virtual ~GenericBufferBase()#
Destructor that ensures proper cleanup of allocated memory.
-
inline virtual T *data() const#
Gets a pointer to the buffer’s data.
- Returns:
Pointer to the buffer’s data.
-
inline virtual size_t size() const#
Gets the current size of the buffer.
- Returns:
Number of elements in the buffer.
-
inline virtual void clear()#
Clear the buffer.
Clear the buffer by freeing the memory and resetting the size to 0.
- inline virtual bool setDevice(
- const int device = -1,
- bool keepData = false,
Changes the 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 (higher or equal to 0) or -1 for CPU.
keepData – [in] If true, the data from the old device is kept on the new device.
- Returns:
True if the device was changed, false otherwise.
-
inline virtual void resize(size_t size)#
Resizes the device buffer (synchronous version of resizeAsync).
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.
- Returns:
True if the size was changed, false otherwise.
- inline virtual void resizeAsync(
- size_t size,
- cudaStream_t cudaStream = 0,
Resizes the device buffer asynchronously (asynchronous version of resize).
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 the operation.
- Returns:
True if the size was changed, false otherwise.
-
inline virtual void copyTo(void *dst, size_t size)#
Copies the buffer’s data to a destination memory (synchronous version of copyToAsync).
Note
If the specified size is greater than the buffer size, only the first
.size()elements are copied. A warning message is logged in this case.- Parameters:
dst – [out] Destination pointer to copy to.
size – [in] Number of elements to copy.
- inline virtual void copyToAsync(
- void *dst,
- size_t size,
- cudaStream_t cudaStream = 0,
Copies the buffer’s data to a destination memory asynchronously (asynchronous version of copyTo).
Note
If the specified size is greater than the buffer size, only the first
.size()elements are copied. A warning message is logged in this case.- Parameters:
dst – [out] Destination pointer to copy to.
size – [in] Number of elements to copy.
cudaStream – [in] CUDA stream to use for the operation.
-
inline virtual void copyFrom(const void *src, size_t size)#
Copies the buffer’s data from a source memory (synchronous version of copyFromAsync).
Note
If the specified size is greater than the buffer size, only the first
.size()elements are copied. A warning message is logged in this case.- Parameters:
src – [in] Source pointer to copy from.
size – [in] Number of elements to copy.
- inline virtual void copyFromAsync(
- const void *src,
- size_t size,
- cudaStream_t cudaStream = 0,
Copies the buffer’s data from a source memory asynchronously (asynchronous version of copyFrom).
Note
If the specified size is greater than the buffer size, only the first
.size()elements are copied. A warning message is logged in this case.- Parameters:
src – [in] Source pointer to copy from.
size – [in] Number of elements to copy.
cudaStream – [in] CUDA stream to use for the operation.
-
inline virtual bool fill(const T &value)#
Fills the buffer with a constant value (synchronous version of fillAsync).
Warning
Only data types of size 1, 2, and 4 bytes are supported. Using other data type sizes will log a warning.
- Parameters:
value – [in] Value to fill the buffer with.
- Returns:
True if the fill was successful, false otherwise.
- inline virtual bool fillAsync(
- const T &value,
- cudaStream_t cudaStream = 0,
Fills the buffer with a constant value asynchronously (asynchronous version of fill).
Warning
Only data types of size 1, 2, and 4 bytes are supported. Using other data type sizes will log a warning.
- Parameters:
value – [in] Value to fill the buffer with.
cudaStream – [in] CUDA stream to use for the operation.
- Returns:
True if the fill was successful, false otherwise.
-
inline std::string toString() const#
Generates a string representation of the buffer.
- Returns:
String representation of the buffer.
-
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.