]>
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(); | |
123 | fCPUTrackers[firstSlice + iSlice].SetupCommonMemory(); | |
124 | } | |
125 | } | |
126 | ||
127 | if (fGPUDebugLevel >= 6 && fUseGPUTracker) | |
128 | { | |
129 | fUseGPUTracker = 0; | |
130 | ProcessSlices(firstSlice, sliceCount, pClusterData, pOutput); | |
131 | fUseGPUTracker = 1; | |
132 | } | |
133 | ||
134 | //printf("Slice Tracks Output: %d\n", pOutput[0].NTracks()); | |
135 | return(0); | |
136 | } | |
137 | ||
138 | unsigned long long int* AliHLTTPCCATrackerFramework::PerfTimer(int GPU, int iSlice, int iTimer) | |
139 | { | |
140 | //Performance information for slice trackers | |
31649d4b | 141 | return(GPU ? fGPUTracker->PerfTimer(iSlice, iTimer) : fCPUTrackers[iSlice].PerfTimer(iTimer)); |
b22af1bf | 142 | } |
143 | ||
144 | int AliHLTTPCCATrackerFramework::InitializeSliceParam(int iSlice, AliHLTTPCCAParam ¶m) | |
145 | { | |
146 | //Initialize Tracker Parameters for a slice | |
31649d4b | 147 | if (fGPUTrackerAvailable && fGPUTracker->InitializeSliceParam(iSlice, param)) return(1); |
b22af1bf | 148 | fCPUTrackers[iSlice].Initialize(param); |
149 | return(0); | |
a59a784e | 150 | } |
31649d4b | 151 | |
152 | #define GPULIBNAME "libAliHLTTPCCAGPU" | |
153 | ||
154 | AliHLTTPCCATrackerFramework::AliHLTTPCCATrackerFramework(int allowGPU) : fGPULibAvailable(false), fGPUTrackerAvailable(false), fUseGPUTracker(false), fGPUDebugLevel(0), fGPUSliceCount(0), fGPUTracker(NULL), fGPULib(NULL), fOutputControl( NULL ), fCPUSliceCount(fgkNSlices) | |
155 | { | |
156 | //Constructor | |
157 | #ifdef R__WIN32 | |
158 | HMODULE hGPULib = LoadLibraryEx(GPULIBNAME ".dll", NULL, NULL); | |
159 | #else | |
160 | void* hGPULib = dlopen(GPULIBNAME ".so", RTLD_NOW); | |
161 | #endif | |
162 | if (hGPULib == NULL) | |
163 | { | |
31649d4b | 164 | if (allowGPU) |
165 | { | |
7dd6188c | 166 | #ifndef R__WIN32 |
167 | HLTInfo("The following error occured during dlopen: %s", dlerror()); | |
168 | #endif | |
169 | HLTError("Error Opening cagpu library for GPU Tracker, will fallback to CPU"); | |
31649d4b | 170 | } |
171 | else | |
172 | { | |
7dd6188c | 173 | HLTDebug("Cagpu library was not found, Tracking on GPU will not be available"); |
31649d4b | 174 | } |
175 | fGPUTracker = new AliHLTTPCCAGPUTracker; | |
176 | } | |
177 | else | |
178 | { | |
179 | #ifdef R__WIN32 | |
180 | FARPROC createFunc = GetProcAddress(hGPULib, "AliHLTTPCCAGPUTrackerNVCCCreate"); | |
181 | #else | |
182 | void* createFunc = (void*) dlsym(hGPULib, "AliHLTTPCCAGPUTrackerNVCCCreate"); | |
183 | #endif | |
184 | if (createFunc == NULL) | |
185 | { | |
186 | HLTError("Error Creating GPU Tracker\n"); | |
187 | #ifdef R__WIN32 | |
188 | FreeLibrary(hGPULib); | |
189 | #else | |
190 | dlclose(hGPULib); | |
191 | #endif | |
192 | fGPUTracker = new AliHLTTPCCAGPUTracker; | |
193 | } | |
194 | else | |
195 | { | |
196 | AliHLTTPCCAGPUTracker* (*tmp)() = (AliHLTTPCCAGPUTracker* (*)()) createFunc; | |
197 | fGPUTracker = tmp(); | |
198 | fGPULibAvailable = true; | |
199 | fGPULib = (void*) (size_t) hGPULib; | |
200 | HLTImportant("GPU Tracker Created by Wrapper library"); | |
201 | } | |
202 | } | |
203 | ||
204 | if (allowGPU && fGPULibAvailable) | |
205 | { | |
206 | fUseGPUTracker = (fGPUTrackerAvailable= (fGPUTracker->InitGPU() == 0)); | |
207 | fGPUSliceCount = fGPUTrackerAvailable ? fGPUTracker->GetSliceCount() : 0; | |
208 | HLTInfo("GPU Tracker Initialized and available in framework"); | |
209 | } | |
210 | } | |
211 | ||
212 | AliHLTTPCCATrackerFramework::~AliHLTTPCCATrackerFramework() | |
213 | { | |
214 | #ifdef R__WIN32 | |
215 | HMODULE hGPULib = (HMODULE) (size_t) fGPULib; | |
216 | #else | |
217 | void* hGPULib = fGPULib; | |
218 | #endif | |
219 | if (fGPULib) | |
220 | { | |
221 | if (fGPUTracker) | |
222 | { | |
223 | #ifdef R__WIN32 | |
224 | FARPROC destroyFunc = GetProcAddress(hGPULib, "AliHLTTPCCAGPUTrackerNVCCDestroy"); | |
225 | #else | |
226 | void* destroyFunc = (void*) dlsym(hGPULib, "AliHLTTPCCAGPUTrackerNVCCDestroy"); | |
227 | #endif | |
228 | if (destroyFunc == NULL) | |
229 | { | |
230 | HLTError("Error Freeing GPU Tracker\n"); | |
231 | } | |
232 | else | |
233 | { | |
234 | void (*tmp)(AliHLTTPCCAGPUTracker*) = (void (*)(AliHLTTPCCAGPUTracker*)) destroyFunc; | |
235 | tmp(fGPUTracker); | |
236 | } | |
237 | } | |
238 | ||
239 | #ifdef R__WIN32 | |
240 | FreeLibrary(hGPULib); | |
241 | #else | |
242 | dlclose(hGPULib); | |
243 | #endif | |
244 | } | |
245 | else if (fGPUTracker) | |
246 | { | |
247 | delete fGPUTracker; | |
248 | } | |
249 | fGPULib = NULL; | |
250 | fGPUTracker = NULL; | |
251 | } |