34#include "include/splitvector/splitvec.h"
35#include "include/hashinator/hashinator.h"
42#define THREADS_PER_MP 2048
44#ifndef REGISTERS_PER_MP
45#define REGISTERS_PER_MP 65536
73#define MAXCPUTHREADS 512
83int gpu_reportMemory(
const size_t local_cap=0,
const size_t ghost_cap=0,
const size_t local_size=0,
const size_t ghost_size=0);
100 cuint largestVmesh=0,
101 cuint unionSetSize=0);
116 split::SplitVector<int>
i,
j;
140 kBegin.optimizeGPU(stream);
141 i.optimizeGPU(stream);
142 j.optimizeGPU(stream);
156 kBegin.optimizeGPU(stream);
157 i.optimizeGPU(stream);
158 j.optimizeGPU(stream);
182 return colCapacity * (2*
sizeof(uint)+5*
sizeof(int))
184 + 4 *
sizeof(split::SplitVector<uint>)
185 + 5 *
sizeof(split::SplitVector<int>);
197 kBegin.resize(nCols,
true);
198 i.resize(nCols,
true);
199 j.resize(nCols,
true);
211 kBegin.device_resize(nCols);
212 i.device_resize(nCols);
213 j.device_resize(nCols);
275 #define NO_POINTER_DEVICE 0
276 #define DEVICE_POINTER 1
277 #define HOST_POINTER 2
280 #define SINGLE_ARG(...) __VA_ARGS__
288 #define DEFINITIONS_HERE
289 size_t dev_allMaps,
dev_allPencilsContainers,
dev_allPencilsMeshes,
dev_blockDataOrdered,
dev_bulkVX,
dev_bulkVY,
dev_bulkVZ,
dev_bValues,
dev_cellIdxArray,
dev_cellIdxKeys,
dev_cellIdxStartCutoff,
dev_columnOffsetData,
dev_Ddt,
dev_densityPostAdjust,
dev_densityPreAdjust,
dev_dfdt_mu,
dev_dxdydz,
dev_fcount,
dev_fmu,
dev_intersections,
dev_lists_delete,
dev_lists_to_replace,
dev_lists_with_replace_new,
dev_lists_with_replace_old,
dev_mass,
dev_massLoss,
dev_max_dt,
dev_minValues,
dev_moments1,
dev_moments2,
dev_nAfter,
dev_nBefore,
dev_nBlocksToChange,
dev_nColumns,
dev_nColumnSets,
dev_nu0Values,
dev_nWithContent,
dev_overflownElements,
dev_pencilBlockData,
dev_pencilBlocksCount,
dev_potentialDdtValues,
dev_probeCubeData,
dev_remappedCellIdxArray,
dev_resizeSuccess,
dev_smallCellIdxArray,
dev_sparsity,
dev_VBC,
dev_VBCs,
dev_vbwcl_neigh,
dev_vbwcl_vec,
dev_velocityIdxArray,
dev_vmeshes,
gpu_block_indices_to_id,
gpu_block_indices_to_probe,
gpu_cell_indices_to_id,
gpuInitBlocks,
gpuInitBuffer,
host_allMaps,
host_allPencilsContainers,
host_allPencilsMeshes,
host_blockDataOrdered,
host_bulkVX,
host_bulkVY,
host_bulkVZ,
host_bValues,
host_cellIdxStartCutoff,
host_Ddt,
host_dxdydz,
host_intersections,
host_lists_delete,
host_lists_to_replace,
host_lists_with_replace_new,
host_lists_with_replace_old,
host_mass,
host_massLoss,
host_max_dt,
host_minValues,
host_moments1,
host_moments2,
host_nAfter,
host_nBefore,
host_nBlocksToChange,
host_nColumns,
host_nColumnSets,
host_nu0Values,
host_nWithContent,
host_overflownElements,
host_remappedCellIdxArray,
host_resizeSuccess,
host_returnLID,
host_returnReal,
host_returnRealf,
host_smallCellIdxArray,
host_sparsity,
host_VBC,
host_VBCs,
host_vbwcl_neigh,
host_vbwcl_vec,
host_vmeshes,
member,
my_test_pointer,
returnLID,
returnReal,
returnRealf;
290 #define DEFINITIONS_END
291 #undef DEFINITIONS_HERE
292 #undef DEFINITIONS_END
296 #define CREATE_UNIQUE_POINTER(object, member) object.createPointer(object.member)
299 if (pointerIndex != 0){
322 #define CREATE_SUBPOINTERS(object, member, amount) object.createSubPointers(object.member, amount)
325 if (firstPointerIndex != 0 || numberOfPointers == 0){
340 for (
size_t i = 0;
i < numberOfPointers;
i++) {
360 std::cerr <<
"Concurrent sessions not supported. Please end previous session before starting a new one.\n";
386 std::cerr <<
"No session is currently on. Please start a session before ending it.\n";
403 #define ALLOCATE_GPU(object, member, bytes) object.allocate(object.member, bytes)
405 bool allocate(
const size_t& pointerIndex,
size_t bytes) {
406 if (pointerIndex == 0) {
407 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.allocate'.\n";
429 #define ALLOCATE_WITH_BUFFER(object, member, bytes, buffer) object.allocateWithBuffer(object.member, bytes, buffer)
432 if (pointerIndex == 0) {
433 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.allocateWithBuffer'.\n";
455 #define HOST_ALLOCATE_GPU(object, member, bytes) object.hostAllocate(object.member, bytes)
458 if (pointerIndex == 0) {
459 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.hostAllocate'.\n";
481 #define HOST_ALLOCATE_WITH_BUFFER(object, member, bytes, buffer) object.hostAllocateWithBuffer(object.member, bytes, buffer)
484 if (pointerIndex == 0) {
485 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.hostAllocateWithBuffer'.\n";
507 #define SUBPOINTER_ALLOCATE(object, member, index, bytes) object.subPointerAllocate(object.member, index, bytes)
511 size_t pointerIndex = firstPointerIndex +
index;
514 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.subPointerAllocate': firstPointerIndex = " << firstPointerIndex <<
", pointerIndex = " << pointerIndex <<
", maxPointerIndex = " <<
maxPointerIndex <<
"\n";
518 return allocate(pointerIndex, bytes);
524 size_t pointerIndex = firstPointerIndex +
index;
527 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.subPointerAllocateWithBuffer'.\n";
534 #define SUBPOINTER_HOST_ALLOCATE(object, member, index, bytes) object.subPointerHostAllocate(object.member, index, bytes)
538 size_t pointerIndex = firstPointerIndex +
index;
541 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.subPointerHostAllocate'.\n";
551 uintptr_t fullAddress =
reinterpret_cast<uintptr_t
>(base) + offset;
552 size_t alignment = std::max(
alignof(T),
size_t(256));
553 size_t alignedAddress = (fullAddress + alignment - 1) & ~(alignment - 1);
554 return alignedAddress -
reinterpret_cast<uintptr_t
>(base);
557 #define SESSION_ALLOCATE(object, type, member, bytes) object.sessionAllocate<type>(object.member, bytes)
562 std::cerr <<
"No session is currently on. Please start a session before allocating to it.\n";
600 #define SESSION_HOST_ALLOCATE(object, type, member, bytes) object.sessionHostAllocate<type>(object.member, bytes)
605 std::cerr <<
"No session is currently on. Please start a session before allocating to it.\n";
643 #define ALLOCATE_GPU_ASYNC(object, member, bytes, stream) object.allocateAsync(object.member, bytes, stream)
646 if (pointerIndex == 0) {
647 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.allocateAsync'.\n";
669 #define SUBPOINTER_ALLOCATE_ASYNC(object, member, index, bytes, stream) object.subPointerAllocateAsync(object.member, index, bytes, stream)
673 size_t pointerIndex = firstPointerIndex +
index;
676 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.subPointerAllocateAsync': firstPointerIndex = " << firstPointerIndex <<
", pointerIndex = " << pointerIndex <<
", maxPointerIndex = " <<
maxPointerIndex <<
"\n";
685 if (pointerIndex == 0) {
686 std::cerr <<
"Error: Pointer not found in 'gpuMemoryManager.freePointer'.\n";
706 size_t getSize(
const size_t& pointerIndex)
const {
707 if (pointerIndex != 0){
717 for (
size_t pointerIndex = 0; pointerIndex <
gpuMemoryPointers.size(); pointerIndex++) {
725 for (
size_t pointerIndex = 0; pointerIndex <
sessionPointers.size(); pointerIndex++) {
740 for (
size_t pointerIndex = 0; pointerIndex <
gpuMemoryPointers.size(); pointerIndex++) {
748 for (
size_t pointerIndex = 0; pointerIndex <
sessionPointers.size(); pointerIndex++) {
761 for (
size_t pointerIndex = 0; pointerIndex <
sessionPointers.size(); pointerIndex++) {
779 for (
size_t pointerIndex = 0; pointerIndex <
gpuMemoryPointers.size(); pointerIndex++) {
809 #define GET_POINTER(object, type, member) object.getPointer<type>(object.member)
811 template <
typename T>
813 if (pointerIndex == 0){
814 throw std::runtime_error(
"Unknown pointer name at gpuMemoryManager.getPointer!\n");
819 #define GET_SUBPOINTER(object, type, member, index) object.getSubPointer<type>(object.member, index)
821 template <
typename T>
824 size_t pointerIndex = firstPointerIndex +
index;
827 throw std::runtime_error(
"Unknown pointer name at gpuMemoryManager.getSubPointer!\n");
833 #define GET_SESSION_POINTER(object, type, member) object.getSessionPointer<type>(object.member)
835 template <
typename T>
838 throw std::runtime_error(
"Unknown pointer name at gpuMemoryManager.getSessionPointer!\n");
850 return reinterpret_cast<T*
>(sessionPointer + offset);
853 #define GET_SESSION_HOST_POINTER(object, type, member) object.getSessionHostPointer<type>(object.member)
855 template <
typename T>
858 throw std::runtime_error(
"Unknown pointer name at gpuMemoryManager.getSessionHostPointer!\n");
870 return reinterpret_cast<T*
>(sessionPointer + offset);
879 #define SET_SUBPOINTER(object, type, member, index, subPointerIndex) object.setSubPointer<type>(object.member, index, subPointerIndex)
881 template <
typename T>
883 if (basePointerIndex == 0 || subPointerIndex == 0) {
884 throw std::runtime_error(
"Error: Pointer not found in 'gpuMemoryManager.setSubPointer'.");
889 basePointer[
index] = subPointer;
cudaStream_t gpuStreamList[]
GPUMemoryManager gpuMemoryManager
std::vector< uint > gpu_vlasov_allocatedSize
ColumnOffsets * host_columnOffsetData
gpuStream_t gpuPriorityStreamList[MAXCPUTHREADS]
size_t gpu_probeFlattenedSize
uint gpu_largest_columnCount
int gpuMultiProcessorCount
unsigned int nextPowerOfTwo(unsigned int n)
static const uint VLASOV_BUFFER_MINBLOCKS
void gpu_batch_allocate(uint nCells=0, uint maxNeighbours=0)
static const int GPU_PROBEFLAT_N
void gpu_vlasov_deallocate()
gpuStream_t gpu_getPriorityStream()
uint gpu_getAllocationCount()
uint gpu_acc_foundColumnsCount
static const uint INIT_MAP_SIZE(16 - WID)
static const double BLOCK_ALLOCATION_PADDING
uint gpu_vlasov_getSmallestAllocation()
void gpu_vlasov_allocate(uint maxBlockCount)
void gpu_acc_allocate(uint maxBlockCount)
static const uint VLASOV_BUFFER_MINCOLUMNS
static const uint INIT_VMESH_SIZE(32768/WID3)
void gpu_trans_allocate(cuint nAllCells=0, cuint largestVmesh=0, cuint unionSetSize=0)
static const int TRANSLATION_BUFFER_ALLOCATION_FACTOR
void gpu_acc_allocate_perthread(uint cpuThreadID, uint firstAllocationCount, uint columnSetAllocationCount=0)
uint gpu_acc_allocatedColumns
static const double BLOCK_ALLOCATION_FACTOR
int gpu_reportMemory(const size_t local_cap=0, const size_t ghost_cap=0, const size_t local_size=0, const size_t ghost_size=0)
void gpu_trans_deallocate()
void gpu_acc_deallocate()
#define NO_POINTER_DEVICE
gpuStream_t gpu_getStream()
void gpu_calculateProbeAllocation(uint maxBlockCount)
void gpu_vlasov_allocate_perthread(uint cpuThreadID, uint maxBlockCount)
split::SplitVector< int > j
split::SplitVector< int > maxBlockK
__device__ size_t dev_capacityColSets() const
__host__ size_t capacityColSets() const
__device__ void device_setSizes(size_t nCols=0, size_t nColSets=0)
__device__ size_t dev_sizeColSets() const
__host__ size_t capacityCols() const
void prefetchDevice(gpuStream_t stream)
void setSizes(size_t nCols=0, size_t nColSets=0)
split::SplitVector< uint > columnNumBlocks
split::SplitVector< uint > setNumColumns
size_t capacityInBytes() const
ColumnOffsets(uint nColumns=1, uint nColumnSets=1)
split::SplitVector< int > kBegin
split::SplitVector< uint > setColumnOffsets
void setCapacities(size_t nCols=0, size_t nColSets=0)
__device__ size_t dev_capacityCols() const
split::SplitVector< int > i
__host__ size_t sizeCols() const
split::SplitVector< uint > columnBlockOffsets
split::SplitVector< int > minBlockK
__device__ size_t dev_sizeCols() const
size_t dev_allPencilsContainers
size_t host_intersections
bool subPointerAllocate(const size_t &firstPointerIndex, const uint index, size_t bytes)
size_t totalGpuAllocation()
bool allocate(const size_t &pointerIndex, size_t bytes)
size_t dev_nBlocksToChange
size_t host_smallCellIdxArray
size_t dev_blockDataOrdered
bool sessionAllocate(size_t &pointerIndex, size_t bytes)
bool createSubPointers(size_t &firstPointerIndex, const size_t numberOfPointers)
size_t dev_lists_to_replace
std::vector< void * > gpuMemoryPointers
size_t dev_allPencilsMeshes
bool hostAllocateWithBuffer(const size_t &pointerIndex, size_t bytes, size_t buffer)
size_t totalCpuAllocation()
std::vector< size_t > sessionAllocationSizes
std::vector< size_t > allocationSizes
void freeSessionPointers()
T * getPointer(const size_t &pointerIndex) const
bool subPointerAllocateWithBuffer(const size_t &firstPointerIndex, const uint index, size_t bytes, size_t buffer)
T * getSessionHostPointer(const size_t &pointerIndex) const
size_t dev_columnOffsetData
size_t host_overflownElements
bool allocateAsync(const size_t &pointerIndex, size_t bytes, gpuStream_t stream)
size_t gpu_block_indices_to_probe
size_t dev_smallCellIdxArray
size_t dev_overflownElements
bool createPointer(size_t &pointerIndex)
size_t alignOffset(void *base, size_t offset)
size_t host_lists_with_replace_old
size_t gpu_block_indices_to_id
T * getSessionPointer(const size_t &pointerIndex) const
size_t dev_pencilBlocksCount
bool sessionHostAllocate(size_t &pointerIndex, size_t bytes)
std::vector< size_t > sessionPointerOffset
size_t getSize(const size_t &pointerIndex) const
T * getSubPointer(const size_t &firstPointerIndex, const uint index) const
bool subPointerHostAllocate(const size_t &firstPointerIndex, const uint index, size_t bytes)
void setSubPointer(const size_t basePointerIndex, const size_t index, const size_t subPointerIndex)
size_t host_lists_with_replace_new
size_t host_remappedCellIdxArray
std::vector< uint > pointerDevice
size_t dev_lists_with_replace_new
size_t maxSessionPointerIndex
size_t dev_remappedCellIdxArray
size_t host_previousSessionSize
size_t dev_previousSessionSize
size_t dev_densityPostAdjust
size_t host_allPencilsMeshes
size_t host_resizeSuccess
size_t host_cellIdxStartCutoff
size_t host_nBlocksToChange
bool subPointerAllocateAsync(const size_t &firstPointerIndex, const uint index, size_t bytes, gpuStream_t stream)
bool freePointer(size_t &pointerIndex)
size_t dev_sessionPointer
bool allocateWithBuffer(const size_t &pointerIndex, size_t bytes, size_t buffer)
size_t host_blockDataOrdered
bool startSession(size_t dev_bytes, size_t host_bytes)
size_t gpu_cell_indices_to_id
bool hostAllocate(const size_t &pointerIndex, size_t bytes)
size_t dev_sessionAllocationSize
size_t dev_densityPreAdjust
size_t dev_lists_with_replace_old
size_t dev_velocityIdxArray
void updatePointer(const size_t &pointerIndex, void *newPtr)
size_t host_sessionPointer
size_t dev_cellIdxStartCutoff
std::vector< void * > sessionPointers
size_t dev_pencilBlockData
size_t host_allPencilsContainers
size_t host_lists_to_replace
size_t dev_potentialDdtValues
size_t host_sessionAllocationSize
std::vector< uint > sessionPointerDevice
An interface to a type with floating point values.
static ARCH_HOSTDEV VecSimple< T > max(VecSimple< T > const &l, VecSimple< T > const &r)