Project
Loading...
Searching...
No Matches
GPUExternalAllocator.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
12#ifndef ALICEO2_ALICE3GLOBALRECONSTRUCTION_GPUEXTERNALALLOCATOR_H
13#define ALICEO2_ALICE3GLOBALRECONSTRUCTION_GPUEXTERNALALLOCATOR_H
14
16
17#include <cstddef>
18#include <cstdint>
19#include <mutex>
20#include <type_traits>
21#include <unordered_map>
22#include <vector>
23
24namespace o2::trk
25{
26
28{
29 public:
32
33 void* allocate(size_t size) override;
34 void deallocate(char* ptr, size_t size) override;
35 void pushTagOnStack(uint64_t tag) override;
36 void popTagOffStack(uint64_t tag) override;
37
38 void releaseAll();
39
40 private:
41 enum class AllocationSpace { Host,
42 Device };
43
44 struct AllocationMeta {
45 AllocationSpace space;
46 uint64_t tag;
47 bool stacked;
48 };
49
50 using MemoryType = std::underlying_type_t<o2::gpu::GPUMemoryResource::MemoryType>;
51
52 void* allocateHost(size_t size);
53 void* allocateDevice(size_t size);
54 void freeAllocation(void* ptr, AllocationSpace space);
55 void removeFromTagLocked(uint64_t tag, void* ptr);
56
57 std::mutex mMutex;
58 std::vector<uint64_t> mTagStack;
59 std::unordered_map<uint64_t, std::vector<void*>> mTaggedAllocations;
60 std::unordered_map<void*, AllocationMeta> mAllocations;
61};
62
63} // namespace o2::trk
64
65#endif
TBranch * ptr
void * allocate(size_t size) override
void pushTagOnStack(uint64_t tag) override
void deallocate(char *ptr, size_t size) override
void popTagOffStack(uint64_t tag) override
GLsizeiptr size
Definition glcorearb.h:659