]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCASliceData.h
Update master to aliroot
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCASliceData.h
CommitLineData
6de2bc40 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
4acc2401 19
7be9b0d7 20#include "AliHLTTPCCADef.h"
4acc2401 21#include "AliHLTTPCCARow.h"
22#include "AliHLTTPCCAMath.h"
d3821846 23#if !(defined(HLTCA_GPUCODE) && defined(__OPENCL__) && !defined(HLTCA_HOSTCODE))
7be9b0d7 24#include "AliHLTArray.h"
d3821846 25#endif
b22af1bf 26#include "AliHLTTPCCAGPUConfig.h"
4acc2401 27
28typedef int int_v;
29typedef unsigned int uint_v;
30typedef short short_v;
31typedef unsigned short ushort_v;
32typedef float float_v;
33
34class AliHLTTPCCAClusterData;
43422963 35#if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
4acc2401 36template<typename T, int Dim> class AliHLTArray;
43422963 37#endif
4acc2401 38class AliHLTTPCCAHit;
43422963 39MEM_CLASS_PRE() class AliHLTTPCCAParam;
4acc2401 40
41/**
42 * Data abstraction class for the Slice Tracker.
43 *
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.
46 */
43422963 47MEM_CLASS_PRE() class AliHLTTPCCASliceData
4acc2401 48{
49 public:
50 AliHLTTPCCASliceData()
e01a1f52 51 :
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 )
55 {
56 }
b22af1bf 57
58#ifndef HLTCA_GPUCODE
e01a1f52 59 ~AliHLTTPCCASliceData();
31649d4b 60#endif //!HLTCA_GPUCODE
4acc2401 61
43422963 62 MEM_CLASS_PRE2() void InitializeRows( const MEM_LG2(AliHLTTPCCAParam) &parameters );
4acc2401 63
64 /**
65 * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
66 * data.
67 */
7be9b0d7 68
e01a1f52 69 void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory);
70 size_t SetPointers(const AliHLTTPCCAClusterData *data, bool allocate = false);
4acc2401 71 void InitFromClusterData( const AliHLTTPCCAClusterData &data );
72
73 /**
74 * Clear the slice data (e.g. for an empty slice)
75 */
76 void Clear();
77
78 /**
79 * Return the number of hits in this slice.
80 */
7be9b0d7 81 GPUhd() int NumberOfHits() const { return fNumberOfHits; }
e01a1f52 82 GPUhd() int NumberOfHitsPlusAlign() const { return fNumberOfHitsPlusAlign; }
4acc2401 83
84 /**
85 * Access to the hit links.
86 *
87 * The links values give the hit index in the row above/below. Or -1 if there is no link.
88 */
43422963 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;
e01a1f52 91
43422963 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];}
b22af1bf 97
43422963 98 MEM_TEMPLATE() GPUd() void SetHitLinkUpData ( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex,
4acc2401 99 const short_v &value );
43422963 100 MEM_TEMPLATE() GPUd() void SetHitLinkDownData( const MEM_TYPE(AliHLTTPCCARow) &row, const short_v &hitIndex,
4acc2401 101 const short_v &value );
102
103 /**
104 * Reset all links to -1.
105 */
106 void ClearLinks();
107
108 /**
109 * Return the y and z coordinate(s) of the given hit(s).
110 */
111 // TODO return float_v
43422963 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;
4acc2401 115
116 /**
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.
119 *
120 * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
121 */
43422963 122 MEM_TEMPLATE() GPUd() ushort_v FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow)&row, ushort_v binIndexes ) const;
4acc2401 123
124 /**
125 * If the given weight is higher than what is currently stored replace with the new weight.
126 */
43422963 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 );
4acc2401 129
130 /**
131 * Return the maximal weight the given hit got from one tracklet
132 */
43422963 133 MEM_TEMPLATE() GPUd() int_v HitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const;
4acc2401 134
135 /**
136 * Reset all hit weights to 0.
137 */
138 void ClearHitWeights();
139
140 /**
141 * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
142 */
43422963 143 MEM_TEMPLATE() GPUhd() int_v ClusterDataIndex( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const;
4acc2401 144
145 /**
146 * Return the row object for the given row index.
147 */
43422963 148 GPUhd() GPUglobalref() const MEM_GLOBAL(AliHLTTPCCARow)& Row( int rowIndex ) const {return fRows[rowIndex];}
149 GPUhd() GPUglobalref() MEM_GLOBAL(AliHLTTPCCARow)* Rows() const {return fRows;}
4acc2401 150
43422963 151 GPUhd() GPUglobalref() int* HitWeights() const {return(fHitWeights); }
6de2bc40 152
e01a1f52 153 GPUhd() void SetGPUTextureBase(char* const val) {fGPUTextureBase = val;}
154 GPUhd() char* GPUTextureBase() const { return(fGPUTextureBase); }
155 GPUhd() char* GPUTextureBaseConst() const { return(fGPUTextureBase); }
b22af1bf 156
43422963 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); }
e01a1f52 161 GPUh() int GPUSharedDataReq() const { return fGPUSharedDataReq; }
43422963 162#endif
b22af1bf 163
e01a1f52 164 void SetGpuSliceData() { fIsGpuSliceData = 1; }
6de2bc40 165
b22af1bf 166 private:
167 AliHLTTPCCASliceData( const AliHLTTPCCASliceData & )
e01a1f52 168 :
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 )
172 {
173 }
b8139972 174 AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) {
6de2bc40 175 return *this;
176 }
b8139972 177
43422963 178#if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
e01a1f52 179 void CreateGrid( AliHLTTPCCARow *row, const float2* data, int ClusterDataHitNumberOffset );
4acc2401 180 void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
43422963 181#endif
4acc2401 182
e01a1f52 183 int fIsGpuSliceData; //Slice Data for GPU Tracker?
184 int fGPUSharedDataReq; //Size of shared memory required for GPU Reconstruction
185
186 int fFirstRow; //First non-empty row
187 int fLastRow; //Last non-empty row
4acc2401 188
189 int fNumberOfHits; // the number of hits in this slice
e01a1f52 190 int fNumberOfHitsPlusAlign;
b22af1bf 191
4acc2401 192 int fMemorySize; // size of the allocated memory in bytes
e01a1f52 193 int fGpuMemorySize; // size of Memory needed to be transfered to GPU
43422963 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
4acc2401 196
43422963 197 GPUglobalref() MEM_GLOBAL(AliHLTTPCCARow) *fRows; // The row objects needed for most accessor functions
b22af1bf 198
43422963 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
4acc2401 201
43422963 202 GPUglobalref() ushort2 *fHitData; // packed y,z coordinate of the given (global) hit index
4acc2401 203
43422963 204 GPUglobalref() int *fClusterDataIndex; // see ClusterDataIndex()
4acc2401 205
206 /*
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].
209 */
43422963 210 GPUglobalref() unsigned short *fFirstHitInBin; // see FirstHitInBin
4acc2401 211
43422963 212 GPUglobalref() int *fHitWeights; // the weight of the longest tracklet crossed the cluster
4acc2401 213
214};
215
43422963 216MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline short_v MEM_LG(AliHLTTPCCASliceData)::HitLinkUpData ( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex ) const
4acc2401 217{
218 return fLinkUpData[row.fHitNumberOffset + hitIndex];
219}
220
43422963 221MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline short_v MEM_LG(AliHLTTPCCASliceData)::HitLinkDownData( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex ) const
4acc2401 222{
223 return fLinkDownData[row.fHitNumberOffset + hitIndex];
224}
225
43422963 226MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::SetHitLinkUpData ( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex, const short_v &value )
4acc2401 227{
228 fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
229}
230
43422963 231MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::SetHitLinkDownData( const MEM_TYPE( AliHLTTPCCARow)&row, const short_v &hitIndex, const short_v &value )
4acc2401 232{
233 fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
234}
235
43422963 236MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::HitDataY( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
b22af1bf 237{
238 return fHitData[row.fHitNumberOffset + hitIndex].x;
239}
240
43422963 241MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::HitDataZ( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
4acc2401 242{
b22af1bf 243 return fHitData[row.fHitNumberOffset + hitIndex].y;
4acc2401 244}
245
43422963 246MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort2 MEM_LG(AliHLTTPCCASliceData)::HitData( const MEM_TYPE( AliHLTTPCCARow)&row, const uint_v &hitIndex ) const
4acc2401 247{
b22af1bf 248 return fHitData[row.fHitNumberOffset + hitIndex];
4acc2401 249}
250
43422963 251MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline ushort_v MEM_LG(AliHLTTPCCASliceData)::FirstHitInBin( const MEM_TYPE( AliHLTTPCCARow)&row, ushort_v binIndexes ) const
4acc2401 252{
253 return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
254}
255
43422963 256MEM_CLASS_PRE() MEM_TEMPLATE() GPUhd() inline int_v MEM_LG(AliHLTTPCCASliceData)::ClusterDataIndex( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const
4acc2401 257{
258 return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
259}
260
43422963 261MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::MaximizeHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight )
4acc2401 262{
263 CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
264}
265
43422963 266MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline void MEM_LG(AliHLTTPCCASliceData)::SetHitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex, int_v weight )
e4818148 267{
268 fHitWeights[row.fHitNumberOffset + hitIndex] = weight;
269}
270
43422963 271MEM_CLASS_PRE() MEM_TEMPLATE() GPUd() inline int_v MEM_LG(AliHLTTPCCASliceData)::HitWeight( const MEM_TYPE( AliHLTTPCCARow)&row, uint_v hitIndex ) const
4acc2401 272{
273 return fHitWeights[row.fHitNumberOffset + hitIndex];
274}
275
43422963 276//typedef AliHLTTPCCASliceData SliceData;
4acc2401 277
31649d4b 278#endif // ALIHLTTPCCASLICEDATA_H