-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathGPUOutputControl.h
More file actions
86 lines (75 loc) · 3.2 KB
/
GPUOutputControl.h
File metadata and controls
86 lines (75 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GPUOutputControl.h
/// \author David Rohr
#ifndef GPUOUTPUTCONTROL_H
#define GPUOUTPUTCONTROL_H
#include "GPUCommonDef.h"
#include <cstddef>
#include <functional>
#include <new>
namespace o2::gpu
{
// This defines an output region. ptrBase points to a memory buffer, which should have a proper alignment.
// Since DPL does not respect the alignment of data types, we do not impose anything specic but just use void*, but it should be >= 64 bytes ideally.
// The size defines the maximum possible buffer size when GPUReconstruction is called, and returns the number of filled bytes when it returns.
// If the buffer size is exceeded, size is set to 1
// ptrCurrent must equal ptr if set (or nullptr), and can be incremented by GPUReconstruction step by step if multiple buffers are used.
// If ptr == nullptr, there is no region defined and GPUReconstruction will write its output to an internal buffer.
// If allocator is set, it is called as a callback to provide a ptr to the memory.
struct GPUOutputControl {
GPUOutputControl() = default;
void set(void* p, size_t s)
{
reset();
ptrBase = ptrCurrent = p;
size = s;
}
void set(const std::function<void*(size_t)>& a)
{
reset();
allocator = a;
}
void reset()
{
new (this) GPUOutputControl;
}
bool useExternal() { return size || allocator; }
bool useInternal() { return !useExternal(); }
void checkCurrent()
{
if (ptrBase && ptrCurrent == nullptr) {
ptrCurrent = ptrBase;
}
}
void* ptrBase = nullptr; // Base ptr to memory pool, occupied size is ptrCurrent - ptr
void* ptrCurrent = nullptr; // Pointer to free Output Space
size_t size = 0; // Max Size of Output Data if Pointer to output space is given
std::function<void*(size_t)> allocator = nullptr; // Allocator callback
};
struct GPUTrackingOutputs {
GPUOutputControl compressedClusters;
GPUOutputControl clustersNative;
GPUOutputControl tpcTracks;
GPUOutputControl clusterLabels;
GPUOutputControl sharedClusterMap;
GPUOutputControl tpcOccupancyMap;
GPUOutputControl tpcTracksO2;
GPUOutputControl tpcTracksO2ClusRefs;
GPUOutputControl tpcTracksO2Labels;
GPUOutputControl tpcTriggerWords;
static constexpr size_t count() { return sizeof(GPUTrackingOutputs) / sizeof(GPUOutputControl); }
GPUOutputControl* asArray() { return (GPUOutputControl*)this; }
size_t getIndex(const GPUOutputControl& v) { return &v - (const GPUOutputControl*)this; }
static int32_t getIndex(GPUOutputControl GPUTrackingOutputs::* v) { return &(((GPUTrackingOutputs*)(0x10000))->*v) - (GPUOutputControl*)(0x10000); }
};
} // namespace o2::gpu
#endif