]>
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; |
53 | fGPUSliceCount = sliceCount; | |
54 | return(retVal); | |
55 | } | |
56 | ||
57 | int AliHLTTPCCATrackerFramework::ExitGPU() | |
58 | { | |
59 | //Uninitialize GPU Tracker | |
60 | if (!fGPUTrackerAvailable) return(0); | |
61 | fUseGPUTracker = false; | |
62 | fGPUTrackerAvailable = false; | |
31649d4b | 63 | return(fGPUTracker->ExitGPU()); |
b22af1bf | 64 | } |
65 | ||
66 | void AliHLTTPCCATrackerFramework::SetGPUDebugLevel(int Level, std::ostream *OutFile, std::ostream *GPUOutFile) | |
67 | { | |
68 | //Set Debug Level for GPU Tracker and also for CPU Tracker for comparison reasons | |
31649d4b | 69 | fGPUTracker->SetDebugLevel(Level, GPUOutFile); |
b22af1bf | 70 | fGPUDebugLevel = Level; |
71 | for (int i = 0;i < fgkNSlices;i++) | |
72 | { | |
73 | fCPUTrackers[i].SetGPUDebugLevel(Level, OutFile); | |
74 | } | |
75 | } | |
76 | ||
77 | int AliHLTTPCCATrackerFramework::SetGPUTracker(bool enable) | |
78 | { | |
79 | //Enable / disable GPU Tracker | |
80 | if (enable && !fGPUTrackerAvailable) | |
81 | { | |
82 | fUseGPUTracker = false; | |
83 | return(1); | |
84 | } | |
85 | fUseGPUTracker = enable; | |
86 | return(0); | |
87 | } | |
88 | ||
d4594e7d | 89 | GPUhd() void AliHLTTPCCATrackerFramework::SetOutputControl( AliHLTTPCCASliceOutput::outputControlStruct* val) |
90 | { | |
444e5682 | 91 | //Set Output Control Pointers |
d4594e7d | 92 | fOutputControl = val; |
31649d4b | 93 | fGPUTracker->SetOutputControl(val); |
d4594e7d | 94 | for (int i = 0;i < fgkNSlices;i++) |
95 | { | |
96 | fCPUTrackers[i].SetOutputControl(val); | |
97 | } | |
98 | } | |
99 | ||
98512261 | 100 | int AliHLTTPCCATrackerFramework::ProcessSlices(int firstSlice, int sliceCount, AliHLTTPCCAClusterData* pClusterData, AliHLTTPCCASliceOutput** pOutput) |
b22af1bf | 101 | { |
102 | //Process sliceCount slices starting from firstslice, in is pClusterData array, out pOutput array | |
103 | if (fUseGPUTracker) | |
104 | { | |
31649d4b | 105 | if (fGPUTracker->Reconstruct(pOutput, pClusterData, firstSlice, CAMath::Min(sliceCount, fgkNSlices - firstSlice))) return(1); |
b22af1bf | 106 | } |
107 | else | |
108 | { | |
109 | #ifdef HLTCA_STANDALONE | |
d4594e7d | 110 | if (fOutputControl->fOutputPtr && omp_get_max_threads() > 1) |
111 | { | |
31649d4b | 112 | HLTError("fOutputPtr must not be used with OpenMP\n"); |
d4594e7d | 113 | return(1); |
114 | } | |
115 | ||
b22af1bf | 116 | #pragma omp parallel for |
117 | #endif | |
118 | for (int iSlice = 0;iSlice < CAMath::Min(sliceCount, fgkNSlices - firstSlice);iSlice++) | |
119 | { | |
120 | fCPUTrackers[firstSlice + iSlice].ReadEvent(&pClusterData[iSlice]); | |
121 | fCPUTrackers[firstSlice + iSlice].SetOutput(&pOutput[iSlice]); | |
122 | fCPUTrackers[firstSlice + iSlice].Reconstruct(); | |
f0bada7f | 123 | if (!fKeepData) |
124 | { | |
125 | fCPUTrackers[firstSlice + iSlice].SetupCommonMemory(); | |
126 | } | |
b22af1bf | 127 | } |
128 | } | |
129 | ||
130 | if (fGPUDebugLevel >= 6 && fUseGPUTracker) | |
131 | { | |
132 | fUseGPUTracker = 0; | |
133 | ProcessSlices(firstSlice, sliceCount, pClusterData, pOutput); | |
134 | fUseGPUTracker = 1; | |
135 | } | |
136 | ||
137 | //printf("Slice Tracks Output: %d\n", pOutput[0].NTracks()); | |
138 | return(0); | |
139 | } | |
140 | ||
141 | unsigned long long int* AliHLTTPCCATrackerFramework::PerfTimer(int GPU, int iSlice, int iTimer) | |
142 | { | |
143 | //Performance information for slice trackers | |
31649d4b | 144 | return(GPU ? fGPUTracker->PerfTimer(iSlice, iTimer) : fCPUTrackers[iSlice].PerfTimer(iTimer)); |
b22af1bf | 145 | } |
146 | ||
147 | int AliHLTTPCCATrackerFramework::InitializeSliceParam(int iSlice, AliHLTTPCCAParam ¶m) | |
148 | { | |
149 | //Initialize Tracker Parameters for a slice | |
31649d4b | 150 | if (fGPUTrackerAvailable && fGPUTracker->InitializeSliceParam(iSlice, param)) return(1); |
b22af1bf | 151 | fCPUTrackers[iSlice].Initialize(param); |
152 | return(0); | |
a59a784e | 153 | } |
31649d4b | 154 | |
f0bada7f | 155 | #ifdef HLTCA_STANDALONE |
156 | #define GPULIBNAME "libAliHLTTPCCAGPUSA" | |
157 | #else | |
31649d4b | 158 | #define GPULIBNAME "libAliHLTTPCCAGPU" |
f0bada7f | 159 | #endif |
31649d4b | 160 | |
f0bada7f | 161 | AliHLTTPCCATrackerFramework::AliHLTTPCCATrackerFramework(int allowGPU) : fGPULibAvailable(false), fGPUTrackerAvailable(false), fUseGPUTracker(false), fGPUDebugLevel(0), fGPUSliceCount(0), fGPUTracker(NULL), fGPULib(NULL), fOutputControl( NULL ), fCPUSliceCount(fgkNSlices), fKeepData(false) |
31649d4b | 162 | { |
163 | //Constructor | |
164 | #ifdef R__WIN32 | |
165 | HMODULE hGPULib = LoadLibraryEx(GPULIBNAME ".dll", NULL, NULL); | |
166 | #else | |
167 | void* hGPULib = dlopen(GPULIBNAME ".so", RTLD_NOW); | |
168 | #endif | |
169 | if (hGPULib == NULL) | |
170 | { | |
31649d4b | 171 | if (allowGPU) |
172 | { | |
7dd6188c | 173 | #ifndef R__WIN32 |
174 | HLTInfo("The following error occured during dlopen: %s", dlerror()); | |
175 | #endif | |
176 | HLTError("Error Opening cagpu library for GPU Tracker, will fallback to CPU"); | |
31649d4b | 177 | } |
178 | else | |
179 | { | |
7dd6188c | 180 | HLTDebug("Cagpu library was not found, Tracking on GPU will not be available"); |
31649d4b | 181 | } |
182 | fGPUTracker = new AliHLTTPCCAGPUTracker; | |
183 | } | |
184 | else | |
185 | { | |
186 | #ifdef R__WIN32 | |
187 | FARPROC createFunc = GetProcAddress(hGPULib, "AliHLTTPCCAGPUTrackerNVCCCreate"); | |
188 | #else | |
189 | void* createFunc = (void*) dlsym(hGPULib, "AliHLTTPCCAGPUTrackerNVCCCreate"); | |
190 | #endif | |
191 | if (createFunc == NULL) | |
192 | { | |
193 | HLTError("Error Creating GPU Tracker\n"); | |
194 | #ifdef R__WIN32 | |
195 | FreeLibrary(hGPULib); | |
196 | #else | |
197 | dlclose(hGPULib); | |
198 | #endif | |
199 | fGPUTracker = new AliHLTTPCCAGPUTracker; | |
200 | } | |
201 | else | |
202 | { | |
203 | AliHLTTPCCAGPUTracker* (*tmp)() = (AliHLTTPCCAGPUTracker* (*)()) createFunc; | |
204 | fGPUTracker = tmp(); | |
205 | fGPULibAvailable = true; | |
206 | fGPULib = (void*) (size_t) hGPULib; | |
207 | HLTImportant("GPU Tracker Created by Wrapper library"); | |
208 | } | |
209 | } | |
210 | ||
211 | if (allowGPU && fGPULibAvailable) | |
212 | { | |
213 | fUseGPUTracker = (fGPUTrackerAvailable= (fGPUTracker->InitGPU() == 0)); | |
214 | fGPUSliceCount = fGPUTrackerAvailable ? fGPUTracker->GetSliceCount() : 0; | |
215 | HLTInfo("GPU Tracker Initialized and available in framework"); | |
216 | } | |
217 | } | |
218 | ||
219 | AliHLTTPCCATrackerFramework::~AliHLTTPCCATrackerFramework() | |
220 | { | |
221 | #ifdef R__WIN32 | |
222 | HMODULE hGPULib = (HMODULE) (size_t) fGPULib; | |
223 | #else | |
224 | void* hGPULib = fGPULib; | |
225 | #endif | |
226 | if (fGPULib) | |
227 | { | |
228 | if (fGPUTracker) | |
229 | { | |
230 | #ifdef R__WIN32 | |
231 | FARPROC destroyFunc = GetProcAddress(hGPULib, "AliHLTTPCCAGPUTrackerNVCCDestroy"); | |
232 | #else | |
233 | void* destroyFunc = (void*) dlsym(hGPULib, "AliHLTTPCCAGPUTrackerNVCCDestroy"); | |
234 | #endif | |
235 | if (destroyFunc == NULL) | |
236 | { | |
237 | HLTError("Error Freeing GPU Tracker\n"); | |
238 | } | |
239 | else | |
240 | { | |
241 | void (*tmp)(AliHLTTPCCAGPUTracker*) = (void (*)(AliHLTTPCCAGPUTracker*)) destroyFunc; | |
242 | tmp(fGPUTracker); | |
243 | } | |
244 | } | |
245 | ||
246 | #ifdef R__WIN32 | |
247 | FreeLibrary(hGPULib); | |
248 | #else | |
249 | dlclose(hGPULib); | |
250 | #endif | |
251 | } | |
252 | else if (fGPUTracker) | |
253 | { | |
254 | delete fGPUTracker; | |
255 | } | |
256 | fGPULib = NULL; | |
257 | fGPUTracker = NULL; | |
258 | } |