@@ -23,57 +23,57 @@ namespace GPUCA_NAMESPACE
2323{
2424namespace gpu
2525{
26+
27+ // This defines an output region. ptrBase points to a memory buffer, which should have a proper alignment.
28+ // 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.
29+ // The size defines the maximum possible buffer size when GPUReconstruction is called, and returns the number of filled bytes when it returns.
30+ // If the buffer size is exceeded, size is set to 1
31+ // ptrCurrent must equal ptr if set (or nullptr), and can be incremented by GPUReconstruction step by step if multiple buffers are used.
32+ // If ptr == nullptr, there is no region defined and GPUReconstruction will write its output to an internal buffer.
33+ // If allocator is set, it is called as a callback to provide a ptr to the memory.
34+
2635struct GPUOutputControl {
27- enum OutputTypeStruct { AllocateInternal = 0 ,
28- UseExternalBuffer = 1 };
2936 GPUOutputControl () = default ;
30- void set (void * ptr , size_t size )
37+ void set (void * p , size_t s )
3138 {
32- new (this ) GPUOutputControl;
33- OutputType = GPUOutputControl::UseExternalBuffer;
34- OutputBase = OutputPtr = (char *)ptr;
35- OutputMaxSize = size;
39+ reset ();
40+ ptrBase = ptrCurrent = p;
41+ size = s;
3642 }
37- void set (const std::function<void *(size_t )>& allocator )
43+ void set (const std::function<void *(size_t )>& a )
3844 {
39- new (this ) GPUOutputControl;
40- OutputType = GPUOutputControl::UseExternalBuffer;
41- OutputAllocator = allocator;
45+ reset ();
46+ allocator = a;
4247 }
4348 void reset ()
4449 {
4550 new (this ) GPUOutputControl;
4651 }
52+ bool useExternal () { return size || allocator; }
53+ bool useInternal () { return !useExternal (); }
54+ void checkCurrent ()
55+ {
56+ if (ptrBase && ptrCurrent == nullptr ) {
57+ ptrCurrent = ptrBase;
58+ }
59+ }
4760
48- void * OutputBase = nullptr ; // Base ptr to memory pool, occupied size is OutputPtr - OutputBase
49- void * OutputPtr = nullptr ; // Pointer to Output Space
50- size_t OutputMaxSize = 0 ; // Max Size of Output Data if Pointer to output space is given
51- std::function<void *(size_t )> OutputAllocator = nullptr ; // Allocator callback
52- OutputTypeStruct OutputType = AllocateInternal; // How to perform the output
53- char EndOfSpace = 0 ; // end of space flag
54- };
55-
56- // This defines an output region. Ptr points to a memory buffer, which should have a proper alignment.
57- // 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.
58- // The size defines the maximum possible buffer size when GPUReconstruction is called, and returns the number of filled bytes when it returns.
59- // If ptr == nullptr, there is no region defined and GPUReconstruction will write its output to an internal buffer.
60- // If allocator is set, it is called as a callback to provide a ptr to the memory.
61- struct GPUInterfaceOutputRegion {
62- void * ptr = nullptr ;
63- size_t size = 0 ;
64- std::function<void *(size_t )> allocator = nullptr ;
61+ void * ptrBase = nullptr ; // Base ptr to memory pool, occupied size is ptrCurrent - ptr
62+ void * ptrCurrent = nullptr ; // Pointer to free Output Space
63+ size_t size = 0 ; // Max Size of Output Data if Pointer to output space is given
64+ std::function<void *(size_t )> allocator = nullptr ; // Allocator callback
6565};
6666
6767struct GPUTrackingOutputs {
68- GPUInterfaceOutputRegion compressedClusters;
69- GPUInterfaceOutputRegion clustersNative;
70- GPUInterfaceOutputRegion tpcTracks;
71- GPUInterfaceOutputRegion clusterLabels;
72- GPUInterfaceOutputRegion sharedClusterMap;
68+ GPUOutputControl compressedClusters;
69+ GPUOutputControl clustersNative;
70+ GPUOutputControl tpcTracks;
71+ GPUOutputControl clusterLabels;
72+ GPUOutputControl sharedClusterMap;
7373
7474 static size_t count () { return sizeof (GPUTrackingOutputs) / sizeof (compressedClusters); }
75- GPUInterfaceOutputRegion * asArray () { return (GPUInterfaceOutputRegion *)this ; }
76- size_t getIndex (const GPUInterfaceOutputRegion & v) { return &v - (const GPUInterfaceOutputRegion *)this ; }
75+ GPUOutputControl * asArray () { return (GPUOutputControl *)this ; }
76+ size_t getIndex (const GPUOutputControl & v) { return &v - (const GPUOutputControl *)this ; }
7777};
7878
7979} // namespace gpu
0 commit comments