]>
Commit | Line | Data |
---|---|---|
1 | // ************************************************************************** | |
2 | // * This file is property of and copyright by the ALICE HLT Project * | |
3 | // * All rights reserved. * | |
4 | // * * | |
5 | // * Primary Authors: * | |
6 | // * Copyright 2009 Matthias Kretz <kretz@kde.org> * | |
7 | // * * | |
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 | // ************************************************************************** | |
16 | ||
17 | #ifndef ALIHLTTPCCASLICEDATA_H | |
18 | #define ALIHLTTPCCASLICEDATA_H | |
19 | ||
20 | #include "AliHLTTPCCADef.h" | |
21 | #include "AliHLTTPCCARow.h" | |
22 | #include "AliHLTTPCCAMath.h" | |
23 | #include "AliHLTArray.h" | |
24 | #include "AliHLTTPCCAGPUConfig.h" | |
25 | ||
26 | typedef int int_v; | |
27 | typedef unsigned int uint_v; | |
28 | typedef short short_v; | |
29 | typedef unsigned short ushort_v; | |
30 | typedef float float_v; | |
31 | ||
32 | class AliHLTTPCCAClusterData; | |
33 | template<typename T, int Dim> class AliHLTArray; | |
34 | class AliHLTTPCCAHit; | |
35 | class AliHLTTPCCAParam; | |
36 | ||
37 | /** | |
38 | * Data abstraction class for the Slice Tracker. | |
39 | * | |
40 | * Different architectures implement this for the most efficient loads and stores. All access to the | |
41 | * data happens through inline functions so that access to the data has no extra costs. | |
42 | */ | |
43 | class AliHLTTPCCASliceData | |
44 | { | |
45 | public: | |
46 | AliHLTTPCCASliceData() | |
47 | : | |
48 | fIsGpuSliceData(0), fGPUSharedDataReq(0), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 ) | |
49 | ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 ) | |
50 | , fFirstHitInBin( 0 ), fHitWeights( 0 ) | |
51 | { | |
52 | } | |
53 | ||
54 | #ifndef HLTCA_GPUCODE | |
55 | ~AliHLTTPCCASliceData(); | |
56 | #endif //!HLTCA_GPUCODE | |
57 | ||
58 | void InitializeRows( const AliHLTTPCCAParam ¶meters ); | |
59 | ||
60 | /** | |
61 | * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster | |
62 | * data. | |
63 | */ | |
64 | ||
65 | void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory); | |
66 | size_t SetPointers(const AliHLTTPCCAClusterData *data, bool allocate = false); | |
67 | void InitFromClusterData( const AliHLTTPCCAClusterData &data ); | |
68 | ||
69 | /** | |
70 | * Clear the slice data (e.g. for an empty slice) | |
71 | */ | |
72 | void Clear(); | |
73 | ||
74 | /** | |
75 | * Return the number of hits in this slice. | |
76 | */ | |
77 | GPUhd() int NumberOfHits() const { return fNumberOfHits; } | |
78 | GPUhd() int NumberOfHitsPlusAlign() const { return fNumberOfHitsPlusAlign; } | |
79 | ||
80 | /** | |
81 | * Access to the hit links. | |
82 | * | |
83 | * The links values give the hit index in the row above/below. Or -1 if there is no link. | |
84 | */ | |
85 | short_v HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const; | |
86 | short_v HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const; | |
87 | ||
88 | GPUhd() const ushort2 *HitData( const AliHLTTPCCARow &row ) const; | |
89 | GPUhd() const ushort2 *HitData() const { return(fHitData); } | |
90 | GPUd() const short_v *HitLinkUpData ( const AliHLTTPCCARow &row ) const; | |
91 | GPUd() const short_v *HitLinkDownData( const AliHLTTPCCARow &row ) const; | |
92 | GPUd() const ushort_v *FirstHitInBin( const AliHLTTPCCARow &row ) const; | |
93 | ||
94 | void SetHitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex, | |
95 | const short_v &value ); | |
96 | void SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex, | |
97 | const short_v &value ); | |
98 | ||
99 | /** | |
100 | * Reset all links to -1. | |
101 | */ | |
102 | void ClearLinks(); | |
103 | ||
104 | /** | |
105 | * Return the y and z coordinate(s) of the given hit(s). | |
106 | */ | |
107 | // TODO return float_v | |
108 | ushort_v HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const; | |
109 | ushort_v HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const; | |
110 | ushort2 HitData( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const; | |
111 | ||
112 | /** | |
113 | * For a given bin index, content tells how many hits there are in the preceding bins. This maps | |
114 | * directly to the hit index in the given row. | |
115 | * | |
116 | * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3. | |
117 | */ | |
118 | ushort_v FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const; | |
119 | ||
120 | /** | |
121 | * If the given weight is higher than what is currently stored replace with the new weight. | |
122 | */ | |
123 | void MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight ); | |
124 | ||
125 | /** | |
126 | * Return the maximal weight the given hit got from one tracklet | |
127 | */ | |
128 | int_v HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const; | |
129 | ||
130 | /** | |
131 | * Reset all hit weights to 0. | |
132 | */ | |
133 | void ClearHitWeights(); | |
134 | ||
135 | /** | |
136 | * Returns the index in the original AliHLTTPCCAClusterData object of the given hit | |
137 | */ | |
138 | int_v ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const; | |
139 | ||
140 | /** | |
141 | * Return the row object for the given row index. | |
142 | */ | |
143 | const AliHLTTPCCARow &Row( int rowIndex ) const; | |
144 | GPUhd() AliHLTTPCCARow* Rows() const {return fRows;} | |
145 | ||
146 | GPUh() char *Memory() const {return(fMemory); } | |
147 | GPUh() size_t MemorySize() const {return(fMemorySize); } | |
148 | GPUh() size_t GpuMemorySize() const {return(fGpuMemorySize); } | |
149 | GPUh() int* HitWeights() const {return(fHitWeights); } | |
150 | ||
151 | GPUhd() void SetGPUTextureBase(char* const val) {fGPUTextureBase = val;} | |
152 | GPUhd() char* GPUTextureBase() const { return(fGPUTextureBase); } | |
153 | GPUhd() char* GPUTextureBaseConst() const { return(fGPUTextureBase); } | |
154 | ||
155 | GPUh() int GPUSharedDataReq() const { return fGPUSharedDataReq; } | |
156 | ||
157 | void SetGpuSliceData() { fIsGpuSliceData = 1; } | |
158 | ||
159 | private: | |
160 | AliHLTTPCCASliceData( const AliHLTTPCCASliceData & ) | |
161 | : | |
162 | fIsGpuSliceData(0), fGPUSharedDataReq(0), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 ) | |
163 | ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 ) | |
164 | , fFirstHitInBin( 0 ), fHitWeights( 0 ) | |
165 | { | |
166 | } | |
167 | AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) { | |
168 | return *this; | |
169 | } | |
170 | ||
171 | void CreateGrid( AliHLTTPCCARow *row, const AliHLTTPCCAClusterData &data, int ClusterDataHitNumberOffset ); | |
172 | void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits ); | |
173 | ||
174 | int fIsGpuSliceData; //Slice Data for GPU Tracker? | |
175 | int fGPUSharedDataReq; //Size of shared memory required for GPU Reconstruction | |
176 | ||
177 | int fNumberOfHits; // the number of hits in this slice | |
178 | int fNumberOfHitsPlusAlign; | |
179 | ||
180 | int fMemorySize; // size of the allocated memory in bytes | |
181 | int fGpuMemorySize; // size of Memory needed to be transfered to GPU | |
182 | char *fMemory; // pointer to the allocated memory where all the following arrays reside in | |
183 | char *fGPUTextureBase; // pointer to start of GPU texture | |
184 | ||
185 | AliHLTTPCCARow *fRows; // The row objects needed for most accessor functions | |
186 | ||
187 | short *fLinkUpData; // hit index in the row above which is linked to the given (global) hit index | |
188 | short *fLinkDownData; // hit index in the row below which is linked to the given (global) hit index | |
189 | ||
190 | ushort2 *fHitData; // packed y,z coordinate of the given (global) hit index | |
191 | ||
192 | int *fClusterDataIndex; // see ClusterDataIndex() | |
193 | ||
194 | /* | |
195 | * The size of the array is row.Grid.N + row.Grid.Ny + 3. The row.Grid.Ny + 3 is an optimization | |
196 | * to remove the need for bounds checking. The last values are the same as the entry at [N - 1]. | |
197 | */ | |
198 | unsigned short *fFirstHitInBin; // see FirstHitInBin | |
199 | ||
200 | int *fHitWeights; // the weight of the longest tracklet crossed the cluster | |
201 | ||
202 | }; | |
203 | ||
204 | GPUd() inline short_v AliHLTTPCCASliceData::HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const | |
205 | { | |
206 | return fLinkUpData[row.fHitNumberOffset + hitIndex]; | |
207 | } | |
208 | ||
209 | GPUd() inline short_v AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const | |
210 | { | |
211 | return fLinkDownData[row.fHitNumberOffset + hitIndex]; | |
212 | } | |
213 | ||
214 | GPUd() inline const ushort_v *AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row ) const | |
215 | { | |
216 | return &fFirstHitInBin[row.fFirstHitInBinOffset]; | |
217 | } | |
218 | ||
219 | GPUd() inline const short_v *AliHLTTPCCASliceData::HitLinkUpData ( const AliHLTTPCCARow &row ) const | |
220 | { | |
221 | return &fLinkUpData[row.fHitNumberOffset]; | |
222 | } | |
223 | ||
224 | GPUd() inline const short_v *AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row ) const | |
225 | { | |
226 | return &fLinkDownData[row.fHitNumberOffset]; | |
227 | } | |
228 | ||
229 | GPUhd() inline const ushort2 *AliHLTTPCCASliceData::HitData( const AliHLTTPCCARow &row ) const | |
230 | { | |
231 | return &fHitData[row.fHitNumberOffset]; | |
232 | } | |
233 | ||
234 | GPUd() inline void AliHLTTPCCASliceData::SetHitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value ) | |
235 | { | |
236 | fLinkUpData[row.fHitNumberOffset + hitIndex] = value; | |
237 | } | |
238 | ||
239 | GPUd() inline void AliHLTTPCCASliceData::SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value ) | |
240 | { | |
241 | fLinkDownData[row.fHitNumberOffset + hitIndex] = value; | |
242 | } | |
243 | ||
244 | GPUd() inline ushort_v AliHLTTPCCASliceData::HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const | |
245 | { | |
246 | return fHitData[row.fHitNumberOffset + hitIndex].x; | |
247 | } | |
248 | ||
249 | GPUd() inline ushort_v AliHLTTPCCASliceData::HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const | |
250 | { | |
251 | return fHitData[row.fHitNumberOffset + hitIndex].y; | |
252 | } | |
253 | ||
254 | GPUd() inline ushort2 AliHLTTPCCASliceData::HitData( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const | |
255 | { | |
256 | return fHitData[row.fHitNumberOffset + hitIndex]; | |
257 | } | |
258 | ||
259 | GPUd() inline ushort_v AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const | |
260 | { | |
261 | return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes]; | |
262 | } | |
263 | ||
264 | GPUhd() inline int_v AliHLTTPCCASliceData::ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const | |
265 | { | |
266 | return fClusterDataIndex[row.fHitNumberOffset + hitIndex]; | |
267 | } | |
268 | ||
269 | GPUhd() inline const AliHLTTPCCARow &AliHLTTPCCASliceData::Row( int rowIndex ) const | |
270 | { | |
271 | return fRows[rowIndex]; | |
272 | } | |
273 | ||
274 | GPUd() inline void AliHLTTPCCASliceData::MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight ) | |
275 | { | |
276 | CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight ); | |
277 | } | |
278 | ||
279 | GPUd() inline int_v AliHLTTPCCASliceData::HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const | |
280 | { | |
281 | return fHitWeights[row.fHitNumberOffset + hitIndex]; | |
282 | } | |
283 | ||
284 | typedef AliHLTTPCCASliceData SliceData; | |
285 | ||
286 | #endif // ALIHLTTPCCASLICEDATA_H |