16 #ifndef LIFOSTORAGECUDA_HPP
17 #define LIFOSTORAGECUDA_HPP
22 #include <condition_variable>
23 #include <camp/camp.hpp>
29 #include "common/FixedSizeDeque.hpp"
30 #include "common/GEOS_RAJA_Interface.hpp"
32 #include "common/FixedSizeDequeWithMutexes.hpp"
33 #include "common/MultiMutexesLock.hpp"
34 #include "common/LifoStorageCommon.hpp"
42 template<
typename T,
typename INDEX_TYPE >
59 LifoStorageCuda(
std::string name,
size_t elemCnt,
int numberOfBuffersToStoreOnDevice,
int numberOfBuffersToStoreOnHost,
int maxNumberOfBuffers ):
60 LifoStorageCommon< T, INDEX_TYPE >( name, elemCnt, numberOfBuffersToStoreOnHost, maxNumberOfBuffers ),
61 m_deviceDeque( numberOfBuffersToStoreOnDevice, elemCnt, LvArray::MemorySpace::cuda ),
62 m_pushToDeviceEvents( maxNumberOfBuffers ),
63 m_popFromDeviceEvents( maxNumberOfBuffers )
77 "Cannot save on a Lifo without host storage (please set lifoSize, lifoOnDevice and lifoOnHost in xml file)" );
79 m_pushToDeviceEvents[id] = m_deviceDeque.emplaceFront( array );
83 LIFO_MARK_SCOPE( geos::lifoStorage::pushAddTasks );
117 LIFO_MARK_SCOPE( geos::LifoStorageCuda::popAddTasks );
126 m_popFromDeviceEvents[id] = m_deviceDeque.popFront( array );
137 m_popFromDeviceEvents[bufferCount].wait();
150 GEOS_ERROR_IF( percent > 100,
"Error, percentage of memory should be smaller than 100, check lifoOnDevice (should be greater than -100)" );
152 GEOS_ERROR_IF( cudaSuccess != cudaMemGetInfo( &free, &total ),
"Error getting CUDA device available memory" );
153 double freeGB = ( ( double ) free ) / ( 1024.0 * 1024.0 * 1024.0 );
154 LIFO_LOG_RANK(
" LIFO : available memory on device " << freeGB <<
" GB" );
155 return std::min( (
int )( 0.01 * percent * free / bufferSize ), maxNumberOfBuffers );
165 void deviceToHost(
int id )
169 baseLifo::m_hostDeque.getStream().wait_for(
const_cast< camp::resources::Event *
>( &m_pushToDeviceEvents[
id] ) );
190 void hostToDevice(
int id,
int id_pop )
209 FixedSizeDequeWithMutexes< T, INDEX_TYPE > m_deviceDeque;
211 std::vector< camp::resources::Event > m_pushToDeviceEvents;
213 std::vector< camp::resources::Event > m_popFromDeviceEvents;
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
int m_bufferCount
counter of buffer stored in LIFO
int m_bufferToDiskCount
counter of buffer pushed to disk
FixedSizeDequeWithMutexes< T, INDEX_TYPE > m_hostDeque
Queue of data stored on host memory.
std::deque< std::packaged_task< void() > > m_task_queue[2]
queue of task to be executed by m_worker.
std::mutex m_task_queue_mutex[2]
mutex to protect access to m_task_queue.
std::condition_variable m_task_queue_not_empty_cond[2]
condition used to tell m_worker queue has been filled or processed is stopped.
int m_bufferToHostCount
counter of buffer pushed to host
int m_maxNumberOfBuffers
number of buffers to be inserted into the LIFO
void pushWait() override final
void popAsync(arrayView1d< T > array) override final
LifoStorageCuda(std::string name, size_t elemCnt, int numberOfBuffersToStoreOnDevice, int numberOfBuffersToStoreOnHost, int maxNumberOfBuffers)
void popWait() override final
static int computeNumberOfBufferOnDevice(int percent, size_t bufferSize, int maxNumberOfBuffers)
void pushAsync(arrayView1d< T > array) override final
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
std::string string
String type.