]>
Commit | Line | Data |
---|---|---|
b22af1bf | 1 | // @(#) $Id: AliHLTTPCCATracker.cxx 34611 2009-09-04 00:22:05Z sgorbuno $ |
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: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> * | |
7 | // Ivan Kisel <kisel@kip.uni-heidelberg.de> * | |
8 | // for The ALICE HLT Project. * | |
9 | // * | |
10 | // Permission to use, copy, modify and distribute this software and its * | |
11 | // documentation strictly for non-commercial purposes is hereby granted * | |
12 | // without fee, provided that the above copyright notice appears in all * | |
13 | // copies and that both the copyright notice and this permission notice * | |
14 | // appear in the supporting documentation. The authors make no claims * | |
15 | // about the suitability of this software for any purpose. It is * | |
16 | // provided "as is" without express or implied warranty. * | |
17 | // * | |
18 | //*************************************************************************** | |
19 | ||
20 | #include "AliHLTTPCCADef.h" | |
21 | #include "AliHLTTPCCAGPUConfig.h" | |
22 | #include "AliHLTTPCCATrackerFramework.h" | |
23 | #include "AliHLTTPCCAGPUTracker.h" | |
24 | #include "AliHLTTPCCATracker.h" | |
25 | #include "AliHLTTPCCAMath.h" | |
26 | #include "AliHLTTPCCAClusterData.h" | |
27 | ||
31649d4b | 28 | #ifdef R__WIN32 |
29 | #include <windows.h> | |
30 | #include <winbase.h> | |
31 | #else | |
32 | #include <dlfcn.h> | |
33 | #endif | |
34 | ||
b22af1bf | 35 | #ifdef HLTCA_STANDALONE |
36 | #include <omp.h> | |
37 | #endif | |
38 | ||
31649d4b | 39 | ClassImp( AliHLTTPCCATrackerFramework ) |
40 | ||
b22af1bf | 41 | int AliHLTTPCCATrackerFramework::InitGPU(int sliceCount, int forceDeviceID) |
42 | { | |
43 | //Initialize GPU Tracker and determine if GPU available | |
44 | int retVal; | |
31649d4b | 45 | if (!fGPULibAvailable) |
46 | { | |
47 | HLTError("GPU Library not loaded\n"); | |
48 | return(1); | |
49 | } | |
b22af1bf | 50 | if (fGPUTrackerAvailable && (retVal = ExitGPU())) return(retVal); |
31649d4b | 51 | retVal = fGPUTracker->InitGPU(sliceCount, forceDeviceID); |
b22af1bf | 52 | fUseGPUTracker = fGPUTrackerAvailable = retVal == 0; |
b22af1bf | 53 | return(retVal); |
54 | } | |
55 | ||
56 | int AliHLTTPCCATrackerFramework::ExitGPU() | |
57 | { | |
58 | //Uninitialize GPU Tracker | |
59 | if (!fGPUTrackerAvailable) return(0); | |
60 | fUseGPUTracker = false; | |
61 | fGPUTrackerAvailable = false; | |
31649d4b | 62 | return(fGPUTracker->ExitGPU()); |
b22af1bf | 63 | } |
64 | ||
65 | void AliHLTTPCCATrackerFramework::SetGPUDebugLevel(int Level, std::ostream *OutFile, std::ostream *GPUOutFile) | |
66 | { | |
67 | //Set Debug Level for GPU Tracker and also for CPU Tracker for comparison reasons | |
31649d4b | 68 | fGPUTracker->SetDebugLevel(Level, GPUOutFile); |
b22af1bf | 69 | fGPUDebugLevel = Level; |
70 | for (int i = 0;i < fgkNSlices;i++) | |
71 | { | |
72 | fCPUTrackers[i].SetGPUDebugLevel(Level, OutFile); | |
73 | } | |
74 | } | |
75 | ||
76 | int AliHLTTPCCATrackerFramework::SetGPUTracker(bool enable) | |
77 | { | |
78 | //Enable / disable GPU Tracker | |
79 | if (enable && !fGPUTrackerAvailable) | |
80 | { | |
81 | fUseGPUTracker = false; | |
82 | return(1); | |
83 | } | |
84 | fUseGPUTracker = enable; | |
85 | return(0); | |
86 | } | |
87 | ||
d4594e7d | 88 | GPUhd() void AliHLTTPCCATrackerFramework::SetOutputControl( AliHLTTPCCASliceOutput::outputControlStruct* val) |
89 | { | |
444e5682 | 90 | //Set Output Control Pointers |
d4594e7d | 91 | fOutputControl = val; |
31649d4b | 92 | fGPUTracker->SetOutputControl(val); |
d4594e7d | 93 | for (int i = 0;i < fgkNSlices;i++) |
94 | { | |
95 | fCPUTrackers[i].SetOutputControl(val); | |
96 | } | |
97 | } | |
98 | ||
98512261 | 99 | int AliHLTTPCCATrackerFramework::ProcessSlices(int firstSlice, int sliceCount, AliHLTTPCCAClusterData* pClusterData, AliHLTTPCCASliceOutput** pOutput) |
b22af1bf | 100 | { |
101 | //Process sliceCount slices starting from firstslice, in is pClusterData array, out pOutput array | |
102 | if (fUseGPUTracker) | |
103 | { | |
31649d4b | 104 | if (fGPUTracker->Reconstruct(pOutput, pClusterData, firstSlice, CAMath::Min(sliceCount, fgkNSlices - firstSlice))) return(1); |
b22af1bf | 105 | } |
106 | else | |
107 | { | |
108 | #ifdef HLTCA_STANDALONE | |
d4594e7d | 109 | if (fOutputControl->fOutputPtr && omp_get_max_threads() > 1) |
110 | { | |
31649d4b | 111 | HLTError("fOutputPtr must not be used with OpenMP\n"); |
d4594e7d | 112 | return(1); |
113 | } | |
114 | ||
b22af1bf | 115 | #pragma omp parallel for |
116 | #endif | |
117 | for (int iSlice = 0;iSlice < CAMath::Min(sliceCount, fgkNSlices - firstSlice);iSlice++) | |
118 | { | |
119 | fCPUTrackers[firstSlice + iSlice].ReadEvent(&pClusterData[iSlice]); | |
120 | fCPUTrackers[firstSlice + iSlice].SetOutput(&pOutput[iSlice]); | |
121 | fCPUTrackers[firstSlice + iSlice].Reconstruct(); | |
f0bada7f | 122 | if (!fKeepData) |
123 | { | |
124 | fCPUTrackers[firstSlice + iSlice].SetupCommonMemory(); | |
125 | } | |
b22af1bf | 126 | } |
127 | } | |
128 | ||
129 | if (fGPUDebugLevel >= 6 && fUseGPUTracker) | |
130 | { | |
131 | fUseGPUTracker = 0; | |
132 | ProcessSlices(firstSlice, sliceCount, pClusterData, pOutput); | |
133 | fUseGPUTracker = 1; | |
134 | } | |
135 | ||
136 | //printf("Slice Tracks Output: %d\n", pOutput[0].NTracks()); | |
137 | return(0); | |
138 | } | |
139 | ||
140 | unsigned long long int* AliHLTTPCCATrackerFramework::PerfTimer(int GPU, int iSlice, int iTimer) | |
141 | { | |
142 | //Performance information for slice trackers | |
31649d4b | 143 | return(GPU ? fGPUTracker->PerfTimer(iSlice, iTimer) : fCPUTrackers[iSlice].PerfTimer(iTimer)); |
b22af1bf | 144 | } |
145 | ||
146 | int AliHLTTPCCATrackerFramework::InitializeSliceParam(int iSlice, AliHLTTPCCAParam ¶m) | |
147 | { | |
148 | //Initialize Tracker Parameters for a slice | |
31649d4b | 149 | if (fGPUTrackerAvailable && fGPUTracker->InitializeSliceParam(iSlice, param)) return(1); |
b22af1bf | 150 | fCPUTrackers[iSlice].Initialize(param); |
151 | return(0); | |
a59a784e | 152 | } |
31649d4b | 153 | |
f0bada7f | 154 | #ifdef HLTCA_STANDALONE |
155 | #define GPULIBNAME "libAliHLTTPCCAGPUSA" | |
156 | #else | |
31649d4b | 157 | #define GPULIBNAME "libAliHLTTPCCAGPU" |
f0bada7f | 158 | #endif |
31649d4b | 159 | |
1e63725a | 160 | AliHLTTPCCATrackerFramework::AliHLTTPCCATrackerFramework(int allowGPU) : fGPULibAvailable(false), fGPUTrackerAvailable(false), fUseGPUTracker(false), fGPUDebugLevel(0), fGPUTracker(NULL), fGPULib(NULL), fOutputControl( NULL ), fKeepData(false) |
31649d4b | 161 | { |
162 | //Constructor | |
163 | #ifdef R__WIN32 | |
164 | HMODULE hGPULib = LoadLibraryEx(GPULIBNAME ".dll", NULL, NULL); | |
165 | #else | |
166 | void* hGPULib = dlopen(GPULIBNAME ".so", RTLD_NOW); | |
167 | #endif | |
168 | if (hGPULib == NULL) | |
169 | { | |
31649d4b | 170 | if (allowGPU) |
171 | { | |
7dd6188c | 172 | #ifndef R__WIN32 |
173 | HLTInfo("The following error occured during dlopen: %s", dlerror()); | |
174 | #endif | |
175 | HLTError("Error Opening cagpu library for GPU Tracker, will fallback to CPU"); | |
31649d4b | 176 | } |
177 | else | |
178 | { | |
7dd6188c | 179 | HLTDebug("Cagpu library was not found, Tracking on GPU will not be available"); |
31649d4b | 180 | } |
181 | fGPUTracker = new AliHLTTPCCAGPUTracker; | |
182 | } | |
183 | else | |
184 | { | |
185 | #ifdef R__WIN32 | |
186 | FARPROC createFunc = GetProcAddress(hGPULib, "AliHLTTPCCAGPUTrackerNVCCCreate"); | |
187 | #else | |
188 | void* createFunc = (void*) dlsym(hGPULib, "AliHLTTPCCAGPUTrackerNVCCCreate"); | |
189 | #endif | |
190 | if (createFunc == NULL) | |
191 | { | |
192 | HLTError("Error Creating GPU Tracker\n"); | |
193 | #ifdef R__WIN32 | |
194 | FreeLibrary(hGPULib); | |
195 | #else | |
196 | dlclose(hGPULib); | |
197 | #endif | |
198 | fGPUTracker = new AliHLTTPCCAGPUTracker; | |
199 | } | |
200 | else | |
201 | { | |
202 | AliHLTTPCCAGPUTracker* (*tmp)() = (AliHLTTPCCAGPUTracker* (*)()) createFunc; | |
203 | fGPUTracker = tmp(); | |
204 | fGPULibAvailable = true; | |
205 | fGPULib = (void*) (size_t) hGPULib; | |
1e63725a | 206 | HLTImportant("GPU Tracker library loaded and GPU tracker object created sucessfully (%sactive)", allowGPU ? "" : "in"); |
31649d4b | 207 | } |
208 | } | |
209 | ||
210 | if (allowGPU && fGPULibAvailable) | |
211 | { | |
1e63725a | 212 | fUseGPUTracker = (fGPUTrackerAvailable = (fGPUTracker->InitGPU() == 0)); |
31649d4b | 213 | HLTInfo("GPU Tracker Initialized and available in framework"); |
214 | } | |
215 | } | |
216 | ||
217 | AliHLTTPCCATrackerFramework::~AliHLTTPCCATrackerFramework() | |
218 | { | |
219 | #ifdef R__WIN32 | |
220 | HMODULE hGPULib = (HMODULE) (size_t) fGPULib; | |
221 | #else | |
222 | void* hGPULib = fGPULib; | |
223 | #endif | |
224 | if (fGPULib) | |
225 | { | |
226 | if (fGPUTracker) | |
227 | { | |
228 | #ifdef R__WIN32 | |
229 | FARPROC destroyFunc = GetProcAddress(hGPULib, "AliHLTTPCCAGPUTrackerNVCCDestroy"); | |
230 | #else | |
231 | void* destroyFunc = (void*) dlsym(hGPULib, "AliHLTTPCCAGPUTrackerNVCCDestroy"); | |
232 | #endif | |
233 | if (destroyFunc == NULL) | |
234 | { | |
235 | HLTError("Error Freeing GPU Tracker\n"); | |
236 | } | |
237 | else | |
238 | { | |
239 | void (*tmp)(AliHLTTPCCAGPUTracker*) = (void (*)(AliHLTTPCCAGPUTracker*)) destroyFunc; | |
240 | tmp(fGPUTracker); | |
241 | } | |
242 | } | |
243 | ||
244 | #ifdef R__WIN32 | |
245 | FreeLibrary(hGPULib); | |
246 | #else | |
247 | dlclose(hGPULib); | |
248 | #endif | |
249 | } | |
250 | else if (fGPUTracker) | |
251 | { | |
252 | delete fGPUTracker; | |
253 | } | |
254 | fGPULib = NULL; | |
255 | fGPUTracker = NULL; | |
256 | } |