1 // **************************************************************************
2 // * This file is property of and copyright by the ALICE HLT Project *
3 // * All rights reserved. *
5 // * Primary Authors: *
6 // * Copyright 2009 Matthias Kretz <kretz@kde.org> *
8 // * Permission to use, copy, modify and distribute this software and its *
9 // * documentation strictly for non-commercial purposes is hereby granted *
10 // * without fee, provided that the above copyright notice appears in all *
11 // * copies and that both the copyright notice and this permission notice *
12 // * appear in the supporting documentation. The authors make no claims *
13 // * about the suitability of this software for any purpose. It is *
14 // * provided "as is" without express or implied warranty. *
15 // **************************************************************************
17 #ifndef ALIHLTTPCCASLICEDATA_H
18 #define ALIHLTTPCCASLICEDATA_H
20 #include "AliHLTTPCCADef.h"
21 #include "AliHLTTPCCARow.h"
22 #include "AliHLTTPCCAMath.h"
23 #include "AliHLTArray.h"
24 #include "AliHLTTPCCAGPUConfig.h"
27 typedef unsigned int uint_v;
28 typedef short short_v;
29 typedef unsigned short ushort_v;
30 typedef float float_v;
32 class AliHLTTPCCAClusterData;
33 #if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
34 template<typename T, int Dim> class AliHLTArray;
37 MEM_CLASS_PRE() class AliHLTTPCCAParam;
40 * Data abstraction class for the Slice Tracker.
42 * Different architectures implement this for the most efficient loads and stores. All access to the
43 * data happens through inline functions so that access to the data has no extra costs.
45 MEM_CLASS_PRE() class AliHLTTPCCASliceData
48 AliHLTTPCCASliceData()
50 fIsGpuSliceData(0), fGPUSharedDataReq(0), fFirstRow( 0 ), fLastRow( HLTCA_ROW_COUNT - 1), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 )
51 ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 )
52 , fFirstHitInBin( 0 ), fHitWeights( 0 )
57 ~AliHLTTPCCASliceData();
58 #endif //!HLTCA_GPUCODE
60 MEM_CLASS_PRE2() void InitializeRows( const MEM_LG2(AliHLTTPCCAParam) ¶meters );
63 * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
67 void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory);
68 size_t SetPointers(const AliHLTTPCCAClusterData *data, bool allocate = false);
69 void InitFromClusterData( const AliHLTTPCCAClusterData &data );
72 * Clear the slice data (e.g. for an empty slice)
77 * Return the number of hits in this slice.
79 GPUhd() int NumberOfHits() const { return fNumberOfHits; }
80 GPUhd() int NumberOfHitsPlusAlign() const { return fNumberOfHitsPlusAlign; }
83 * Access to the hit links.
85 * The links values give the hit index in the row above/below. Or -1 if there is no link.
87 MEM_TEMPLATE() GPUd() short_v HitLinkUpData ( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex ) const;
88 MEM_TEMPLATE() GPUd() short_v HitLinkDownData( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex ) const;
90 MEM_TEMPLATE() GPUhd() GPUglobalref() const ushort2 *HitData( const MEM_TYPE(AliHLTTPCCARow) &row ) const {return &fHitData[row.fHitNumberOffset];}
91 GPUhd() GPUglobalref() const ushort2* HitData() const { return(fHitData); }
92 MEM_TEMPLATE() GPUd() GPUglobalref() const short_v *HitLinkUpData ( const MEM_TYPE(AliHLTTPCCARow) &row ) const {return &fLinkUpData[row.fHitNumberOffset];}
93 MEM_TEMPLATE() GPUd() GPUglobalref() const short_v *HitLinkDownData( const MEM_TYPE(AliHLTTPCCARow) &row ) const {return &fLinkDownData[row.fHitNumberOffset];}
94 MEM_TEMPLATE() GPUd() GPUglobalref() const ushort_v *FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow) &row ) const {return &fFirstHitInBin[row.fFirstHitInBinOffset];}
96 MEM_TEMPLATE() GPUd() void SetHitLinkUpData ( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex,
97 const short_v &value );
98 MEM_TEMPLATE() GPUd() void SetHitLinkDownData( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex,
99 const short_v &value );
102 * Reset all links to -1.
107 * Return the y and z coordinate(s) of the given hit(s).
109 // TODO return float_v
110 MEM_TEMPLATE() GPUd() ushort_v HitDataY( const MEM_TYPE( AliHLTTPCCARow) &row, const uint_v &hitIndex ) const;
111 MEM_TEMPLATE() GPUd() ushort_v HitDataZ( const MEM_TYPE( AliHLTTPCCARow) &row, const uint_v &hitIndex ) const;
112 MEM_TEMPLATE() GPUd() ushort2 HitData( const MEM_TYPE( AliHLTTPCCARow) &row, const uint_v &hitIndex ) const;
115 * For a given bin index, content tells how many hits there are in the preceding bins. This maps
116 * directly to the hit index in the given row.
118 * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
120 MEM_TEMPLATE() GPUd() ushort_v FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow)&row, ushort_v binIndexes ) const;
123 * If the given weight is higher than what is currently stored replace with the new weight.
125 MEM_TEMPLATE() GPUd() void MaximizeHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight );
126 MEM_TEMPLATE() GPUd() void SetHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight );
129 * Return the maximal weight the given hit got from one tracklet
131 MEM_TEMPLATE() GPUd() int_v HitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const;
134 * Reset all hit weights to 0.
136 void ClearHitWeights();
139 * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
141 MEM_TEMPLATE() GPUhd() int_v ClusterDataIndex( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const;
144 * Return the row object for the given row index.
146 GPUhd() GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow)& Row( int rowIndex ) const {return fRows[rowIndex];}
147 GPUhd() GPUglobalref() MEM_GLOBAL(AliHLTTPCCARow)* Rows() const {return fRows;}
149 GPUhd() GPUglobalref() int* HitWeights() const {return(fHitWeights); }
151 GPUhd() void SetGPUTextureBase(char* const val) {fGPUTextureBase = val;}
152 GPUhd() char* GPUTextureBase() const { return(fGPUTextureBase); }
153 GPUhd() char* GPUTextureBaseConst() const { return(fGPUTextureBase); }
155 #if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
156 GPUh() char* Memory() const {return(fMemory); }
157 GPUh() size_t MemorySize() const {return(fMemorySize); }
158 GPUh() size_t GpuMemorySize() const {return(fGpuMemorySize); }
159 GPUh() int GPUSharedDataReq() const { return fGPUSharedDataReq; }
162 void SetGpuSliceData() { fIsGpuSliceData = 1; }
165 AliHLTTPCCASliceData( const AliHLTTPCCASliceData & )
167 fIsGpuSliceData(0), fGPUSharedDataReq(0), fFirstRow(0), fLastRow(HLTCA_ROW_COUNT - 1), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 )
168 ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 )
169 , fFirstHitInBin( 0 ), fHitWeights( 0 )
172 AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) {
176 #if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
177 void CreateGrid( AliHLTTPCCARow *row, const float2* data, int ClusterDataHitNumberOffset );
178 void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
181 int fIsGpuSliceData; //Slice Data for GPU Tracker?
182 int fGPUSharedDataReq; //Size of shared memory required for GPU Reconstruction
184 int fFirstRow; //First non-empty row
185 int fLastRow; //Last non-empty row
187 int fNumberOfHits; // the number of hits in this slice
188 int fNumberOfHitsPlusAlign;
190 int fMemorySize; // size of the allocated memory in bytes
191 int fGpuMemorySize; // size of Memory needed to be transfered to GPU
192 GPUglobalref() char *fMemory; // pointer to the allocated memory where all the following arrays reside in
193 GPUglobalref() char *fGPUTextureBase; // pointer to start of GPU texture
195 GPUglobalref() MEM_GLOBAL(AliHLTTPCCARow) *fRows; // The row objects needed for most accessor functions
197 GPUglobalref() short *fLinkUpData; // hit index in the row above which is linked to the given (global) hit index
198 GPUglobalref() short *fLinkDownData; // hit index in the row below which is linked to the given (global) hit index
200 GPUglobalref() ushort2 *fHitData; // packed y,z coordinate of the given (global) hit index
202 GPUglobalref() int *fClusterDataIndex; // see ClusterDataIndex()
205 * The size of the array is row.Grid.N + row.Grid.Ny + 3. The row.Grid.Ny + 3 is an optimization
206 * to remove the need for bounds checking. The last values are the same as the entry at [N - 1].
208 GPUglobalref() unsigned short *fFirstHitInBin; // see FirstHitInBin
210 GPUglobalref() int *fHitWeights; // the weight of the longest tracklet crossed the cluster
214 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline short_v MEM_LG(AliHLTTPCCASliceData)::HitLinkUpData ( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex ) const
216 return fLinkUpData[row.fHitNumberOffset + hitIndex];
219 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline short_v MEM_LG(AliHLTTPCCASliceData)::HitLinkDownData( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex ) const
221 return fLinkDownData[row.fHitNumberOffset + hitIndex];
224 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::SetHitLinkUpData ( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex, const short_v &value )
226 fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
229 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::SetHitLinkDownData( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex, const short_v &value )
231 fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
234 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::HitDataY( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
236 return fHitData[row.fHitNumberOffset + hitIndex].x;
239 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::HitDataZ( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
241 return fHitData[row.fHitNumberOffset + hitIndex].y;
244 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort2 MEM_LG(AliHLTTPCCASliceData)::HitData( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
246 return fHitData[row.fHitNumberOffset + hitIndex];
249 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow)&row, ushort_v binIndexes ) const
251 return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
254 MEM_CLASS_PRE() MEM_TEMPLATE() GPUhd() inline int_v MEM_LG(AliHLTTPCCASliceData)::ClusterDataIndex( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const
256 return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
259 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::MaximizeHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight )
261 CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
264 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::SetHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight )
266 fHitWeights[row.fHitNumberOffset + hitIndex] = weight;
269 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline int_v MEM_LG(AliHLTTPCCASliceData)::HitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const
271 return fHitWeights[row.fHitNumberOffset + hitIndex];
274 //typedef AliHLTTPCCASliceData SliceData;
276 #endif // ALIHLTTPCCASLICEDATA_H