1 // @(#) $Id: AliHLTTPCCAStartHitsFinder.cxx 27042 2008-07-02 12:06:02Z richterm $
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
6 // Primary Authors: David Rohr <drohr@kip.uni-heidelberg.de> *
7 // for The ALICE HLT Project. *
9 // Permission to use, copy, modify and distribute this software and its *
10 // documentation strictly for non-commercial purposes is hereby granted *
11 // without fee, provided that the above copyright notice appears in all *
12 // copies and that both the copyright notice and this permission notice *
13 // appear in the supporting documentation. The authors make no claims *
14 // about the suitability of this software for any purpose. It is *
15 // provided "as is" without express or implied warranty. *
17 //***************************************************************************
19 #include "AliHLTTPCCAStartHitsSorter.h"
20 #include "AliHLTTPCCATracker.h"
22 GPUd() void AliHLTTPCCAStartHitsSorter::Thread
23 ( int nBlocks, int nThreads, int iBlock, int iThread, int iSync,
24 AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
26 //Sorts the Start Hits by Row Index and create RowBlock Data
29 const int gpuFixedBlockCount = tracker.GPUParametersConst()->fGPUFixedBlockCount;
30 const int tmpNRows = tracker.Param().NRows() - 6;
31 const int nRows = iBlock == (nBlocks - 1) ? (tmpNRows - (tmpNRows / nBlocks) * (nBlocks - 1)) : (tmpNRows / nBlocks);
32 const int nStartRow = (tmpNRows / nBlocks) * iBlock + 1;
35 #ifndef HLTCA_GPU_ALTERNATIVE_SCHEDULER
37 int previousBlockEndTracklet = 0;
38 int nCurrentBlock = 0;
41 for (int ir = 1;ir < tracker.Param().NRows() - 5;ir++)
44 startOffset2 += tracker.RowStartHitCountOffset()[ir].x;
46 #ifndef HLTCA_GPU_ALTERNATIVE_SCHEDULER
47 if (iBlock == nBlocks - 1 && nCurrentBlock < gpuFixedBlockCount)
49 startOffset += tracker.RowStartHitCountOffset()[ir].x;
50 for (int i = previousBlockEndTracklet + HLTCA_GPU_THREAD_COUNT;i <= startOffset;i += HLTCA_GPU_THREAD_COUNT)
52 if (previousBlockEndTracklet / HLTCA_GPU_THREAD_COUNT != i / HLTCA_GPU_THREAD_COUNT)
54 tracker.BlockStartingTracklet()[nCurrentBlock].x = previousBlockEndTracklet;
55 tracker.BlockStartingTracklet()[nCurrentBlock++].y = HLTCA_GPU_THREAD_COUNT;
56 previousBlockEndTracklet += HLTCA_GPU_THREAD_COUNT;
57 if (nCurrentBlock == gpuFixedBlockCount)
63 if ((ir + 1) % HLTCA_GPU_SCHED_ROW_STEP == 0 && nCurrentBlock < gpuFixedBlockCount)
65 if (previousBlockEndTracklet != startOffset)
67 tracker.BlockStartingTracklet()[nCurrentBlock].x = previousBlockEndTracklet;
68 tracker.BlockStartingTracklet()[nCurrentBlock++].y = startOffset - previousBlockEndTracklet;
69 previousBlockEndTracklet = startOffset;
72 if (nCurrentBlock == gpuFixedBlockCount)
74 tracker.GPUParameters()->fScheduleFirstDynamicTracklet = previousBlockEndTracklet;
78 if (iBlock == nBlocks - 1)
80 if (nCurrentBlock < gpuFixedBlockCount)
82 tracker.BlockStartingTracklet()[nCurrentBlock].x = previousBlockEndTracklet;
83 tracker.BlockStartingTracklet()[nCurrentBlock++].y = startOffset - previousBlockEndTracklet;
84 tracker.GPUParameters()->fScheduleFirstDynamicTracklet = startOffset;
86 for (int i = nCurrentBlock;i < nBlocks;i++)
88 tracker.BlockStartingTracklet()[i].x = 0;
89 tracker.BlockStartingTracklet()[i].y = 0;
93 s.fStartOffset = startOffset2;
95 s.fStartRow = nStartRow;
97 } else if ( iSync == 1 ) {
98 int startOffset = s.fStartOffset;
99 for (int ir = 0;ir < s.fNRows;ir++)
101 AliHLTTPCCAHitId *const startHits = tracker.TrackletStartHits();
102 AliHLTTPCCAHitId *const tmpStartHits = tracker.TrackletTmpStartHits();
103 const int tmpLen = tracker.RowStartHitCountOffset()[ir + s.fStartRow].x; //Length of hits in row stored by StartHitsFinder
104 const int tmpOffset = tracker.RowStartHitCountOffset()[ir + s.fStartRow].y; //Offset of first hit in row of unsorted array by StartHitsFinder
106 tracker.RowStartHitCountOffset()[ir + s.fStartRow].z = startOffset; //Store New Offset Value of sorted array
108 for (int j = iThread;j < tmpLen;j += nThreads)
110 startHits[startOffset + j] = tmpStartHits[tmpOffset + j];
112 startOffset += tmpLen;