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 #if !(defined(HLTCA_GPUCODE) && defined(__OPENCL__) && !defined(HLTCA_HOSTCODE))
24 #include "AliHLTArray.h"
26 #include "AliHLTTPCCAGPUConfig.h"
29 typedef unsigned int uint_v;
30 typedef short short_v;
31 typedef unsigned short ushort_v;
32 typedef float float_v;
34 class AliHLTTPCCAClusterData;
35 #if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
36 template<typename T, int Dim> class AliHLTArray;
39 MEM_CLASS_PRE() class AliHLTTPCCAParam;
42 * Data abstraction class for the Slice Tracker.
44 * Different architectures implement this for the most efficient loads and stores. All access to the
45 * data happens through inline functions so that access to the data has no extra costs.
47 MEM_CLASS_PRE() class AliHLTTPCCASliceData
50 AliHLTTPCCASliceData()
52 fIsGpuSliceData(0), fGPUSharedDataReq(0), fFirstRow( 0 ), fLastRow( HLTCA_ROW_COUNT - 1), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 )
53 ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 )
54 , fFirstHitInBin( 0 ), fHitWeights( 0 )
59 ~AliHLTTPCCASliceData();
60 #endif //!HLTCA_GPUCODE
62 MEM_CLASS_PRE2() void InitializeRows( const MEM_LG2(AliHLTTPCCAParam) ¶meters );
65 * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
69 void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory);
70 size_t SetPointers(const AliHLTTPCCAClusterData *data, bool allocate = false);
71 void InitFromClusterData( const AliHLTTPCCAClusterData &data );
74 * Clear the slice data (e.g. for an empty slice)
79 * Return the number of hits in this slice.
81 GPUhd() int NumberOfHits() const { return fNumberOfHits; }
82 GPUhd() int NumberOfHitsPlusAlign() const { return fNumberOfHitsPlusAlign; }
85 * Access to the hit links.
87 * The links values give the hit index in the row above/below. Or -1 if there is no link.
89 MEM_TEMPLATE() GPUd() short_v HitLinkUpData ( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex ) const;
90 MEM_TEMPLATE() GPUd() short_v HitLinkDownData( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex ) const;
92 MEM_TEMPLATE() GPUhd() GPUglobalref() const ushort2 *HitData( const MEM_TYPE(AliHLTTPCCARow) &row ) const {return &fHitData[row.fHitNumberOffset];}
93 GPUhd() GPUglobalref() const ushort2* HitData() const { return(fHitData); }
94 MEM_TEMPLATE() GPUd() GPUglobalref() const short_v *HitLinkUpData ( const MEM_TYPE(AliHLTTPCCARow) &row ) const {return &fLinkUpData[row.fHitNumberOffset];}
95 MEM_TEMPLATE() GPUd() GPUglobalref() const short_v *HitLinkDownData( const MEM_TYPE(AliHLTTPCCARow) &row ) const {return &fLinkDownData[row.fHitNumberOffset];}
96 MEM_TEMPLATE() GPUd() GPUglobalref() const ushort_v *FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow) &row ) const {return &fFirstHitInBin[row.fFirstHitInBinOffset];}
98 MEM_TEMPLATE() GPUd() void SetHitLinkUpData ( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex,
99 const short_v &value );
100 MEM_TEMPLATE() GPUd() void SetHitLinkDownData( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex,
101 const short_v &value );
104 * Reset all links to -1.
109 * Return the y and z coordinate(s) of the given hit(s).
111 // TODO return float_v
112 MEM_TEMPLATE() GPUd() ushort_v HitDataY( const MEM_TYPE( AliHLTTPCCARow) &row, const uint_v &hitIndex ) const;
113 MEM_TEMPLATE() GPUd() ushort_v HitDataZ( const MEM_TYPE( AliHLTTPCCARow) &row, const uint_v &hitIndex ) const;
114 MEM_TEMPLATE() GPUd() ushort2 HitData( const MEM_TYPE( AliHLTTPCCARow) &row, const uint_v &hitIndex ) const;
117 * For a given bin index, content tells how many hits there are in the preceding bins. This maps
118 * directly to the hit index in the given row.
120 * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
122 MEM_TEMPLATE() GPUd() ushort_v FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow)&row, ushort_v binIndexes ) const;
125 * If the given weight is higher than what is currently stored replace with the new weight.
127 MEM_TEMPLATE() GPUd() void MaximizeHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight );
128 MEM_TEMPLATE() GPUd() void SetHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight );
131 * Return the maximal weight the given hit got from one tracklet
133 MEM_TEMPLATE() GPUd() int_v HitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const;
136 * Reset all hit weights to 0.
138 void ClearHitWeights();
141 * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
143 MEM_TEMPLATE() GPUhd() int_v ClusterDataIndex( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const;
146 * Return the row object for the given row index.
148 GPUhd() GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow)& Row( int rowIndex ) const {return fRows[rowIndex];}
149 GPUhd() GPUglobalref() MEM_GLOBAL(AliHLTTPCCARow)* Rows() const {return fRows;}
151 GPUhd() GPUglobalref() int* HitWeights() const {return(fHitWeights); }
153 GPUhd() void SetGPUTextureBase(char* const val) {fGPUTextureBase = val;}
154 GPUhd() char* GPUTextureBase() const { return(fGPUTextureBase); }
155 GPUhd() char* GPUTextureBaseConst() const { return(fGPUTextureBase); }
157 #if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
158 GPUh() char* Memory() const {return(fMemory); }
159 GPUh() size_t MemorySize() const {return(fMemorySize); }
160 GPUh() size_t GpuMemorySize() const {return(fGpuMemorySize); }
161 GPUh() int GPUSharedDataReq() const { return fGPUSharedDataReq; }
164 void SetGpuSliceData() { fIsGpuSliceData = 1; }
167 AliHLTTPCCASliceData( const AliHLTTPCCASliceData & )
169 fIsGpuSliceData(0), fGPUSharedDataReq(0), fFirstRow(0), fLastRow(HLTCA_ROW_COUNT - 1), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 )
170 ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 )
171 , fFirstHitInBin( 0 ), fHitWeights( 0 )
174 AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) {
178 #if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
179 void CreateGrid( AliHLTTPCCARow *row, const float2* data, int ClusterDataHitNumberOffset );
180 void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
183 int fIsGpuSliceData; //Slice Data for GPU Tracker?
184 int fGPUSharedDataReq; //Size of shared memory required for GPU Reconstruction
186 int fFirstRow; //First non-empty row
187 int fLastRow; //Last non-empty row
189 int fNumberOfHits; // the number of hits in this slice
190 int fNumberOfHitsPlusAlign;
192 int fMemorySize; // size of the allocated memory in bytes
193 int fGpuMemorySize; // size of Memory needed to be transfered to GPU
194 GPUglobalref() char *fMemory; // pointer to the allocated memory where all the following arrays reside in
195 GPUglobalref() char *fGPUTextureBase; // pointer to start of GPU texture
197 GPUglobalref() MEM_GLOBAL(AliHLTTPCCARow) *fRows; // The row objects needed for most accessor functions
199 GPUglobalref() short *fLinkUpData; // hit index in the row above which is linked to the given (global) hit index
200 GPUglobalref() short *fLinkDownData; // hit index in the row below which is linked to the given (global) hit index
202 GPUglobalref() ushort2 *fHitData; // packed y,z coordinate of the given (global) hit index
204 GPUglobalref() int *fClusterDataIndex; // see ClusterDataIndex()
207 * The size of the array is row.Grid.N + row.Grid.Ny + 3. The row.Grid.Ny + 3 is an optimization
208 * to remove the need for bounds checking. The last values are the same as the entry at [N - 1].
210 GPUglobalref() unsigned short *fFirstHitInBin; // see FirstHitInBin
212 GPUglobalref() int *fHitWeights; // the weight of the longest tracklet crossed the cluster
216 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline short_v MEM_LG(AliHLTTPCCASliceData)::HitLinkUpData ( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex ) const
218 return fLinkUpData[row.fHitNumberOffset + hitIndex];
221 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline short_v MEM_LG(AliHLTTPCCASliceData)::HitLinkDownData( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex ) const
223 return fLinkDownData[row.fHitNumberOffset + hitIndex];
226 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 )
228 fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
231 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 )
233 fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
236 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::HitDataY( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
238 return fHitData[row.fHitNumberOffset + hitIndex].x;
241 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::HitDataZ( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
243 return fHitData[row.fHitNumberOffset + hitIndex].y;
246 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort2 MEM_LG(AliHLTTPCCASliceData)::HitData( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
248 return fHitData[row.fHitNumberOffset + hitIndex];
251 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow)&row, ushort_v binIndexes ) const
253 return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
256 MEM_CLASS_PRE() MEM_TEMPLATE() GPUhd() inline int_v MEM_LG(AliHLTTPCCASliceData)::ClusterDataIndex( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const
258 return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
261 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::MaximizeHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight )
263 CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
266 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::SetHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight )
268 fHitWeights[row.fHitNumberOffset + hitIndex] = weight;
271 MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline int_v MEM_LG(AliHLTTPCCASliceData)::HitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const
273 return fHitWeights[row.fHitNumberOffset + hitIndex];
276 //typedef AliHLTTPCCASliceData SliceData;
278 #endif // ALIHLTTPCCASLICEDATA_H