2 #include <muda/tools/version.h> 3 #include <thrust/device_allocator.h> 5 #include <thrust/device_vector.h> 6 #include <thrust/host_vector.h> 9 #include <muda/muda_def.h> 11 #include <muda/viewer/dense.h> 17 template <
typename T,
typename Alloc>
18 using vector_base = thrust::detail::vector_base<T, Alloc>;
22 class DeviceVector :
public thrust::device_vector<T, thrust::device_allocator<T>>
25 using Base = thrust::device_vector<T, thrust::device_allocator<T>>;
27 using Base::operator=;
29 auto view() MUDA_NOEXCEPT {
return BufferView<T>{raw_ptr(), Base::size()}; }
31 auto view() const MUDA_NOEXCEPT
33 return CBufferView<T>{raw_ptr(), Base::size()};
36 operator BufferView<T>()
const MUDA_NOEXCEPT {
return view(); }
37 operator CBufferView<T>()
const MUDA_NOEXCEPT {
return view(); }
39 DeviceVector& operator=(CBufferView<T> v)
41 this->resize(v.size());
46 void copy_to(std::vector<T>& v)
const 48 v.resize(this->size());
49 view().copy_to(v.data());
52 auto viewer() MUDA_NOEXCEPT
54 return Dense1D<T>(raw_ptr(),
static_cast<int>(this->size()));
57 auto cviewer() const MUDA_NOEXCEPT
59 return CDense1D<T>(raw_ptr(),
static_cast<int>(this->size()));
63 T* raw_ptr() {
return thrust::raw_pointer_cast(Base::data()); }
64 const T* raw_ptr()
const {
return thrust::raw_pointer_cast(Base::data()); }
68 class HostVector :
public thrust::host_vector<T, std::allocator<T>>
71 using thrust::host_vector<T, std::allocator<T>>::host_vector;
72 using thrust::host_vector<T, std::allocator<T>>::operator=;
A view interface for any array-like liner memory, which can be constructed from DeviceBuffer/DeviceVe...