From b030ac0433768b2e9eef1e53849a7a719023db6f Mon Sep 17 00:00:00 2001 From: Mathieu Barnachon Date: Mon, 8 Feb 2016 13:17:08 +0100 Subject: [PATCH 1/2] Ensure the Cuda context is initialized correctly as long as the setDevice is not called in a multi-thread environment. --- modules/core/src/cuda_info.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/core/src/cuda_info.cpp b/modules/core/src/cuda_info.cpp index 5ad33ce8a1..08013ca988 100644 --- a/modules/core/src/cuda_info.cpp +++ b/modules/core/src/cuda_info.cpp @@ -70,6 +70,7 @@ void cv::cuda::setDevice(int device) (void) device; throw_no_cuda(); #else + cudaFree(0); cudaSafeCall( cudaSetDevice(device) ); #endif } From 6a0d3b3e42a1afd8f63b7e4b290c8227b93d7735 Mon Sep 17 00:00:00 2001 From: Mathieu Barnachon Date: Tue, 9 Feb 2016 14:40:09 +0100 Subject: [PATCH 2/2] Called after setDevice. Wrap in a cudaSafeCall. --- modules/core/src/cuda_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/cuda_info.cpp b/modules/core/src/cuda_info.cpp index 08013ca988..b412438581 100644 --- a/modules/core/src/cuda_info.cpp +++ b/modules/core/src/cuda_info.cpp @@ -70,8 +70,8 @@ void cv::cuda::setDevice(int device) (void) device; throw_no_cuda(); #else - cudaFree(0); cudaSafeCall( cudaSetDevice(device) ); + cudaSafeCall( cudaFree(0) ); #endif }