Peano
Loading...
Searching...
No Matches
GPUMemoryManager.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#ifndef GPU_MEMORY_MANAGER_H
4#define GPU_MEMORY_MANAGER_H
5
7
9#include "tarch/logging/Log.h"
10
11#include <map>
12#include <list>
13#include <vector>
14
15namespace tarch {
16 namespace accelerator {
17 class GPUMemoryManager;
18 #if defined(GPUOffloadingSYCL)
19 typedef ::sycl::queue& DeviceType;
20 #else
21 typedef int DeviceType;
22 #endif
23 }
24}
25
38 private:
40
45 static int _allocatedMemory;
46 static constexpr int _maxMemory = -1;
47
49
53 typedef std::map< int, std::vector<void*> > FreePages;
54
59 typedef std::map< void*, int > UsedPages;
60
65
69 std::map<int, DeviceMemory> _deviceMemory;
70
71 GPUMemoryManager() = default;
72
73 public:
74 GPUMemoryManager( const GPUMemoryManager& copy ) = delete;
75
80
82
88 template <class T>
89 T* allocate( int size, DeviceType device ) {
90 return reinterpret_cast<T*>( allocateRawData(size * static_cast<int>(sizeof(T)), device ) );
91 }
92
121 void* allocateRawData( int size, DeviceType device );
122
128 void free(void* devicePointer, DeviceType device);
129
139 void clear();
140};
141
142#endif
Singleton that manages persistent memory on the GPUs.
static int _allocatedMemory
_allocatedMemory and _maxMemory are used to track remaining space on the device.
std::map< int, DeviceMemory > _deviceMemory
Map from device number onto memory.
static GPUMemoryManager & getInstance()
void free(void *devicePointer, DeviceType device)
Free does not actually free data, but instead hands the memory block back to the singleton,...
GPUMemoryManager(const GPUMemoryManager &copy)=delete
std::map< void *, int > UsedPages
Counterpart of FreePages, i.e.
static tarch::logging::Log _log
void * allocateRawData(int size, DeviceType device)
Return a pointer to new device data of size size bytes on device.
std::map< int, std::vector< void * > > FreePages
Map of pages (memory blocks) per size.
tarch::multicore::BooleanSemaphore _semaphore
virtual ~GPUMemoryManager()
Invoke clear().
void clear()
Idempotent function.
T * allocate(int size, DeviceType device)
Log Device.
Definition Log.h:517
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19