Stores an owned, contiguous sequence in CUDA device memory. More...
#include <DeviceVector.h>
Public Member Functions | |
| DeviceVector (void) | |
| Constructs an empty vector without owned device storage. | |
| DeviceVector (const std::size_t count) | |
| Constructs a vector with uninitialized device storage. | |
| DeviceVector (const std::vector< T > &other) | |
| Constructs a device vector by copying a host vector. | |
| DeviceVector (const std::vector< T > &&other) | |
| Constructs a device vector by copying a const host rvalue. | |
| DeviceVector (const DeviceVector< T > &other) | |
| Constructs an independent copy of another device vector. | |
| DeviceVector (const DeviceVector< T > &&other) | |
| Constructs an independent copy of a const device-vector rvalue. | |
| ~DeviceVector (void) noexcept | |
| Releases owned device storage without propagating CUDA failures. | |
| DeviceVector< T > & | operator= (const std::vector< T > &other) |
| Replaces the vector with a copy of a host vector. | |
| DeviceVector< T > & | operator= (const std::vector< T > &&other) |
| Replaces the vector with a copy of a const host rvalue. | |
| DeviceVector< T > & | operator= (const DeviceVector< T > &other) |
| Replaces the vector with a deep copy of another device vector. | |
| DeviceVector< T > & | operator= (const DeviceVector< T > &&other) |
| Replaces the vector with a deep copy of a const device-vector rvalue. | |
| const T * | data (void) const |
| Returns a read-only pointer to the owned device allocation. | |
| T * | data (void) |
| Returns a mutable pointer to the owned device allocation. | |
| void | assignData (T *data) |
| Replaces the stored device pointer without changing metadata. | |
| bool | empty (void) const |
| Returns whether the active element range is empty. | |
| std::size_t | size (void) const |
| Returns the number of active element slots. | |
| std::size_t | capacity (void) const |
| Returns the number of allocated element slots. | |
| void | shrink_to_fit (void) |
| Reduces device capacity to the current size. | |
| void | clear (void) |
| Releases all device storage and resets the vector. | |
| void | push_back (const T &value) |
| Appends one value to the active device sequence. | |
| void | resize (const std::size_t count) |
| Changes the number of active element slots. | |
| void | swap (DeviceVector< T > &other) noexcept |
| Exchanges allocation ownership and metadata with another vector. | |
Stores an owned, contiguous sequence in CUDA device memory.
DeviceVector owns one CUDA allocation containing capacity() adjacent element slots and identifies the active prefix with size(). It has no host mirror, iterator interface, stream member, or recorded CUDA device. Allocation and copy operations therefore use the CUDA runtime state current on the calling thread. Use CudaContainer when coordinated host and device representations are required.
Elements are handlded as raw storage. The container does not construct, destroy, or value-initialize individual elements. The specializations provided by the current apoCHARMM library are int, int2, int3, int4, unsigned int, float, float2, float3, float4, long long int, longlong2, longlong3, longlong4, unsigned long long int, std::size_t, double, double2, double3, and double4.
| T | Element representation stored in device memory. A specialization must be safe to copy byte-for-byte and pass by value to a CUDA kernel. |
data() are device pointers. Host code must not dereference them directly. | DeviceVector< T >::DeviceVector | ( | void | ) |
Constructs an empty vector without owned device storage.
empty() is true, size() and capacity() are zero, and data() is nullptr. | DeviceVector< T >::DeviceVector | ( | const std::size_t | count | ) |
Constructs a vector with uninitialized device storage.
| [in] | count | Number of active element slots to allocate. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if the CUDA allocation fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
count * sizeof(T) is representable as std::size_t. size() and capacity() equal count. A zero count produces data() == nullptr; otherwise data() identifies an owned device allocation. | DeviceVector< T >::DeviceVector | ( | const std::vector< T > & | other | ) |
Constructs a device vector by copying a host vector.
| [in] | other | Borrowed, read-only host vector. Its active elements are copied during the call, and no reference to it is retained. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if device allocation or the host-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() and capacity() equal other.size(), and the active device elements are an independent copy of other. cudaMemcpy without an explicit stream and performs no separate device synchronization. | DeviceVector< T >::DeviceVector | ( | const std::vector< T > && | other | ) |
Constructs a device vector by copying a const host rvalue.
| [in] | other | Borrowed, read-only host vector. Its active elements are copied during the call, and no reference to it is retained. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if device allocation or the host-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() and capacity() equal other.size(), and the active device elements are an independent copy of other. other; it performs the same host-to-device copy as the lvalue overload. cudaMemcpy without an explicit stream and performs no separate device synchronization. | DeviceVector< T >::DeviceVector | ( | const DeviceVector< T > & | other | ) |
Constructs an independent copy of another device vector.
| [in] | other | Borrowed, read-only source vector. Its active device elements are copied during the call, and no pointer into it is retained. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if device allocation or the device-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() and capacity() equal other.size(), and the active elements reside in an allocation independent of other. other is not copied. cudaMemcpy without an explicit stream and performs no separate device synchronization. | DeviceVector< T >::DeviceVector | ( | const DeviceVector< T > && | other | ) |
Constructs an independent copy of a const device-vector rvalue.
| [in] | other | Borrowed, read-only source vector. Its active device elements are copied during the call, and no pointer into it is retained. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if device allocation or the device-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() and capacity() equal other.size(), and the active elements reside in an allocation independent of other. other; it performs the same deep copy as the lvalue copy constructor. cudaMemcpy without an explicit stream and performs no separate device synchronization.
|
noexcept |
Releases owned device storage without propagating CUDA failures.
The destructor passes the stored pointer to the non-throwing CUDA cleanup helper, clears the metadata, and ignores the return status from cudaFree.
| void DeviceVector< T >::assignData | ( | T * | data | ) |
Replaces the stored device pointer without changing metadata.
This legacy escape hatch performs no copy, allocation, deallocation, or validation. Subsequent clear() or destruction passes the replacement pointer to cudaFree, so a non-null pointer is effectively transferred to this object.
| [in] | data | Nullable CUDA allocation pointer to store. When non-null, it must be releasable with cudaFree and identify storage for at least capacity() elements. |
data() equals data; size() and capacity() are unchanged. nullptr while capacity() is nonzero, passing borrowed storage, or passing a buffer shorter than capacity() breaks the ownership and storage invariants required by later operations. | std::size_t DeviceVector< T >::capacity | ( | void | ) | const |
Returns the number of allocated element slots.
| void DeviceVector< T >::clear | ( | void | ) |
Releases all device storage and resets the vector.
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if cudaFree fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
empty() is true, size() and capacity() are zero, and data() is nullptr. | T * DeviceVector< T >::data | ( | void | ) |
Returns a mutable pointer to the owned device allocation.
nullptr when no allocation is owned. The pointee storage remains valid until this object is destroyed, cleared, assigned replacement storage, or reallocated. swap() preserves the pointer value but transfers ownership to the other vector. size() or capacity(). | const T * DeviceVector< T >::data | ( | void | ) | const |
Returns a read-only pointer to the owned device allocation.
nullptr when no allocation is owned. The pointee storage remains valid until this object is destroyed, cleared, assigned replacement storage, or reallocated. swap() preserves the pointer value but transfers ownership to the other vector. | bool DeviceVector< T >::empty | ( | void | ) | const |
Returns whether the active element range is empty.
true when size() is zero; otherwise false. An empty vector may still own storage when capacity() is nonzero. | DeviceVector< T > & DeviceVector< T >::operator= | ( | const DeviceVector< T > && | other | ) |
Replaces the vector with a deep copy of a const device-vector rvalue.
The destination capacity is changed to other.capacity(), then other.size() active elements are copied device-to-device.
| [in] | other | Borrowed, read-only source vector. No pointer into it is retained after the call. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if allocation, device-to-device prefix preservation, deallocation, or the final device-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() equals other.size(), capacity() equals other.capacity(), and the active elements are an independent copy. [other.size(), other.capacity()) are not copied. other. cudaMemcpy without an explicit stream and perform no separate device synchronization. | DeviceVector< T > & DeviceVector< T >::operator= | ( | const DeviceVector< T > & | other | ) |
Replaces the vector with a deep copy of another device vector.
The destination capacity is changed to other.capacity(), then other.size() active elements are copied device-to-device.
| [in] | other | Borrowed, read-only source vector. No pointer into it is retained after the call. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if allocation, device-to-device prefix preservation, deallocation, or the final device-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() equals other.size(), capacity() equals other.capacity(), and the active elements are an independent copy. [other.size(), other.capacity()) are not copied. cudaMemcpy without an explicit stream and perform no separate device synchronization. | DeviceVector< T > & DeviceVector< T >::operator= | ( | const std::vector< T > && | other | ) |
Replaces the vector with a copy of a const host rvalue.
The destination capacity is changed to other.capacity(), then other.size() active elements are copied from host to device.
| [in] | other | Borrowed, read-only host vector. No reference to it is retained after the call. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if allocation, device-to-device prefix preservation, deallocation, or the final host-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() equals other.size(), capacity() equals other.capacity(), and the active device elements copy other. other. cudaMemcpy without an explicit stream and perform no separate device synchronization. | DeviceVector< T > & DeviceVector< T >::operator= | ( | const std::vector< T > & | other | ) |
Replaces the vector with a copy of a host vector.
The destination capacity is changed to other.capacity(), then other.size() active elements are copied from host to device.
| [in] | other | Borrowed, read-only host vector. No reference to it is retained after the call. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if allocation, device-to-device prefix preservation, deallocation, or the final host-to-device copy fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
size() equals other.size(), capacity() equals other.capacity(), and the active device elements copy other. [size(), capacity()) have unspecified contents. cudaMemcpy without an explicit stream and perform no separate device synchronization. | void DeviceVector< T >::push_back | ( | const T & | value | ) |
Appends one value to the active device sequence.
When the allocation is full, capacity grows to capacity() + capacity() / 2 + 1 and the existing active prefix is copied to the replacement allocation. A single CUDA thread then writes the new value on the default stream.
| [in] | value | Host value copied into the new device element. No reference to value is retained after kernel launch. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if allocation, device-to-device prefix copying, deallocation, or cudaGetLastError() returns a non-success status immediately after launch. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
std::size_t. size() is increased by one and the write has been enqueued. size() is not increased. Any completed growth remains in effect, and storage outside the active prefix may have been modified by an enqueued kernel. | void DeviceVector< T >::resize | ( | const std::size_t | count | ) |
Changes the number of active element slots.
Growing beyond capacity reallocates exactly count slots and preserves the old active prefix. Resizing within capacity changes only the logical size. Newly exposed elements are not initialized, and shrinking does not release storage.
| [in] | count | Requested active element count. |
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if required allocation, device-to-device prefix copying, or deallocation fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
count * sizeof(T) is representable as std::size_t when allocation or reallocation is required. size() equals count. Capacity is unchanged when it was already sufficient; otherwise it equals count. resize(0) preserves an existing nonzero-capacity allocation. cudaMemcpy without an explicit stream and perform no separate device synchronization. | void DeviceVector< T >::shrink_to_fit | ( | void | ) |
Reduces device capacity to the current size.
The active prefix is preserved. The call is a no-op when size() already equals capacity(); otherwise it replaces or releases the allocation.
| ApoCharmmError | With ApoCharmmErrorCode::Cuda if allocation, device-to-device prefix copying, or deallocation fails. |
| std::bad_alloc | If reporting a CUDA failure cannot allocate diagnostic storage. |
| std::length_error | If a CUDA failure diagnostic exceeds an implementation-defined string limit. |
capacity() equals size(). If the size is zero, data() is nullptr. cudaMemcpy without an explicit stream and perform no separate device synchronization. | std::size_t DeviceVector< T >::size | ( | void | ) | const |
Returns the number of active element slots.
|
noexcept |
Exchanges allocation ownership and metadata with another vector.
| [in,out] | other | Vector whose size, capacity, and device pointer are exchanged with this object. No element data is copied. |