Commit 4f64e0ca authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

[cuda/vectors] Added direct conversion from eigen vectors to cuda::Host/DeviceVector

parent 5235b681
......@@ -6,6 +6,7 @@
#include <cuda_runtime.h>
#include <rtac_base/types/common.h>
#include <rtac_base/types/SharedVector.h>
#include <rtac_base/cuda/utils.h>
......@@ -45,6 +46,7 @@ class DeviceVector
DeviceVector(const DeviceVector<T>& other);
DeviceVector(const HostVector<T>& other);
DeviceVector(const std::vector<T>& other);
DeviceVector(const types::Vector<T>& other);
~DeviceVector();
void copy_from_host(size_t size, const T* data);
......@@ -52,6 +54,7 @@ class DeviceVector
DeviceVector& operator=(const DeviceVector<T>& other);
DeviceVector& operator=(const HostVector<T>& other);
DeviceVector& operator=(const std::vector<T>& other);
DeviceVector& operator=(const types::Vector<T>& other);
void resize(size_t size);
size_t size() const;
......@@ -104,6 +107,13 @@ DeviceVector<T>::DeviceVector(const std::vector<T>& other) :
*this = other;
}
template <typename T>
DeviceVector<T>::DeviceVector(const types::Vector<T>& other) :
DeviceVector(other.size())
{
*this = other;
}
template <typename T>
DeviceVector<T>::~DeviceVector()
{
......@@ -153,6 +163,17 @@ DeviceVector<T>& DeviceVector<T>::operator=(const std::vector<T>& other)
return *this;
}
template <typename T>
DeviceVector<T>& DeviceVector<T>::operator=(const types::Vector<T>& other)
{
this->resize(other.size());
CUDA_CHECK( cudaMemcpy(reinterpret_cast<void*>(data_),
reinterpret_cast<const void*>(other.data()),
sizeof(T)*size_,
cudaMemcpyHostToDevice) );
return *this;
}
template <typename T>
void DeviceVector<T>::allocate(size_t size)
{
......
......@@ -6,6 +6,7 @@
#include <cuda_runtime.h>
#include <rtac_base/types/common.h>
#include <rtac_base/types/SharedVector.h>
#include <rtac_base/cuda/utils.h>
......@@ -45,11 +46,13 @@ class HostVector
HostVector(const HostVector<T>& other);
HostVector(const DeviceVector<T>& other);
HostVector(const std::vector<T>& other);
HostVector(const types::Vector<T>& other);
~HostVector();
HostVector& operator=(const HostVector<T>& other);
HostVector& operator=(const DeviceVector<T>& other);
HostVector& operator=(const std::vector<T>& other);
HostVector& operator=(const types::Vector<T>& other);
void resize(size_t size);
size_t size() const;
......@@ -110,6 +113,13 @@ HostVector<T>::HostVector(const std::vector<T>& other) :
*this = other;
}
template <typename T>
HostVector<T>::HostVector(const types::Vector<T>& other) :
HostVector(other.size())
{
*this = other;
}
template <typename T>
HostVector<T>::~HostVector()
{
......@@ -149,6 +159,17 @@ HostVector<T>& HostVector<T>::operator=(const std::vector<T>& other)
return *this;
}
template <typename T>
HostVector<T>& HostVector<T>::operator=(const types::Vector<T>& other)
{
this->resize(other.size());
CUDA_CHECK( cudaMemcpy(reinterpret_cast<void*>(data_),
reinterpret_cast<const void*>(other.data()),
sizeof(T)*size_,
cudaMemcpyHostToHost) );
return *this;
}
template <typename T>
void HostVector<T>::allocate(size_t size)
{
......
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