|
Celeritas 0.7+d9d378c
|
Manage generic array-like data ownership and transfer from host to device. More...
#include <Collection.hh>
Public Member Functions | |
| template<Ownership W2, MemSpace M2> | |
| Collection & | operator= (Collection< T, W2, M2, I > const &other) |
| template<Ownership W2, MemSpace M2> | |
| Collection & | operator= (Collection< T, W2, M2, I > &other) |
| reference | operator[] (ItemIdT i) |
| Access a single element. | |
| const_reference | operator[] (ItemIdT i) const |
| Access a single element (const). | |
| SpanT | operator[] (ItemRangeT ps) |
| Access a subset of the data as a Span. | |
| SpanConstT | operator[] (ItemRangeT ps) const |
| Access a subset of the data as a Span (const). | |
| template<Ownership W2, MemSpace M2> | |
| Collection (Collection< T, W2, M2, I > const &other) | |
| Construct or assign from another collection. | |
| template<Ownership W2, MemSpace M2> | |
| Collection (Collection< T, W2, M2, I > &other) | |
| Construct or assign from another collection. | |
| template<Ownership W2, MemSpace M2> | |
| Collection< T, W, M, I > & | operator= (Collection< T, W2, M2, I > const &other) |
| Construct or assign from another collection. | |
| template<Ownership W2, MemSpace M2> | |
| Collection< T, W, M, I > & | operator= (Collection< T, W2, M2, I > &other) |
| Construct or assign from another collection. | |
| Collection & | operator= (Collection const &other)=default |
| Collection & | operator= (Collection &&other)=default |
| SpanT | operator[] (AllItemsT) |
| SpanConstT | operator[] (AllItemsT) const |
| size_type | size () const |
| bool | empty () const |
| pointer | data () |
| const_pointer | data () const |
Static Public Attributes | |
| static constexpr Ownership | ownership = W |
| static constexpr MemSpace | memspace = M |
Friends | |
| template<class T2 , MemSpace M2, class Id2 > | |
| class | CollectionBuilder |
| template<class T2 , class Id2 > | |
| class | DedupeCollectionBuilder |
Type aliases | |
| using | value_type = typename TraitsT::type |
| using | SpanT = typename TraitsT::SpanT |
| using | SpanConstT = typename TraitsT::SpanConstT |
| using | pointer = detail::ContainerObserverPtr< SpanT, M > |
| using | const_pointer = detail::ContainerObserverPtr< SpanConstT, M > |
| using | reference = typename SpanT::reference |
| using | const_reference = typename SpanConstT::reference |
| using | size_type = MakeSize_t< I > |
| using | ItemIdT = I |
| using | ItemRangeT = Range< ItemIdT > |
| using | AllItemsT = detail::AllItems_t< T, M > |
| using | reference_type = reference |
| using | const_reference_type = const_reference |
| Collection ()=default | |
| Collection (Collection const &)=default | |
| Collection (Collection &&)=default | |
Manage generic array-like data ownership and transfer from host to device.
Data are constructed incrementally on the host, then copied (along with their associated ItemRange) to device. A Collection can act as a std::vector<T>, DeviceVector<T>, Span<T>, or Span<const T>. The Spans can point to host or device memory, but the MemSpace template argument protects against accidental accesses from the wrong memory space.
Each Collection object is usually accessed with an ItemRange, which references a contiguous set of elements in the Collection. For example, setup code on the host would extend the Collection with a series of vectors, the addition of which returns a ItemRange that returns the equivalent data on host or device. This methodology allows complex nested data structures to be built up quickly at setup time without knowing the size requirements beforehand.
Host-device functions and classes should use Collection with a reference or const_reference Ownership, and the MemSpace::native type, which expects device memory when compiled inside a CUDA file and host memory when used inside a C++ source or test. This design choice prevents a single CUDA file from compiling separate host-compatible and device-compatible compute kernels. (In the case of Celeritas this situation won't arise, because we always want to build host code in C++ files for development ease and to allow testing when CUDA is disabled.)
A MemSpace::Mapped collection will be accessible on both host and device. Unified addressing must be supported by the current device, or an exception will be thrown when initializing the collection. Memory pages will reside on in "pinned" memory on host, and each access from device code to a changed page will require a slow memory transfer. Allocating pinned memory is slow and reduces the memory available to the system: so only allocate the smallest amount needed with the longest possible lifetime. Frequently accessing data from device code will result in low performance. Use case for mapped memory are:
Accessing a const_reference collection in device memory will return a wrapper container that accesses the low-level data through the celeritas::ldg wrapper function, which can accelerate random access on GPU by telling the compiler the memory will not be changed during the lifetime of the kernel. Therefore it is important to only use const Collections for shared, immutable-after-creation "params" data.
Accessing a reference collection returns mutable pointers, even when given the collection as a const reference.
Since the behavior of this class does not depend on the item ID (only the types do), the implementation of each function directly forwards to a less-templated function to reduce object size.
Default constructors
| using celeritas::Collection< T, W, M, I >::const_pointer = detail::ContainerObserverPtr<SpanConstT, M> |
Default constructors
Default constructors
| using celeritas::Collection< T, W, M, I >::const_reference_type = const_reference |
Default constructors
Default constructors
Default constructors
| using celeritas::Collection< T, W, M, I >::size_type = MakeSize_t<I> |
Default constructors
Default constructors
|
default |
Default constructors
Default constructors
|
default |
Default constructors
|
inlineexplicit |
Construct or assign from another collection.
These are generally used to create "references" to "values" (same memory space) but can also be used to copy from device to host. Allowable transformations and memory moves are statically checked.
|
inlineexplicit |
Construct or assign from another collection.
These are generally used to create "references" to "values" (same memory space) but can also be used to copy from device to host. Allowable transformations and memory moves are statically checked.
|
inline |
Direct accessors to underlying data
Direct accessors to underlying data
|
default |
Default assignment
|
default |
Default assignment
| Collection< T, W, M, I > & celeritas::Collection< T, W, M, I >::operator= | ( | Collection< T, W2, M2, I > & | other | ) |
Construct or assign from another collection.
These are generally used to create "references" to "values" (same memory space) but can also be used to copy from device to host. Allowable transformations and memory moves are statically checked.
| Collection< T, W, M, I > & celeritas::Collection< T, W, M, I >::operator= | ( | Collection< T, W2, M2, I > const & | other | ) |
Construct or assign from another collection.
These are generally used to create "references" to "values" (same memory space) but can also be used to copy from device to host. Allowable transformations and memory moves are statically checked.
|
inline |
Access all data as a span (memspace-safe)
|
inline |
Access all data as a span (memspace-safe)
Direct accessors to underlying data