Celeritas  0.5.0-56+6b053cd
Public Member Functions | List of all members
celeritas::DeviceVector< T > Class Template Reference

Host vector for managing uninitialized device-storage data. More...

#include <DeviceVector.hh>

Public Types

Type aliases
using value_type = T
 
using SpanT = Span< T >
 
using SpanConstT = Span< T const >
 

Public Member Functions

 DeviceVector (StreamId stream)
 Construct with a stream.
 
 DeviceVector (size_type count)
 Construct with a number of allocated elements.
 
 DeviceVector (size_type count, StreamId stream)
 Construct with a number of allocated elements and a stream.
 
void swap (DeviceVector &other) noexcept
 Get the device data pointer.
 
void assign (T const *first, T const *last)
 Allocate and copy from host pointers. More...
 
size_type size () const
 Get the number of elements.
 
bool empty () const
 Whether any elements are stored.
 
void copy_to_device (SpanConstT host_data)
 Copy data to device.
 
void copy_to_host (SpanT host_data) const
 Copy data to host.
 
SpanT device_ref ()
 
SpanConstT device_ref () const
 
T * data ()
 Get a device data pointer.
 
T const * data () const
 Get a device data pointer.
 

Detailed Description

template<class T>
class celeritas::DeviceVector< T >

Host vector for managing uninitialized device-storage data.

This is a class used only in host memory (not passed to kernels) to manage device allocation and host/device copies. It does not perform initialization on the data: the host code must define and copy over suitable data.

For more complex data usage (dynamic size increases, std vector-like access, object initialization), use thrust::device_vector inside a .cu file.

When a StreamId is passed as the last constructor argument, all memory operations are asynchronous and ordered within that stream.

DeviceVector<double> myvec(100);
myvec.copy_to_device(make_span(hostvec));
myvec.copy_to_host(make_span(hostvec));
CELER_CONSTEXPR_FUNCTION Span< T, N > make_span(Array< T, N > &x)
Get a mutable fixed-size view to an array.
Definition: Span.hh:200

Member Function Documentation

◆ assign()

template<class T >
void celeritas::DeviceVector< T >::assign ( T const *  first,
T const *  last 
)

Allocate and copy from host pointers.

Not exception safe: if the copy fails, the original contents are lost.


The documentation for this class was generated from the following file: