Skip to content
Snippets Groups Projects
Commit d46372d3 authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Fixing Cuda compilation

parent 8595ed09
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ void CudaMemory::destroy()
*
*/
void CudaMemory::allocate_host(size_t sz)
void CudaMemory::allocate_host(size_t sz) const
{
if (hm == NULL)
{
......@@ -74,7 +74,7 @@ void CudaMemory::allocate_host(size_t sz)
* \param ptr
* \return true if success
*/
bool CudaMemory::copyFromPointer(void * ptr)
bool CudaMemory::copyFromPointer(const void * ptr)
{
// check if we have a host buffer, if not allocate it
......@@ -87,7 +87,7 @@ bool CudaMemory::copyFromPointer(void * ptr)
// memory copy
memcpy(ptr,dvp,sz);
memcpy(dvp,ptr,sz);
return true;
}
......@@ -100,7 +100,7 @@ bool CudaMemory::copyFromPointer(void * ptr)
*
* \return true is success
*/
bool CudaMemory::copyDeviceToDevice(CudaMemory & m)
bool CudaMemory::copyDeviceToDevice(const CudaMemory & m)
{
//! The source buffer is too big to copy it
......@@ -123,10 +123,10 @@ bool CudaMemory::copyDeviceToDevice(CudaMemory & m)
* \param m a memory interface
*
*/
bool CudaMemory::copy(memory & m)
bool CudaMemory::copy(const memory & m)
{
//! Here we try to cast memory into OpenFPMwdeviceCudaMemory
CudaMemory * ofpm = dynamic_cast<CudaMemory *>(&m);
const CudaMemory * ofpm = dynamic_cast<const CudaMemory *>(&m);
//! if we fail we get the pointer and simply copy from the pointer
......@@ -152,11 +152,12 @@ bool CudaMemory::copy(memory & m)
*
*/
size_t CudaMemory::size()
size_t CudaMemory::size() const
{
return sz;
}
/*! \brief Resize the allocated memory
*
* Resize the allocated memory, if request is smaller than the allocated memory
......@@ -241,3 +242,28 @@ void * CudaMemory::getPointer()
return hm;
}
/*! \brief Return a readable pointer with your data
*
* Return a readable pointer with your data
*
*/
const void * CudaMemory::getPointer() const
{
//| allocate an host memory if not allocated
if (hm == NULL)
allocate_host(sz);
//! if the host buffer is synchronized with the device buffer return the host buffer
if (is_hm_sync)
return hm;
//! copy from device to host memory
CUDA_SAFE_CALL(cudaMemcpy(hm,dm,sz,cudaMemcpyDeviceToHost));
return hm;
}
......@@ -46,13 +46,19 @@ class CudaMemory : public memory
void * dm;
//! host memory
void * hm;
mutable void * hm;
//! Reference counter
size_t ref_cnt;
//! Allocate an host buffer
void allocate_host(size_t sz);
void allocate_host(size_t sz) const;
//! copy from GPU to GPU buffer directly
bool copyDeviceToDevice(const CudaMemory & m);
//! copy from Pointer to GPU
bool copyFromPointer(const void * ptr);
public:
......@@ -63,17 +69,14 @@ public:
//! copy from a General device
virtual bool copy(const memory & m);
//! the the size of the allocated memory
virtual size_t size();
virtual size_t size() const;
//! resize the momory allocated
virtual bool resize(size_t sz);
//! get a readable pointer with the data
void * getPointer();
//! copy from GPU to GPU buffer directly
bool copyDeviceToDevice(CudaMemory & m);
//! copy from Pointer to GPU
bool copyFromPointer(void * ptr);
//! get a readable pointer with the data
virtual const void * getPointer() const;
//! This function notify that the device memory is not sync with
//! the host memory, is called when a task is performed that write
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment