]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCAStartHitsSorter.cxx
fix of segm. violation in the GPU tracker (by D.Rohr)
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAStartHitsSorter.cxx
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.                           *
5 //                                                                          *
6 // Primary Authors: David Rohr <drohr@kip.uni-heidelberg.de>                            *
7 //                  for The ALICE HLT Project.                              *
8 //                                                                          *
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.                    *
16 //                                                                          *
17 //***************************************************************************
18
19 #include "AliHLTTPCCAStartHitsSorter.h"
20 #include "AliHLTTPCCATracker.h"
21
22 GPUd() void AliHLTTPCCAStartHitsSorter::Thread
23 ( int nBlocks, int nThreads, int iBlock, int iThread, int iSync,
24  AliHLTTPCCASharedMemory &s, AliHLTTPCCATracker &tracker )
25 {
26         //Sorts the Start Hits by Row Index and create RowBlock Data
27         if ( iSync == 0 ) {
28                 if ( iThread == 0 ) {
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;
33                         int startOffset2 = 0;
34
35 #ifndef HLTCA_GPU_ALTERNATIVE_SCHEDULER                         
36                         int startOffset = 0;
37                         int previousBlockEndTracklet = 0;
38                         int nCurrentBlock = 0;
39 #endif
40
41                         for (int ir = 1;ir < tracker.Param().NRows() - 5;ir++)
42                         {
43                                 if (ir < nStartRow)
44                                         startOffset2 += tracker.RowStartHitCountOffset()[ir].x;
45
46 #ifndef HLTCA_GPU_ALTERNATIVE_SCHEDULER                         
47                                 if (iBlock == nBlocks - 1 && nCurrentBlock < gpuFixedBlockCount)
48                                 {
49                                         startOffset += tracker.RowStartHitCountOffset()[ir].x;
50                                         for (int i = previousBlockEndTracklet + HLTCA_GPU_THREAD_COUNT;i <= startOffset;i += HLTCA_GPU_THREAD_COUNT)
51                                         {
52                                                 if (previousBlockEndTracklet / HLTCA_GPU_THREAD_COUNT != i / HLTCA_GPU_THREAD_COUNT)
53                                                 {
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)
58                                                         {
59                                                                 break;
60                                                         }
61                                                 }
62                                         }
63                                         if ((ir + 1) % HLTCA_GPU_SCHED_ROW_STEP == 0 && nCurrentBlock < gpuFixedBlockCount)
64                                         {
65                                                 if (previousBlockEndTracklet != startOffset)
66                                                 {
67                                                         tracker.BlockStartingTracklet()[nCurrentBlock].x = previousBlockEndTracklet;
68                                                         tracker.BlockStartingTracklet()[nCurrentBlock++].y = startOffset - previousBlockEndTracklet;
69                                                         previousBlockEndTracklet = startOffset;
70                                                 }
71                                         }
72                                         if (nCurrentBlock == gpuFixedBlockCount)
73                                         {
74                                                 tracker.GPUParameters()->fScheduleFirstDynamicTracklet = previousBlockEndTracklet;
75                                         }
76                                 }
77                         }
78                         if (iBlock == nBlocks - 1)
79                         {
80                                 if (nCurrentBlock < gpuFixedBlockCount)
81                                 {
82                                         tracker.BlockStartingTracklet()[nCurrentBlock].x = previousBlockEndTracklet;
83                                         tracker.BlockStartingTracklet()[nCurrentBlock++].y = startOffset - previousBlockEndTracklet;
84                                         tracker.GPUParameters()->fScheduleFirstDynamicTracklet = startOffset;
85                                 }
86                                 for (int i = nCurrentBlock;i < nBlocks;i++)
87                                 {
88                                         tracker.BlockStartingTracklet()[i].x = 0;
89                                         tracker.BlockStartingTracklet()[i].y = 0;                       
90                                 }
91 #endif
92                         }
93                         s.fStartOffset = startOffset2;
94                         s.fNRows = nRows;
95                         s.fStartRow = nStartRow;
96                 }
97         } else if ( iSync == 1 ) {
98                 int startOffset = s.fStartOffset;
99                 for (int ir = 0;ir < s.fNRows;ir++)
100                 {
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
105                         if (iThread == 0)
106                                 tracker.RowStartHitCountOffset()[ir + s.fStartRow].z = startOffset;                             //Store New Offset Value of sorted array
107
108                         for (int j = iThread;j < tmpLen;j += nThreads)
109                         {
110                                 startHits[startOffset + j] = tmpStartHits[tmpOffset + j];
111                         }
112                         startOffset += tmpLen;
113                 }
114         }
115 }
116