diff --git a/include/itkCudaContextManager.h b/include/itkCudaContextManager.h index fa3b7d3..1cd9564 100644 --- a/include/itkCudaContextManager.h +++ b/include/itkCudaContextManager.h @@ -43,9 +43,6 @@ class CudaCommon_EXPORT CudaContextManager : public LightObject static void DestroyInstance(); - CUcontext * - GetCurrentContext(); - int GetCurrentDevice(); diff --git a/include/itkCudaImageDataManager.hxx b/include/itkCudaImageDataManager.hxx index 57fecec..249a6ed 100644 --- a/include/itkCudaImageDataManager.hxx +++ b/include/itkCudaImageDataManager.hxx @@ -76,9 +76,6 @@ CudaImageDataManager::MakeCPUBufferUpToDate() std::cout << this << ": GPU->CPU data copy" << std::endl; #endif - CUDA_CHECK(cuCtxSetCurrent( - *(this->m_ContextManager->GetCurrentContext()))); // This is necessary when running multithread to bind the host - // CPU thread to the right context errid = cudaMemcpy(m_CPUBuffer, m_GPUBuffer->GetPointer(), m_BufferSize, cudaMemcpyDeviceToHost); CudaCheckError(errid, __FILE__, __LINE__, ITK_LOCATION); @@ -117,9 +114,6 @@ CudaImageDataManager::MakeGPUBufferUpToDate() std::cout << "CPU->GPU data copy" << std::endl; #endif - CUDA_CHECK(cuCtxSetCurrent( - *(this->m_ContextManager->GetCurrentContext()))); // This is necessary when running multithread to bind the host - // CPU thread to the right context errid = cudaMemcpy(m_GPUBuffer->GetPointer(), m_CPUBuffer, m_BufferSize, cudaMemcpyHostToDevice); CudaCheckError(errid, __FILE__, __LINE__, ITK_LOCATION); diff --git a/src/itkCudaContextManager.cxx b/src/itkCudaContextManager.cxx index 4c80479..b202ab6 100644 --- a/src/itkCudaContextManager.cxx +++ b/src/itkCudaContextManager.cxx @@ -66,14 +66,8 @@ CudaContextManager::CudaContextManager() if (m_NumberOfDevices) { CUdevice device = 0; - m_DeviceIdx = itk::CudaGetMaxFlopsDev(); - CUDA_CHECK(cuDeviceGet(&device, m_DeviceIdx)); - - CUDA_CHECK(cuCtxCreate(&m_Context, CU_CTX_SCHED_AUTO, device)); - - CUDA_CHECK(cuCtxSetCurrent(m_Context)); - m_Device = device; + CUDA_CHECK(cudaSetDevice(m_Device)); } else { @@ -83,14 +77,7 @@ CudaContextManager::CudaContextManager() } } -CudaContextManager::~CudaContextManager() -{ - if (m_Context) - { - CUDA_CHECK(cuCtxDestroy(m_Context)); - } - cudaDeviceReset(); -} +CudaContextManager::~CudaContextManager() {} int CudaContextManager::GetCurrentDevice() @@ -100,10 +87,4 @@ CudaContextManager::GetCurrentDevice() return device; } -CUcontext * -CudaContextManager::GetCurrentContext() -{ - return &m_Context; -} - } // namespace itk diff --git a/src/itkCudaDataManager.cxx b/src/itkCudaDataManager.cxx index 6db4870..850a7f0 100644 --- a/src/itkCudaDataManager.cxx +++ b/src/itkCudaDataManager.cxx @@ -33,9 +33,6 @@ CudaDataManager::CudaDataManager() // is no CUDA device available, we just do not set the context (SR). This fixes // the problem reported here: // https://www.creatis.insa-lyon.fr/pipermail/rtk-users/2015-July/000570.html - CUcontext * ctx = m_ContextManager->GetCurrentContext(); - if (ctx) - CUDA_CHECK(cuCtxSetCurrent(*ctx)); m_CPUBuffer = nullptr; m_GPUBuffer = GPUMemPointer::New(); @@ -91,9 +88,6 @@ CudaDataManager::Free() { try { - CUDA_CHECK(cuCtxSetCurrent( - *(this->m_ContextManager->GetCurrentContext()))); // This is necessary when running multithread to bind the host - // CPU thread to the right context m_GPUBuffer->Free(); } catch (itk::ExceptionObject & e) @@ -171,9 +165,6 @@ CudaDataManager::UpdateCPUBuffer() std::cout << this << "::UpdateCPUBuffer GPU->CPU data copy " << m_GPUBuffer->GetPointer() << "->" << m_CPUBuffer << " : " << m_BufferSize << std::endl; #endif - CUDA_CHECK(cuCtxSetCurrent( - *(this->m_ContextManager->GetCurrentContext()))); // This is necessary when running multithread to bind the host - // CPU thread to the right context CUDA_CHECK(cudaMemcpy(m_CPUBuffer, m_GPUBuffer->GetPointer(), m_BufferSize, cudaMemcpyDeviceToHost)); m_IsCPUBufferDirty = false; } @@ -212,9 +203,6 @@ CudaDataManager::UpdateGPUBuffer() std::cout << this << "::UpdateGPUBuffer CPU->GPU data copy " << m_CPUBuffer << "->" << m_GPUBuffer->GetPointer() << " : " << m_BufferSize << std::endl; #endif - CUDA_CHECK(cuCtxSetCurrent( - *(this->m_ContextManager->GetCurrentContext()))); // This is necessary when running multithread to bind the host - // CPU thread to the right context CUDA_CHECK(cudaMemcpy(m_GPUBuffer->GetPointer(), m_CPUBuffer, m_BufferSize, cudaMemcpyHostToDevice)); } m_IsGPUBufferDirty = false;