From b316ab5ac48a27eaca45cd556e1d983d8df22f0b Mon Sep 17 00:00:00 2001 From: David Rohr Date: Thu, 14 Mar 2024 13:44:18 +0100 Subject: [PATCH] GPU: Fix deinitialization order Was wrong for a long time, but not spotted since return value was not checked before --- GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu index c110efd5af77f..f0e6a21242417 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu @@ -53,9 +53,6 @@ GPUReconstructionCUDABackend::GPUReconstructionCUDABackend(const GPUSettingsDevi GPUReconstructionCUDABackend::~GPUReconstructionCUDABackend() { if (mMaster == nullptr) { - for (unsigned int i = 0; i < mInternals->kernelModules.size(); i++) { - GPUFailedMsg(cuModuleUnload(*mInternals->kernelModules[i])); - } delete mInternals; } } @@ -451,6 +448,10 @@ int GPUReconstructionCUDA::ExitDevice_Runtime() } GPUFailedMsgI(cudaFreeHost(mHostMemoryBase)); + for (unsigned int i = 0; i < mInternals->kernelModules.size(); i++) { + GPUFailedMsg(cuModuleUnload(*mInternals->kernelModules[i])); + } + GPUFailedMsgI(cudaDeviceReset()); GPUInfo("CUDA Uninitialized"); }