Project
Loading...
Searching...
No Matches
GPUMemoryResource.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef GPUMEMORYRESOURCE_H
16#define GPUMEMORYRESOURCE_H
17
18#include "GPUCommonDef.h"
19#include "GPUProcessor.h"
20
21namespace o2::gpu
22{
23
25 enum Type : int32_t {
26 NONE = 0,
27 REUSE_1TO1 = 1
28 };
37 using ID = uint32_t;
38
39 GPUMemoryReuse(Type t, Group g, uint16_t i) : type(t), id(((uint32_t)g << 16) | ((uint32_t)i & 0xFFFF)) {}
40 GPUMemoryReuse(bool condition, Type t, Group g, uint16_t i) : GPUMemoryReuse()
41 {
42 if (condition) {
43 *this = GPUMemoryReuse{t, g, i};
44 }
45 }
46 constexpr GPUMemoryReuse() = default;
47
49 ID id = 0;
50};
51
53{
54 friend class GPUReconstruction;
56
57 public:
59 MEMORY_HOST = 1, // Memory allocated on host (irrespective of other flags)
60 MEMORY_GPU = 2, // Memory allocated on GPU (irrespective of other flags)
61 MEMORY_INPUT_FLAG = 4, // Flag to signal this memory is copied to GPU with TransferMemoryResourcesToGPU, and alike
62 MEMORY_INPUT = 7, // Input data for GPU has the MEMORY_INPUT_FLAG flat and is allocated on host and GPU
63 MEMORY_OUTPUT_FLAG = 8, // Flag to signal this memory is copied to Host with TransferMemoryResourcesToHost, and alike
64 MEMORY_OUTPUT = 11, // Output data for GPU has the MEMORY_OUTPUT_FLAG flat and is allocated on host and GPU
65 MEMORY_INOUT = 15, // Combination if MEMORY_INPUT and MEMORY_OUTPUT
66 MEMORY_SCRATCH = 16, // Scratch memory, is allocated only on GPU by default if running on GPU, only on host otherwise, if MEMORY_HOST and MEMORY_GPU flags not set.
67 MEMORY_SCRATCH_HOST = 17, // Scratch memory only on host
68 MEMORY_EXTERNAL = 32, // Special flag to signal that memory on host shall not be allocated, but will be provided externally and manually
69 MEMORY_PERMANENT = 64, // Permanent memory, registered once with AllocateRegisteredPermanentMemory, not per time frame. Only for small sizes!
70 MEMORY_CUSTOM = 128, // Memory is not allocated automatically with AllocateRegisteredMemory(GPUProcessor), but must be allocated manually via AllocateRegisteredMemory(memoryId)
71 MEMORY_CUSTOM_TRANSFER = 256, // Memory is not transfered automatically with TransferMemoryResourcesTo, but must be transferred manually with TransferMemoryTo...(memoryId)
72 MEMORY_STACK = 512 // Use memory from non-persistent stack at the end of the global memory region. Not persistent for full TF. Use PushNonPersistentMemory and PopNonPersistentMemory to release memory from the stack
73 };
74 enum AllocationType { ALLOCATION_AUTO = 0, // --> GLOBAL if GPU is used, INDIVIDUAL otherwise
75 ALLOCATION_INDIVIDUAL = 1, // Individual memory allocations with malloc (host only)
76 ALLOCATION_GLOBAL = 2 }; // Allocate memory blocks from large preallocated memory range with internal allocator (host and GPU)
77
78 GPUMemoryResource(GPUProcessor* proc, void* (GPUProcessor::*setPtr)(void*), MemoryType type, const char* name = "") : mProcessor(proc), mPtr(nullptr), mPtrDevice(nullptr), mSetPointers(setPtr), mName(name), mSize(0), mOverrideSize(0), mReuse(-1), mType(type)
79 {
80 }
82
83 void* SetPointers(void* ptr)
84 {
85 return (mProcessor->*mSetPointers)(ptr);
86 }
87 void* SetDevicePointers(void* ptr) { return (mProcessor->mLinkedProcessor->*mSetPointers)(ptr); }
88 void* Ptr() { return mPtr; }
89 void* PtrDevice() { return mPtrDevice; }
90 size_t Size() const { return mSize; }
91 const char* Name() const { return mName; }
92 MemoryType Type() const { return mType; }
93
94 private:
95 GPUProcessor* mProcessor;
96 void* mPtr;
97 void* mPtrDevice;
98 void* (GPUProcessor::*mSetPointers)(void*);
99 const char* mName;
100 size_t mSize;
101 size_t mOverrideSize;
102 int32_t mReuse;
103 MemoryType mType;
104};
105} // namespace o2::gpu
106
107#endif
int32_t i
TBranch * ptr
void * SetDevicePointers(void *ptr)
GPUMemoryResource(const GPUMemoryResource &)=default
const char * Name() const
GPUMemoryResource(GPUProcessor *proc, void *(GPUProcessor::*setPtr)(void *), MemoryType type, const char *name="")
GPUProcessor * mLinkedProcessor
GLuint const GLchar * name
Definition glcorearb.h:781
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean g
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650
GPUMemoryReuse(Type t, Group g, uint16_t i)
GPUMemoryReuse(bool condition, Type t, Group g, uint16_t i)
constexpr GPUMemoryReuse()=default