@@ -41,57 +41,6 @@ GPUReconstructionDeviceBase::GPUReconstructionDeviceBase(const GPUSettingsDevice
4141
4242GPUReconstructionDeviceBase::~GPUReconstructionDeviceBase () = default ;
4343
44- void * GPUReconstructionDeviceBase::helperWrapper_static (void * arg)
45- {
46- GPUReconstructionHelpers::helperParam* par = (GPUReconstructionHelpers::helperParam*)arg;
47- GPUReconstructionDeviceBase* cls = par->cls ;
48- return cls->helperWrapper (par);
49- }
50-
51- void * GPUReconstructionDeviceBase::helperWrapper (GPUReconstructionHelpers::helperParam* par)
52- {
53- if (mProcessingSettings .debugLevel >= 3 ) {
54- GPUInfo (" \t Helper thread %d starting" , par->num );
55- }
56-
57- // cpu_set_t mask; //TODO add option
58- // CPU_ZERO(&mask);
59- // CPU_SET(par->num * 2 + 2, &mask);
60- // sched_setaffinity(0, sizeof(mask), &mask);
61-
62- par->mutex [0 ].lock ();
63- while (par->terminate == false ) {
64- for (int32_t i = par->num + 1 ; i < par->count ; i += mProcessingSettings .nDeviceHelperThreads + 1 ) {
65- // if (mProcessingSettings.debugLevel >= 3) GPUInfo("\tHelper Thread %d Running, Slice %d+%d, Phase %d", par->num, i, par->phase);
66- if ((par->functionCls ->*par->function )(i, par->num + 1 , par)) {
67- par->error = 1 ;
68- }
69- if (par->reset ) {
70- break ;
71- }
72- par->done = i + 1 ;
73- // if (mProcessingSettings.debugLevel >= 3) GPUInfo("\tHelper Thread %d Finished, Slice %d+%d, Phase %d", par->num, i, par->phase);
74- }
75- ResetThisHelperThread (par);
76- par->mutex [0 ].lock ();
77- }
78- if (mProcessingSettings .debugLevel >= 3 ) {
79- GPUInfo (" \t Helper thread %d terminating" , par->num );
80- }
81- par->mutex [1 ].unlock ();
82- pthread_exit (nullptr );
83- return (nullptr );
84- }
85-
86- void GPUReconstructionDeviceBase::ResetThisHelperThread (GPUReconstructionHelpers::helperParam* par)
87- {
88- if (par->reset ) {
89- GPUImportant (" GPU Helper Thread %d reseting" , par->num );
90- }
91- par->reset = false ;
92- par->mutex [1 ].unlock ();
93- }
94-
9544int32_t GPUReconstructionDeviceBase::GetGlobalLock (void *& pLock)
9645{
9746#ifdef _WIN32
@@ -138,86 +87,6 @@ void GPUReconstructionDeviceBase::ReleaseGlobalLock(void* sem)
13887#endif
13988}
14089
141- void GPUReconstructionDeviceBase::ResetHelperThreads (int32_t helpers)
142- {
143- GPUImportant (" Error occurred, GPU tracker helper threads will be reset (Number of threads %d (%d))" , mProcessingSettings .nDeviceHelperThreads , mNSlaveThreads );
144- SynchronizeGPU ();
145- for (int32_t i = 0 ; i < mProcessingSettings .nDeviceHelperThreads ; i++) {
146- mHelperParams [i].reset = true ;
147- if (helpers || i >= mProcessingSettings .nDeviceHelperThreads ) {
148- pthread_mutex_lock (&((pthread_mutex_t *)mHelperParams [i].mutex )[1 ]);
149- }
150- }
151- GPUImportant (" GPU Tracker helper threads have ben reset" );
152- }
153-
154- int32_t GPUReconstructionDeviceBase::StartHelperThreads ()
155- {
156- int32_t nThreads = mProcessingSettings .nDeviceHelperThreads ;
157- if (nThreads) {
158- mHelperParams = new GPUReconstructionHelpers::helperParam[nThreads];
159- if (mHelperParams == nullptr ) {
160- GPUError (" Memory allocation error" );
161- ExitDevice ();
162- return (1 );
163- }
164- for (int32_t i = 0 ; i < nThreads; i++) {
165- mHelperParams [i].cls = this ;
166- mHelperParams [i].terminate = false ;
167- mHelperParams [i].reset = false ;
168- mHelperParams [i].num = i;
169- for (int32_t j = 0 ; j < 2 ; j++) {
170- mHelperParams [i].mutex [j].lock ();
171- }
172-
173- if (pthread_create (&mHelperParams [i].threadId , nullptr , helperWrapper_static, &mHelperParams [i])) {
174- GPUError (" Error starting slave thread" );
175- ExitDevice ();
176- return (1 );
177- }
178- }
179- }
180- mNSlaveThreads = nThreads;
181- return (0 );
182- }
183-
184- int32_t GPUReconstructionDeviceBase::StopHelperThreads ()
185- {
186- if (mNSlaveThreads ) {
187- for (int32_t i = 0 ; i < mNSlaveThreads ; i++) {
188- mHelperParams [i].terminate = true ;
189- mHelperParams [i].mutex [0 ].unlock ();
190- mHelperParams [i].mutex [1 ].lock ();
191- if (pthread_join (mHelperParams [i].threadId , nullptr )) {
192- GPUError (" Error waiting for thread to terminate" );
193- return (1 );
194- }
195- }
196- delete[] mHelperParams ;
197- }
198- mNSlaveThreads = 0 ;
199- return (0 );
200- }
201-
202- void GPUReconstructionDeviceBase::WaitForHelperThreads ()
203- {
204- for (int32_t i = 0 ; i < mProcessingSettings .nDeviceHelperThreads ; i++) {
205- pthread_mutex_lock (&((pthread_mutex_t *)mHelperParams [i].mutex )[1 ]);
206- }
207- }
208-
209- void GPUReconstructionDeviceBase::RunHelperThreads (int32_t (GPUReconstructionHelpers::helperDelegateBase::*function)(int32_t i, int32_t t, GPUReconstructionHelpers::helperParam* p), GPUReconstructionHelpers::helperDelegateBase* functionCls, int32_t count)
210- {
211- for (int32_t i = 0 ; i < mProcessingSettings .nDeviceHelperThreads ; i++) {
212- mHelperParams [i].done = 0 ;
213- mHelperParams [i].error = 0 ;
214- mHelperParams [i].function = function;
215- mHelperParams [i].functionCls = functionCls;
216- mHelperParams [i].count = count;
217- pthread_mutex_unlock (&((pthread_mutex_t *)mHelperParams [i].mutex )[0 ]);
218- }
219- }
220-
22190int32_t GPUReconstructionDeviceBase::InitDevice ()
22291{
22392 // cpu_set_t mask;
@@ -262,10 +131,6 @@ int32_t GPUReconstructionDeviceBase::InitDevice()
262131 mProcShadow .mMemoryResProcessors = RegisterMemoryAllocation (&mProcShadow , &GPUProcessorProcessors::SetPointersDeviceProcessor, GPUMemoryResource::MEMORY_PERMANENT | GPUMemoryResource::MEMORY_HOST, " Processors" );
263132 AllocateRegisteredMemory (mProcShadow .mMemoryResProcessors );
264133
265- if (StartHelperThreads ()) {
266- return (1 );
267- }
268-
269134 if (mMaster == nullptr || mProcessingSettings .debugLevel >= 2 ) {
270135 GPUInfo (" GPU Tracker initialization successfull" ); // Verbosity reduced because GPU backend will print GPUImportant message!
271136 }
@@ -282,10 +147,6 @@ void* GPUReconstructionDeviceBase::GPUProcessorProcessors::SetPointersDeviceProc
282147
283148int32_t GPUReconstructionDeviceBase::ExitDevice ()
284149{
285- if (StopHelperThreads ()) {
286- return (1 );
287- }
288-
289150 int32_t retVal = ExitDevice_Runtime ();
290151 mProcessorsShadow = nullptr ;
291152 mHostMemoryPool = mHostMemoryBase = mDeviceMemoryPool = mDeviceMemoryBase = mHostMemoryPoolEnd = mDeviceMemoryPoolEnd = mHostMemoryPermanent = mDeviceMemoryPermanent = nullptr ;
0 commit comments