Commit 254379d0 authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

[cuda] More CUDA capabilities for DeviceVector

parent a056a29f
......@@ -8,10 +8,15 @@
#include <rtac_base/cuda/utils.h>
#include <rtac_base/types/SharedVector.h>
#ifndef RTAC_CUDACC
#include <rtac_base/types/common.h>
#endif
#ifdef RTAC_CUDACC
#include <thrust/device_ptr.h>
#endif
namespace rtac { namespace cuda {
......@@ -72,6 +77,21 @@ class DeviceVector
iterator end();
const_iterator begin() const;
const_iterator end() const;
#ifdef RTAC_CUDACC // the following methods are only usable in CUDA code.
value_type& operator[](size_t idx);
const value_type& operator[](size_t idx) const;
value_type& front();
const value_type& front() const;
value_type& back();
const value_type& back() const;
thrust::device_ptr<T> begin_thrust();
thrust::device_ptr<T> end_thrust();
thrust::device_ptr<const T> begin_thrust() const;
thrust::device_ptr<const T> end_thrust() const;
#endif
};
template <typename T>
using SharedDeviceVector = rtac::types::SharedVectorBase<DeviceVector<T>>;
......@@ -253,6 +273,68 @@ const_iterator DeviceVector<T>::end() const
return data_ + size_;
}
#ifdef RTAC_CUDACC
template <typename T> typename DeviceVector<T>::
value_type& DeviceVector<T>::operator[](size_t idx)
{
return data_[idx];
}
template <typename T> const typename DeviceVector<T>::
value_type& DeviceVector<T>::operator[](size_t idx) const
{
return data_[idx];
}
template <typename T> typename DeviceVector<T>::
value_type& DeviceVector<T>::front()
{
return data_[0];
}
template <typename T> const typename DeviceVector<T>::
value_type& DeviceVector<T>::front() const
{
return data_[0];
}
template <typename T> typename DeviceVector<T>::
value_type& DeviceVector<T>::back()
{
return data_[this->size() - 1];
}
template <typename T> const typename DeviceVector<T>::
value_type& DeviceVector<T>::back() const
{
return data_[this->size() - 1];
}
template <typename T>
thrust::device_ptr<T> DeviceVector<T>::begin_thrust()
{
return thrust::device_pointer_cast(data_);
}
template <typename T>
thrust::device_ptr<T> DeviceVector<T>::end_thrust()
{
return thrust::device_pointer_cast(data_ + size_);
}
template <typename T>
thrust::device_ptr<const T> DeviceVector<T>::begin_thrust() const
{
return thrust::device_pointer_cast(data_);
}
template <typename T>
thrust::device_ptr<const T> DeviceVector<T>::end_thrust() const
{
return thrust::device_pointer_cast(data_ + size_);
}
#endif //RTAC_CUDACC
}; //namespace cuda
}; //namespace rtac
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment